分配给实例列表的 Terraform 导入卷
Terraform import volumes assigned to instances list
我已经为实例列表配置了一个资源:
resource "aws_instance" "masters" {
count = "${var.masters_count}"
# count = 2
ami = "${var.aws_centos_ami}"
instance_type = "t2.micro"
key_name = "${var.aws_key_name}"
vpc_security_group_ids = ["${aws_security_group.bastion.id}"]
associate_public_ip_address = true
source_dest_check = false
subnet_id = "${aws_subnet.eu-west-1b-public.id}"
availability_zone = "eu-west-1b"
tags {
Name = "master-${count.index}"
}
}
然后我将卷附加到该实例:
data "aws_ebs_volume" "masters_ebs_volume" {
count = 2
filter {
name = "attachment.instance-id"
values = ["${element(aws_instance.masters.*.id, count.index)}"]
}
}
现在我正在尝试将卷导入 terraform。我只是尝试使用:
terraform import aws_ebs_volume.data[0] vol-1153438514541
terraform import aws_ebs_volume.masters_ebs_volume[0] vol-1153438514541
terraform import aws_ebs_volume.masters[0] vol-1153438514541
terraform import aws_ebs_volume.data vol-1153438514541
terraform import aws_ebs_volume.masters vol-1153438514541
但没有任何效果..我该如何导入这些卷?
我刚解决添加:
root_block_device {
delete_on_termination = true
}
因此,如果卷在外部发生变化,它会破坏。
我已经为实例列表配置了一个资源:
resource "aws_instance" "masters" {
count = "${var.masters_count}"
# count = 2
ami = "${var.aws_centos_ami}"
instance_type = "t2.micro"
key_name = "${var.aws_key_name}"
vpc_security_group_ids = ["${aws_security_group.bastion.id}"]
associate_public_ip_address = true
source_dest_check = false
subnet_id = "${aws_subnet.eu-west-1b-public.id}"
availability_zone = "eu-west-1b"
tags {
Name = "master-${count.index}"
}
}
然后我将卷附加到该实例:
data "aws_ebs_volume" "masters_ebs_volume" {
count = 2
filter {
name = "attachment.instance-id"
values = ["${element(aws_instance.masters.*.id, count.index)}"]
}
}
现在我正在尝试将卷导入 terraform。我只是尝试使用:
terraform import aws_ebs_volume.data[0] vol-1153438514541
terraform import aws_ebs_volume.masters_ebs_volume[0] vol-1153438514541
terraform import aws_ebs_volume.masters[0] vol-1153438514541
terraform import aws_ebs_volume.data vol-1153438514541
terraform import aws_ebs_volume.masters vol-1153438514541
但没有任何效果..我该如何导入这些卷?
我刚解决添加:
root_block_device {
delete_on_termination = true
}
因此,如果卷在外部发生变化,它会破坏。