[英]Error AWS Terraform VPC Peering while running TF Import
我在 2 个 AWS 账户之间创建了一个 VPC 对等互连。 账户 A 的一个 VPC 位于 us-east-1 中,账户 B 的第二个 VPC 位于 us-west-2 中。
对等连接处于活动状态并且工作正常!
我现在需要将它添加到我的 terraform 代码中,用于两个账户 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.
确认您是否使用来自账户 B 的正确凭据。
provider "aws" {
alias = "account_b"
region = "us-west-2"
access_key = "my-access-key"
secret_key = "my-secret-key"
}
resource "aws_vpc_peering_connection" "this_3" {
provider = "aws.account_b"
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
}
并尝试再次运行导入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.