由于 AWS 市场相关错误,Terraform Apply 在尝试使用 CoreOS AMI ID 创建 AWS 实例时失败

Posted

技术标签:

【中文标题】由于 AWS 市场相关错误,Terraform Apply 在尝试使用 CoreOS AMI ID 创建 AWS 实例时失败【英文标题】:Terraform Apply fails when trying to create an AWS instance with CoreOS AMI ID due to AWS market place related error 【发布时间】:2019-10-06 22:09:04 【问题描述】:

我创建了一个包含 AWS CoreOS AMI 作为映像的启动配置。这已附加到 AWS Auto Scaling 组中。以上所有过程都是通过 Terraform 完成的。但是,当 Auto Scaling 组尝试创建实例时,它会失败并出现以下错误。

StatusMessage: "In order to use this AWS Marketplace product you need to accept terms and subscribe. To do so please visit https://aws.amazon.com/marketplace/pp?sku=ryg425ue2hwnsok9ccfastg4. Launching EC2 instance failed."

似乎我必须订阅才能使用此 CoreOS AMI 映像,但是当我在 AS 控制台上创建和实例时,我只需从市场中选择 CoreOS 映像并继续与实例相关的其他配置。但是如何在 Terraform 中实现这一点?我应该事先订阅 AWS CoreOS AMI,还是有办法在 Terraform 中绕过它?

下面给出了所有相关文件和错误跟踪,

launch-configuration.tf 文件

resource "aws_launch_configuration" "tomcat-webapps-all" 
  name                 = "tomcat-webapps-all"
  image_id             = "ami-028e043d0e518a84a"
  instance_type        = "t2.micro"
  key_name             = "rnf-sec"
  security_groups      = ["$aws_security_group.allow-multi-tomcat-webapp-traffic.id"]
  user_data            = "$data.ignition_config.webapps.rendered"

auto-scale-group.tf 文件

resource "aws_autoscaling_group" "tomcat-webapps-all-asg" 
  name                      = "tomcat-webapps-all-asg"
  depends_on                = ["aws_launch_configuration.tomcat-webapps-all"]
  vpc_zone_identifier       = ["$aws_default_subnet.default-az1.id", "$aws_default_subnet.default-az2.id", "$aws_default_subnet.default-az3.id"]
  max_size                  = 1
  min_size                  = 0
  health_check_grace_period = 300
  health_check_type         = "EC2"
  desired_capacity          = 1
  force_delete              = true
  launch_configuration      = "$aws_launch_configuration.tomcat-webapps-all.id"
  target_group_arns         = ["$aws_lb_target_group.newdasboard-lb-tg.arn", "$aws_lb_target_group.signup-lb-tg.arn"]

错误追踪

Error: Error applying plan:

1 error(s) occurred:

* aws_autoscaling_group.tomcat-webapps-all-asg: 1 error(s) occurred:

* aws_autoscaling_group.tomcat-webapps-all-asg: "tomcat-webapps-all-asg": Waiting up to 10m0s: Need at least 1 healthy instances in ASG, have 0. Most recent activity: 
  ActivityId: "9455ab55-426a-c888-ac95-2d45c78d445a",
  AutoScalingGroupName: "tomcat-webapps-all-asg",
  Cause: "At 2019-05-20T12:56:29Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.",
  Description: "Launching a new EC2 instance.  Status Reason: In order to use this AWS Marketplace product you need to accept terms and subscribe. To do so please visit https://aws.amazon.com/marketplace/pp?sku=ryg425ue2hwnsok9ccfastg4. Launching EC2 instance failed.",
  Details: "\"Subnet ID\":\"subnet-c650458f\",\"Availability Zone\":\"ap-southeast-1a\"",
  EndTime: 2019-05-20 12:56:30 +0000 UTC,
  Progress: 100,
  StartTime: 2019-05-20 12:56:30.642 +0000 UTC,
  StatusCode: "Failed",
  StatusMessage: "In order to use this AWS Marketplace product you need to accept terms and subscribe. To do so please visit https://aws.amazon.com/marketplace/pp?sku=ryg425ue2hwnsok9ccfastg4. Launching EC2 instance failed."

【问题讨论】:

【参考方案1】:

如果您登录控制台并接受 ULA 条款,一旦通过 terraform 应用此错误就会消失。

如果我是你,我会登录,完成整个过程以使用此 AMI 启动一个实例,终止它,然后应用 terraform。

【讨论】:

感谢您的回复,我也这样做了,并且还按照我在回答中解释的步骤进行了操作。无论如何,它现在似乎工作正常【参考方案2】:

如果有人也遇到同样的问题,我可以通过使用 root 用户登录我的 EC2 控制台并订阅 AWS Marketplace 上的 AWS CoreOS 产品页面来解决它。

之后,一切都按预期进行。返回的错误带有指向 AWS Marketplace 上 CoreOS 产品页面的 Web URL。只需单击“继续订阅”按钮即可。

如果上述步骤不起作用,请参阅此答案 - https://***.com/a/56222898/4334340

【讨论】:

以上是关于由于 AWS 市场相关错误,Terraform Apply 在尝试使用 CoreOS AMI ID 创建 AWS 实例时失败的主要内容,如果未能解决你的问题,请参考以下文章

使用 terraform 覆盖已删除的 aws_secretsmanager_secret 资源

Terraform 和 AWS:未找到配置文件错误

创建 AWS Cognito 用户池时出现 Terraform 错误

Terraform:导入 aws 资源时出现凭证错误 - 调用 sts 时出错:GetCallerIdentity:ExpiredToken

Terraform:验证错误...成员必须满足正则表达式模式:arn:aws:iam::

通过 Terraform 创建的 AWS Glue 中的无效架构错误