【发布时间】:2021-12-16 01:02:27
【问题描述】:
我正在尝试恢复配置了 terraform 的 AWS 账户的状态。我已经用我的模块运行了“terraform import”,并且能够为几个 aws_subnets 拉入状态,但是当我运行“terraform plan”时,它仍然试图强制破坏现有子网并重新创建它们。
这是我的 terraform 的样子
resource "aws_subnet" "instance_subnets" {
for_each = { for idx, subnet in keys(var.subnets) : idx => { name = subnet
cidr = var.subnets[subnet] } }
cidr_block = each.value.cidr
vpc_id = aws_vpc.vpc.id
availability_zone = element(data.aws_availability_zones.available.names, each.key)
tags = {
Name = each.value.name
}
}
我的 terraform.tf
variable "subnets" {
type = map(string)
default = {
"Public" : "10.10.0.0/24"
"Private" : "10.10.1.0/24"
}
地形计划输出
# module.mymodule.aws_subnet.subnets will be destroyed
- resource "aws_subnet" "subnets" {
- arn = "arn:aws:ec2:eu-west-2:0xxxxxxxxxxxxx:subnet/subnet-0000xxxxx" -> null
- assign_ipv6_address_on_creation = false -> null
- availability_zone = "eu-west-2a" -> null
- availability_zone_id = "euw2-az2" -> null
- cidr_block = "10.10.0.0/24" -> null
- id = "subnet-0000xxxxx" -> null
- map_customer_owned_ip_on_launch = false -> null
- map_public_ip_on_launch = false -> null
- owner_id = "0xxxxxxxxxxxxx" -> null
- tags = {
- "Name" = "Public"
} -> null
- tags_all = {
- "Name" = "Public"
} -> null
- vpc_id = "vpc-0000xxxxxxx" -> null
- timeouts {}
}
# module.mymodule.aws_subnet.subnets[1] will be destroyed
- resource "aws_subnet" "subnets" {
- arn = "arn:aws:ec2:eu-west-2:0xxxxxxxxxxxxx:subnet/subnet-0000xxxxx" -> null
- assign_ipv6_address_on_creation = false -> null
- availability_zone = "eu-west-2b" -> null
- availability_zone_id = "euw2-az3" -> null
- cidr_block = "10.10.1.0/24" -> null
- id = "subnet-0000xxxxx" -> null
- map_customer_owned_ip_on_launch = false -> null
- map_public_ip_on_launch = false -> null
- owner_id = "0xxxxxxxxxxxxx" -> null
- tags = {
- "Name" = "Private"
} -> null
- tags_all = {
- "Name" = "Private"
} -> null
- vpc_id = "vpc-0000xxxxxxx" -> null
- timeouts {}
}
# module.mymodule.aws_subnet.subnets["0"] will be created
+ resource "aws_subnet" "subnets" {
+ arn = (known after apply)
+ assign_ipv6_address_on_creation = false
+ availability_zone = "eu-west-2a"
+ availability_zone_id = (known after apply)
+ cidr_block = "10.10.0.0/24"
+ id = (known after apply)
+ ipv6_cidr_block_association_id = (known after apply)
+ map_public_ip_on_launch = false
+ owner_id = (known after apply)
+ tags = {
+ "Name" = "Public"
}
+ tags_all = {
+ "Name" = "Public"
}
+ vpc_id = "vpc-0000xxxxxxx"
}
# module.mymodule.aws_subnet.subnets["1"] will be created
+ resource "aws_subnet" "subnets" {
+ arn = (known after apply)
+ assign_ipv6_address_on_creation = false
+ availability_zone = "eu-west-2b"
+ availability_zone_id = (known after apply)
+ cidr_block = "10.10.1.0/24"
+ id = (known after apply)
+ ipv6_cidr_block_association_id = (known after apply)
+ map_public_ip_on_launch = false
+ owner_id = (known after apply)
+ tags = {
+ "Name" = "Private"
}
+ tags_all = {
+ "Name" = "Private"
}
+ vpc_id = "vpc-0000xxxxxxx"
}
我有无法在每个子网中终止的 ec2 实例,因此无法将其销毁和重新创建。是否可以以允许我按原样使用状态文件的方式导入它们?
【问题讨论】:
标签: amazon-web-services terraform terraform-provider-aws