Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Terraform – The instance profile associated with the environment does not exist

I am trying to create an Elastic Beanstalk application but I am coming across the error:

The instance profile iam_for_beanstalk associated with the environment does not exist.

The role does exist as you can see here:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

and it is being created via Terraform through the following code:

resource "aws_iam_role" "beanstalk" {
  name = "iam_for_beanstalk"
  assume_role_policy = file("${path.module}/assumerole.json")
}

assumerole.json looks like this:

{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow",
        "Principal": {
            "Service": "elasticbeanstalk.amazonaws.com"
        },
        "Action": "sts:AssumeRole",
        "Condition": {
          "StringEquals": {
            "sts:ExternalId": "elasticbeanstalk"
          }
        }
    }]
}

And here is how I try to associate it to the newly created application:

resource "aws_elastic_beanstalk_environment" "nodejs" {
  application = aws_elastic_beanstalk_application.nodejs.name
  name = "stackoverflow"
  version_label = var.app_version
  solution_stack_name = "64bit Amazon Linux 2 v5.4.6 running Node.js 14"

  setting {
    namespace = "aws:autoscaling:launchconfiguration"
    name      = "IamInstanceProfile"
    value     = "iam_for_beanstalk"
  }...

I also tried to assign the name like below, but no success:

value     = aws_iam_role.beanstalk.name

>Solution :

You also need to create an aws_iam_instance_profile resource:

resource "aws_iam_instance_profile" "beanstalk_instance_profile" {
  name = "stack-overflow-example"
  role = aws_iam_role.beanstalk.name
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading