terraform - 创建 AWS Elastic Beanstalk 时出错

terraform - error on creating AWS Elastic Beanstalk

我正在尝试使用 terrafrom 配置 AWS Elastic Beanstalk。下面是我写的 .tf 文件:

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"        
}

根据 the official documentation,我向 aws_elastic_beanstalk_environment 模块提供了所有必需的参数。

但是,在执行脚本时,出现以下错误:

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.

这对我有用:将下面的 setting 添加到您的 aws_elastic_beanstalk_environment 资源:

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

此处提供有关常规设置的更多信息:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html

关于 aws_elastic_beanstalk_environment 的信息:https://www.terraform.io/docs/providers/aws/r/elastic_beanstalk_environment.html