Terraform - AWS 上的共享卷

Terraform - Shared volume on AWS

正在尝试将共享卷附加到我的自动缩放组。不确定如何在 terraform 中完成这项工作,或者即使那是可能的?

aws_volume_attachment 采用一个实例 ID,但我希望以某种方式将其放入启动配置中。有人可以帮忙吗

resource "aws_ebs_volume" "shared_volume" {
  availability_zone = "us-east-1"
  size = 2
}

resource "aws_volume_attachment" "volume_attachment" {
  device_name = "/dev/xvdb"
  instance_id = "????"
  volume_id = "${aws_ebs_volume.shared_volume.id}"
  skip_destroy = true
}

resource "aws_launch_configuration" "flume-conf" {
  image_id             = "${var.app_ami_id}"
  instance_type        = "${var.app_instance_type}"
  key_name             = "${var.ssh_key_name}"
  security_groups      = ["${var.app_security_group_id}"]
  user_data            = "${data.template_file.config.rendered}"
  iam_instance_profile = "${var.app_iam_role}"

  root_block_device {
    volume_size = 50
    volume_type = "gp2"
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_autoscaling_group" "ec2_asg" {
  name                 = "${format("%s", var.app_name)}"
  launch_configuration = "${aws_launch_configuration.flume-conf.name}"
  min_size             = "${var.asg_min_size}"
  max_size             = "${var.asg_max_size}"
  vpc_zone_identifier  = ["${element(data.aws_subnet_ids.private.ids, 0)}", "${element(data.aws_subnet_ids.private.ids, 1)}"]
  availability_zones   = "${var.availability_zones}"
  depends_on = []

  lifecycle {
    create_before_destroy = false
  }
}

EBS 卷无法安装到多个主机。如果您正在寻找此功能,请考虑 EFS。