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

时间:2019-05-20 14:04:42

标签: amazon-web-services terraform devops

我创建了一个启动配置,其中包含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."
}

2 个答案:

答案 0 :(得分:1)

如果您登录控制台并接受ULA条款,则通过Terraform应用该错误时,该错误将消失。

如果我要登录,请执行整个过程以使用此AMI启动一个实例,终止该实例,然后应用terraform。

答案 1 :(得分:0)

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

之后,一切都按预期进行。该错误使用Web URL重新调到AWS Marketplace上的CoreOS产品页面。只需单击“继续订阅”按钮即可。

如果上述步骤无效,请参考以下答案-https://stackoverflow.com/a/56222898/4334340