Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk instance profile not automatically created when using Terraform in eu-west-2 region

I am using Terraform to successfully spin up some Elastic Beanstalk apps (Single Docker configuration) and enable auto-scaling as part of the app / environment creation.

This works fine in most regions I’ve tried, but when I try to spin it up in London (eu-west-2) I get an error:

Error: Error applying plan:

1 error(s) occurred:

* aws_elastic_beanstalk_environment.my-service-env: 1 error(s) occurred:

* aws_elastic_beanstalk_environment.my-service-env: Error waiting for Elastic Beanstalk Environment (e-mt7f3i5bmq) to become ready: 2 error(s) occurred:

* 2018-06-11 19:31:29.28 +0000 UTC (e-mt7f3i5bmq) : Environment must have instance profile associated with it.
* 2018-06-11 19:31:29.39 +0000 UTC (e-mt7f3i5bmq) : Failed to launch environment.

I have found that if I manually attach the aws-elasticbeanstalk-ec2-role as the IamInstanceProfile it works fine - but this relies on the role having been automatically created previously...

Is there something about the eu-west-2 region which would mean the Beanstalk apps don’t get created with the instance profile as they do in other regions?

What am I missing?

Thanks for your help!

like image 290
MattStibbs Avatar asked Jun 11 '18 21:06

MattStibbs


People also ask

How do I make rubber Beanstalk in terraform with AWS?

Create a file name main.tf and paste the entire content in that file. For deploying ElasticBeanstalk we need to create an ElasticBeanstalk application and environment. So, In this file we are creating an application and environment. Step2: After that we will create a vars.tf file in the same directory.

What two types of environments can be created when using Elastic Beanstalk?

In AWS Elastic Beanstalk, you can create a load-balanced, scalable environment or a single-instance environment.


1 Answers

For others stuck on this issue I have found a solution by adding the instance profile directly as a setting. This instance profile doesn't get automatically added like it does when creating an elastic beanstalk through the console. Below is the full beanstalk environment resource defined:

resource "aws_elastic_beanstalk_environment" "beanstalkenvironment" {
  name                = "dev-example"
  application         = aws_elastic_beanstalk_application.beanstalkapp.name
  solution_stack_name = "64bit Amazon Linux 2018.03 v2.14.1 running Docker 18.09.9-ce"
  version_label       = aws_elastic_beanstalk_application_version.beanstalkapplicationversion.name
  setting {
      namespace = "aws:autoscaling:launchconfiguration"
      name = "IamInstanceProfile"
      value = "aws-elasticbeanstalk-ec2-role"
  }
  setting {
    namespace = "aws:autoscaling:launchconfiguration"
    name = "InstanceType"
    value = "t2.micro"
  }
  tags = {
    Name = "test"
    Environment = "test"
  }
}

The exact setting used to fix this error was:

setting {
      namespace = "aws:autoscaling:launchconfiguration"
      name = "IamInstanceProfile"
      value = "aws-elasticbeanstalk-ec2-role"
  }

To find what the value "aws-elasticbeanstalk-ec2-role" that's required I checked an existing elastic beanstalk instance that was created through the console. Under the environment, in configuration there is a security section. The role name needed is listed as "IAM instance profile". Hopefully this helps others who get stuck on this issue.

like image 134
user3352617 Avatar answered Nov 10 '22 14:11

user3352617