我正在用Terraform创建两种不同类型的EC2实例。这些实例中的每一个都需要具有为/ var / opt / MarkLogic创建的卷。我有创建卷的代码,但无法弄清楚如何将它们附加到两种EC2实例上。有没有一种方法可以创建两个单独的aws_volume_attachment
?
我尝试使用instance_id = "${element(aws_instance.*.*.id, count.index)}"
上的splat,但Terraform不允许这样做。如何在一个aws_volume_attachment
resource "aws_instance" "marklogic-d-nodes" {
count = "${var.dnodes}"
ami = "ami-0f5da6468457979f6"
instance_type = "t2.micro"
subnet_id = "${var.subnet}"
key_name = "AWS_ML_Oregon"
security_groups = ["sg-0cd3123385e1bd3a2"]
iam_instance_profile = "DefaultEC2Role"
user_data = "${file("../global/scripts/dnodes.sh")}"
disable_api_termination = false
}
resource "aws_instance" "marklogic-e-nodes" {
count = "${var.enodes}"
ami = "ami-0f5da6468457979f6"
instance_type = "t2.small"
subnet_id = "${var.subnet}"
key_name = "AWS_ML_Oregon"
security_groups = ["sg-0cd3123385e1bd3a2"]
iam_instance_profile = "DefaultEC2Role"
user_data = "${file("../global/scripts/enodes.sh")}"
disable_api_termination = false
}
resource "aws_ebs_volume" "varopt" {
count = "${var.dnodes + var.enodes}"
availability_zone = "us-west-2b"
size = 100
type = "gp2"
}
resource "aws_volume_attachment" "varopt-volume-attachment" {
count = "${var.dnodes + var.enodes}"
device_name = "/dev/sdf"
instance_id = "${element(aws_instance.*.*.id, count.index)}"
volume_id = "${element(aws_ebs_volume.varopt.*.id, count.index)}"
force_detach = true
}