2016-05-24 00:24:28 +02:00
|
|
|
// make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccAwsVPCPeeringConnectionAccepter_'
|
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2017-02-03 00:46:23 +01:00
|
|
|
"regexp"
|
2016-05-24 00:24:28 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2017-02-03 00:46:23 +01:00
|
|
|
func TestAccAwsVPCPeeringConnectionAccepter_sameAccount(t *testing.T) {
|
2016-05-24 00:24:28 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
2017-02-03 00:46:23 +01:00
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccAwsVPCPeeringConnectionAccepterDestroy,
|
2016-05-24 00:24:28 +02:00
|
|
|
Steps: []resource.TestStep{
|
2017-02-03 00:46:23 +01:00
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAwsVPCPeeringConnectionAccepterSameAccountConfig,
|
|
|
|
ExpectError: regexp.MustCompile(`aws_vpc_peering_connection_accepter can only adopt into management cross-account VPC peering connections`),
|
2016-05-24 00:24:28 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:46:23 +01:00
|
|
|
func testAccAwsVPCPeeringConnectionAccepterDestroy(s *terraform.State) error {
|
|
|
|
// We don't destroy the underlying VPC Peering Connection.
|
|
|
|
return nil
|
2016-05-24 00:24:28 +02:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:46:23 +01:00
|
|
|
const testAccAwsVPCPeeringConnectionAccepterSameAccountConfig = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-west-2"
|
|
|
|
// Requester's credentials.
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "aws" {
|
|
|
|
alias = "peer"
|
|
|
|
region = "us-west-2"
|
|
|
|
// Accepter's credentials.
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "main" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "peer" {
|
|
|
|
provider = "aws.peer"
|
|
|
|
cidr_block = "10.1.0.0/16"
|
|
|
|
}
|
|
|
|
|
|
|
|
data "aws_caller_identity" "peer" {
|
|
|
|
provider = "aws.peer"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Requester's side of the connection.
|
|
|
|
resource "aws_vpc_peering_connection" "peer" {
|
|
|
|
vpc_id = "${aws_vpc.main.id}"
|
|
|
|
peer_vpc_id = "${aws_vpc.peer.id}"
|
|
|
|
peer_owner_id = "${data.aws_caller_identity.peer.account_id}"
|
|
|
|
auto_accept = false
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Side = "Requester"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accepter's side of the connection.
|
|
|
|
resource "aws_vpc_peering_connection_accepter" "peer" {
|
|
|
|
provider = "aws.peer"
|
|
|
|
vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
|
|
|
|
auto_accept = true
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Side = "Accepter"
|
|
|
|
}
|
|
|
|
}
|
2016-05-24 00:24:28 +02:00
|
|
|
`
|