【发布时间】:2021-03-30 21:08:00
【问题描述】:
我在 2 个 AWS 账户之间创建了一个 VPC 对等互连。账户 A 的一个 VPC 位于 us-east-1,账户 B 的第二个 VPC 位于 us-west-2。
-
对等连接处于活动状态并且工作正常!
-
我现在需要在我的 terraform 代码中为两个 Accounts terraform 代码添加它。
-
我现在先把它添加到帐户 B 中! 这是我迄今为止所做的:
# VPC peering connection #
# (3) #
##########################
resource "aws_vpc_peering_connection" "this_3" {
count = var.create_peering_3 ? 1 : 0
peer_owner_id = var.peer_account_id_3
peer_vpc_id = var.vpc_peer_id_3
vpc_id = module.vpc-us-west-2.vpc_id
auto_accept = var.auto_accept_peering_3
}
这些是变量:
##########################
# VPC peering connection #
# (3) #
##########################
variable "peer_account_id_3" {
description = "AWS owner account ID"
default = "**account*A**"
}
variable "vpc_peer_id_3" {
description = "Peer VPC ID"
default = "vpc-029***"
}
variable "peer_cidr_block_3" {
description = "Peer VPC CIDR block"
default = "192.168.0.0/16"
}
variable "auto_accept_peering_3" {
description = "Auto accept peering connection"
default = true
}
variable "create_peering_3" {
description = "Create peering connection, 0 to not create"
default = true
type = bool
}
variable "this_vpc_id_3" {
description = "This VPC ID"
default = "vpc-0e2**"
}
variable "private_route_table_ids_3" {
type = list(string)
description = "A list of private route tables"
default = ["rtb-0**, rtb-04**"]
}
variable "public_route_table_ids_3" {
type = list(string)
description = "A list of public route tables"
default = ["rtb-0f**"]
}
variable "peering_id_3" {
description = "Provide already existing peering connection id"
default = "pcx-0878***"
}
现在,当我运行 tf plan 时,它正在创建它。我不希望它这样做,因为它已经制作好了!
-
我希望我的计划没有任何变化!
-
我也尝试过使用 tf import 命令:
terraform import aws_vpc_peering_connection.this_3 pcx-0878******
但它给了我这个错误:
Error: Cannot import non-existent remote object
While attempting to import an existing object to
aws_vpc_peering_connection.this_3, the provider detected that no object exists
with the given id. Only pre-existing objects can be imported; check that the
id is correct and that it is associated with the provider's configured region
or endpoint, or use "terraform apply" to create a new remote object for this
resource.
- 我不知道如何解决这个问题
【问题讨论】:
-
哪个账户正在创建 VPC 连接,A 还是 B?
-
@John Rotenstein 帐户 A
标签: amazon-web-services terraform amazon-vpc terraform-provider-aws