如何使用Terraform标记从自动缩放启动的实例?

问题描述 投票:0回答:1

我正在使用Terraform来设置ECS集群。这是我的启动配置:

resource "aws_launch_configuration" "launch_config" {
  name_prefix = "my_project_lc"
  image_id = "ami-ff15039b"
  instance_type = "t2.medium"
  user_data = "${data.template_file.user_data.rendered}"
  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_autoscaling_group" "autoscaling_group" {
  name = "my_project_asg"
  max_size = 2
  min_size = 1
  launch_configuration = "${aws_launch_configuration.launch_config.name}"
  vpc_zone_identifier = ["${aws_subnet.public.id}"]
}

它工作正常,但EC2实例没有名称(标签“名称”)。如何更改配置以便为实例提供有意义的名称?前缀或东西......

谢谢

amazon-web-services terraform autoscaling
1个回答
1
投票

对的,这是可能的。请参阅aws_autoscaling_group resource的文档。示例代码:

resource "aws_autoscaling_group" "bar" {
  name = "my_project_asg"
  max_size = 2
  min_size = 1
  launch_configuration = "${aws_launch_configuration.launch_config.name}"
  vpc_zone_identifier = ["${aws_subnet.public.id}"]

  tag {
    key                 = "Name"
    value               = "something-here"
    propagate_at_launch = true
  }

  tag {
    key                 = "lorem"
    value               = "ipsum"
    propagate_at_launch = false
  }
}

或者,您可以使用实现不同类型标记的terraform-aws-autoscaling模块。

© www.soinside.com 2019 - 2024. All rights reserved.