2016-11-06 57 views
1

我正在嘗試在帳戶之間創建VPC對等並自動接受它,但它失敗並顯示權限錯誤。爲什麼在嘗試在Terraform中auto_accept vpc對等時收到權限錯誤?

這裏是提供商main.tf

provider "aws" { 
    region     = "${var.region}" 
    shared_credentials_file = "/Users/<username>/.aws/credentials" 
    profile     = "sandbox" 
} 

data "aws_caller_identity" "current" { } 

這裏是vpc_peer模塊:

resource "aws_vpc_peering_connection" "peer" { 
     peer_owner_id    = "${var.peer_owner_id}" 
     peer_vpc_id    = "${var.peer_vpc_id}" 
     vpc_id      = "${var.vpc_id}" 
     auto_accept    = "${var.auto_accept}" 

     accepter { 
     allow_remote_vpc_dns_resolution = true 
     } 

     requester { 
     allow_remote_vpc_dns_resolution = true 
     } 

     tags { 
     Name = "VPC Peering between ${var.peer_vpc_id} and ${var.vpc_id}" 
     } 
} 

這裏在maint.ft

模塊執行
module "peering" { 
    source = "../modules/vpc_peer" 

    region  = "${var.region}" 
    peer_owner_id = "<management account number>" 
    peer_vpc_id = "<vpc-********>" 
    vpc_id  = "${module.network.vpc_id}" 
    auto_accept = "true" 
} 

現在,我從「沙盒」提供商使用的IAM用戶具有管理帳戶中的VPC中的VPC對等的權限。

我使用AWS以下步驟:http://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html

不幸的是我一直用下面的錯誤而失敗:

1 error(s) occurred: 

* aws_vpc_peering_connection.peer: Unable to accept VPC Peering Connection: OperationNotPermitted: User 651267440910 cannot accept peering pcx-f9c55290 
    status code: 400, request id: cfbe1163-241e-413b-a8de-d2bca19726e5 

任何想法?

回答

0

Terraform中的auto_accept參數只能在同一個帳戶的VPC上使用。從documentation

auto_accept - (Optional) Accept the peering (both VPCs need to be in the same AWS account).

...

If both VPCs are not in the same AWS account do not enable the auto_accept attribute. You will still have to accept the VPC Peering Connection request manually using the AWS Management Console, AWS CLI, through SDKs, etc.

所以你只需要就這一端在terraform沒有auto_accept對等連接,然後手動或編程方式接受它的目標賬戶。一些程序上的選項:

的AWS SDK在您所選擇的語言應對此有一個匹配方法,以及。

+0

謝謝安東尼,我找到了解決這個問題的方法。 通過運行local_exec和aws cli命令來接受遠程帳戶上的同位體。 –

+0

太棒了!很高興你解決了你的問題。 –

1

我設法運行一個local_exec來接受對等體。

下面是一個例子:

resource "aws_vpc_peering_connection" "peer" { 

    peer_owner_id    = "${var.peer_owner_id}" 
    peer_vpc_id    = "${var.peer_vpc_id}" 
    vpc_id      = "${var.vpc_id}" 

    provisioner "local-exec" { 
    command = "aws ec2 accept-vpc-peering-connection --vpc-peering-connection-id=${aws_vpc_peering_connection.peer.id} --region=${var.region} --profile=${var.profile}" 

    } 

    tags { 
    Name = "VPC Peering between ${var.peer_vpc_id} and ${var.vpc_id}" 
    } 
} 
0

VPC對等將發生在具有相同的帳戶或不同戶頭的相同區域,在這兩個側面上的VPC窺視需要被依次從一個VPC接受訪問到另一個vpc。

相關問題