I am trying to provision an AWS Elastic Beanstalk using terrafrom. Below is the .tf
file I have written:
resource "aws_s3_bucket" "default" {
bucket = "textX"
}
resource "aws_s3_bucket_object" "default" {
bucket = "${aws_s3_bucket.default.id}"
key = "test-app-version-tf--dev"
source = "somezipFile.zip"
}
resource "aws_elastic_beanstalk_application_version" "default" {
name = "tf-test-version-label"
application = "tf-test-name"
description = "application version created by terraform"
bucket = "${aws_s3_bucket.default.id}"
key = "${aws_s3_bucket_object.default.id}"
}
resource "aws_elastic_beanstalk_application" "tftest" {
name = "tf-test-name"
description = "tf-test-name"
}
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
description = "test"
application = "${aws_elastic_beanstalk_application.tftest.name}"
name = "synchronicity-dev"
cname_prefix = "ops-api-opstest"
solution_stack_name = "64bit Amazon Linux 2 v5.0.1 running Node.js 12"
tier = "WebServer"
wait_for_ready_timeout = "20m"
}
According to the official documentation, I am supplying all the Required arguments to aws_elastic_beanstalk_environment
module.
However, upon executing the script, I am getting the following error:
Error waiting for Elastic Beanstalk Environment (e-39m6ygzdxh) to become ready: 2 errors occurred: * 2020-05-13 12:59:02.206 +0000 UTC (e-3xff9mzdxh) : You must specify an Instance Profile for your EC2 instance in this region. See Managing Elastic Beanstalk Instance Profiles for more information. * 2020-05-13 12:59:02.319 +0000 UTC (e-3xff9mzdxh) : Failed to launch environment.
This worked for me: add the setting
below to your aws_elastic_beanstalk_environment
resource:
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
....
....
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "IamInstanceProfile"
value = "aws-elasticbeanstalk-ec2-role"
}
}
More information on general settings here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html
Info on the aws_elastic_beanstalk_environment
: https://www.terraform.io/docs/providers/aws/r/elastic_beanstalk_environment.html