terraform - 创建 AWS Elastic Beanstalk 时出错

Ben*_*min 5 terraform terraform-provider-aws

我正在尝试使用 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"        
}
Run Code Online (Sandbox Code Playgroud)

根据官方文档,我向模块提供了所有必需的参数 aws_elastic_beanstalk_environment

但是,执行脚本后,我收到以下错误:

等待 Elastic Beanstalk 环境 (e-39m6ygzdxh) 准备就绪时出错:发生 2 个错误:* 2020-05-13 12:59:02.206 +0000 UTC (e-3xff9mzdxh):您必须在以下位置为您的 EC2 实例指定实例配置文件:这个地区。 有关更多信息,请参阅 管理 Elastic Beanstalk 实例配置文件。* 2020-05-13 12:59:02.319 +0000 UTC (e-3xff9mzdxh) : 无法启动环境。

Mob*_*tal 3

这对我有用:将setting以下内容添加到您的aws_elastic_beanstalk_environment资源中:

 resource "aws_elastic_beanstalk_environment" "tfenvtest" {
 ....
 ....
    setting {
      namespace = "aws:autoscaling:launchconfiguration"
      name      = "IamInstanceProfile"
      value     = "aws-elasticbeanstalk-ec2-role"
    }
 }
Run Code Online (Sandbox Code Playgroud)

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

有关信息aws_elastic_beanstalk_environmenthttps://www.terraform.io/docs/providers/aws/r/elastic_beanstalk_environment.html