AWS Elasticbeanstalk environment deployment

Hello everyone.
I’m stuck at deploying an AWS Elasticbeanstalk environment via Terraform.
I have a code that looks like this:

resource "aws_elastic_beanstalk_application" "beanstalk_app" {
  name = "${var.repo_name}-beanstalk"
  description = "Beanstalk application"
}

resource "aws_elastic_beanstalk_environment" "beanstalk_env" {
  count = length(var.environments)
  name = "${var.repo_name}-${var.environments[count.index]}-env"
  application = aws_elastic_beanstalk_application.beanstalk_app.name
  solution_stack_name = var.solution_stack_name
  depends_on = [aws_iam_role.beanstalk_role, aws_iam_role.beanstalk_service_role]

  # Auto Scaling launch configuration
  setting {
      namespace = "aws:autoscaling:launchconfiguration"
      name = "IamInstanceProfile"
      value = "aws-elasticbeanstalk-ec2-role-test"
  }
  setting {
    namespace = "aws:autoscaling:launchconfiguration"
    name = "SecurityGroups"
    value = var.security_groups
  }

And I’m constantly getting this error:

The instance profile aws-elasticbeanstalk-ec2-role-test associated with the environment does not exist.
	* 2021-08-31 11:11:32.389 +0000 UTC (e-qaqgvyrmfp) : Failed to launch environment.

I have tried creating this role as a separate resource with Terraform, created it using aws-cli and still it didn’t work.
Although, when I created this role manually via AWS Console, it worked.
Is there something that I’m missing?
Thank you!

Found what was the problem.
As the error said:
The instance profile aws-elasticbeanstalk-ec2-role-test associated with the environment does not exist.
Additionally I created an instance profile role and associated it with the aws-elasticbeanstalk-ec2-role-test role and it worked.