首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行TF导入时的AWS Terraform VPC窥视错误

运行TF导入时的AWS Terraform VPC窥视错误
EN

Stack Overflow用户
提问于 2020-12-21 03:03:23
回答 1查看 382关注 0票数 0

我已经创建了一个VPC窥视之间的2个AWS帐户。帐户A的一个VPC在美国东部-1号,第二个VPC在帐户B在美国-west-2。

  • 对等连接处于活动状态,工作正常!

  • ,我现在需要将它添加到我的terraform代码中,这两个帐户都是terraform代码。

  • ,我现在先把它添加到帐户B中!这是我到现在为止所做的:

代码语言:javascript
复制
# 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
}

这些变量是:

代码语言:javascript
复制
##########################
# 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计划时,它正在创建它。我不想让它做,因为它已经做好了!

  • 我想看到我的计划没有任何变化!

  • I也尝试使用tf导入命令:

代码语言:javascript
复制
terraform import aws_vpc_peering_connection.this_3 pcx-0878******

但它给了我一个错误:

代码语言:javascript
复制
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.

  • 我不知道如何修复
EN

回答 1

Stack Overflow用户

发布于 2020-12-21 03:39:12

确认您是否使用了来自帐户B的正确凭据。

代码语言:javascript
复制
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
}

并尝试再次运行导入。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65387073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档