【问题标题】:Terraform couldn't destroy metrics for aws asgTerraform 无法破坏 aws asg 的指标
【发布时间】:2021-07-02 21:43:39
【问题描述】:

接管了一个遗留堆栈,它使用 Terraform 创建了一堆资源,其中一个是以下 asg:

resource "aws_autoscaling_group" "logstashcluster_asg" {
  lifecycle { create_before_destroy = true }

  name                      = "${var.stack_id}-asg"

  vpc_zone_identifier       = ["${data.terraform_remote_state.global.vpc_server_subnet_ids_az}"]
  max_size                  = "${lookup(var.max_count, var.aws_account_id)}"
  min_size                  = "${lookup(var.min_count, var.aws_account_id)}"
  health_check_grace_period = 600
  health_check_type         = "ELB"
  force_delete              = true
  launch_configuration      = "${aws_launch_configuration.cloud_logstashcluster.name}"
  target_group_arns         = ["${aws_lb_target_group.logstashcluster8080.arn}", "${aws_lb_target_group.logstashcluster8081.arn}", "${aws_lb_target_group.logstashcluster.arn}","${aws_lb_target_group.logstashcluster5445.arn}","${aws_lb_target_group.logstashcluster8090.arn}"]

  tags = [
    {
      key = "StackId"
      value = "${var.stack_id}"
      propagate_at_launch = true
    },
    {
      key = "Name"
      value = "${var.stack_id}"
      propagate_at_launch = true
    }
  ]

}

请注意其中没有 enabled_metrics,但是当我运行它时,我得到了以下日志:

aws_autoscaling_group.logstashcluster_asg: Modifying... (ID: cloud-logstashcluster-asg)

  enabled_metrics.#:          "21" => "0"

  enabled_metrics.119681000:  "GroupStandbyInstances" => ""

  enabled_metrics.1196937530: "WarmPoolWarmedCapacity" => ""

  enabled_metrics.1460020489: "GroupAndWarmPoolTotalCapacity" => ""

  enabled_metrics.1940933563: "GroupTotalInstances" => ""

  enabled_metrics.2498709624: "GroupTotalCapacity" => ""

  enabled_metrics.2591500440: "GroupInServiceCapacity" => ""

  enabled_metrics.3061563798: "WarmPoolTerminatingCapacity" => ""

  enabled_metrics.3076096507: "GroupStandbyCapacity" => ""

  enabled_metrics.308948767:  "GroupPendingInstances" => ""

  enabled_metrics.3113454766: "WarmPoolMinSize" => ""

  enabled_metrics.3267518000: "GroupTerminatingInstances" => ""

  enabled_metrics.3360752227: "WarmPoolPendingCapacity" => ""

  enabled_metrics.3394537085: "GroupDesiredCapacity" => ""

  enabled_metrics.3480424646: "GroupAndWarmPoolDesiredCapacity" => ""

  enabled_metrics.3551801763: "GroupInServiceInstances" => ""

  enabled_metrics.3977504579: "GroupTerminatingCapacity" => ""

  enabled_metrics.4118539418: "GroupMinSize" => ""

  enabled_metrics.4136111317: "GroupMaxSize" => ""

  enabled_metrics.4168968189: "WarmPoolTotalCapacity" => ""

  enabled_metrics.628375462:  "GroupPendingCapacity" => ""

  enabled_metrics.661765048:  "WarmPoolDesiredCapacity" => ""



Error: Error applying plan:



1 error occurred:

    * aws_autoscaling_group.logstashcluster_asg: 1 error occurred:

    * aws_autoscaling_group.logstashcluster_asg: Error updating AutoScaling Group Metrics collection: Failure to Disable metrics collection types for ASG cloud-logstashcluster-asg: ValidationError: Valid metrics collection types are: [GroupMinSize, GroupMaxSize, GroupDesiredCapacity, GroupInServiceInstances, GroupInServiceCapacity, GroupPendingInstances, GroupPendingCapacity, GroupTerminatingInstances, GroupTerminatingCapacity, GroupStandbyInstances, GroupStandbyCapacity, GroupTotalInstances, GroupTotalCapacity, WarmPoolMinSize, WarmPoolDesiredCapacity, WarmPoolPendingCapacity, WarmPoolTerminatingCapacity, WarmPoolWarmedCapacity, WarmPoolTotalCapacity, GroupAndWarmPoolDesiredCapacity, GroupAndWarmPoolTotalCapacity].

    status code: 400, request id: 9ed94b27-cc08-4d47-b2d8-829d587f2b64

不确定这是否是因为他们之前有指标,但不应该只是简单地被 TF 修改/销毁吗?为什么抱怨?另外,我尝试将 enabled_metrics =[] 添加为空列表,仍然出现相同的错误。请帮忙。

【问题讨论】:

  • 这个输出是怎么得到的?这不是来自terraform plan
  • @Marcin 我相信这是来自 terraform apply。
  • 那么这个错误是加enabled_metrics =[] 还是不加呢?
  • 指标可能已在 TF 之外启用,导致漂移。但是这个错误很奇怪。您使用什么版本的 TF 和 aws 提供程序?
  • 如果你运行 terraform --version if 也会给你 aws 提供者版本。但无论如何,您是否有可能检查当前的 tf 和 aws 提供程序版本?

标签: amazon-web-services terraform aws-auto-scaling


【解决方案1】:

不确定是什么导致了这种情况,但通过添加这个 ignore_changes 选项找到了一个临时解决方法,如下所示:

lifecycle {
  ignore_changes = ["tags", "enabled_metrics"]
}

【讨论】:

    猜你喜欢
    • 2019-11-20
    • 2021-07-05
    • 2018-10-18
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 2018-12-14
    • 2019-06-28
    相关资源
    最近更新 更多