github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_vpc_peering_connection_accepter_test.go (about)

     1  // make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccAwsVPCPeeringConnectionAccepter_'
     2  package aws
     3  
     4  import (
     5  	"regexp"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  	"github.com/hashicorp/terraform/terraform"
    10  )
    11  
    12  func TestAccAwsVPCPeeringConnectionAccepter_sameAccount(t *testing.T) {
    13  	resource.Test(t, resource.TestCase{
    14  		PreCheck:     func() { testAccPreCheck(t) },
    15  		Providers:    testAccProviders,
    16  		CheckDestroy: testAccAwsVPCPeeringConnectionAccepterDestroy,
    17  		Steps: []resource.TestStep{
    18  			resource.TestStep{
    19  				Config:      testAccAwsVPCPeeringConnectionAccepterSameAccountConfig,
    20  				ExpectError: regexp.MustCompile(`aws_vpc_peering_connection_accepter can only adopt into management cross-account VPC peering connections`),
    21  			},
    22  		},
    23  	})
    24  }
    25  
    26  func testAccAwsVPCPeeringConnectionAccepterDestroy(s *terraform.State) error {
    27  	// We don't destroy the underlying VPC Peering Connection.
    28  	return nil
    29  }
    30  
    31  const testAccAwsVPCPeeringConnectionAccepterSameAccountConfig = `
    32  provider "aws" {
    33      region = "us-west-2"
    34      // Requester's credentials.
    35  }
    36  
    37  provider "aws" {
    38      alias = "peer"
    39      region = "us-west-2"
    40      // Accepter's credentials.
    41  }
    42  
    43  resource "aws_vpc" "main" {
    44      cidr_block = "10.0.0.0/16"
    45  }
    46  
    47  resource "aws_vpc" "peer" {
    48      provider = "aws.peer"
    49      cidr_block = "10.1.0.0/16"
    50  }
    51  
    52  data "aws_caller_identity" "peer" {
    53      provider = "aws.peer"
    54  }
    55  
    56  // Requester's side of the connection.
    57  resource "aws_vpc_peering_connection" "peer" {
    58      vpc_id = "${aws_vpc.main.id}"
    59      peer_vpc_id = "${aws_vpc.peer.id}"
    60      peer_owner_id = "${data.aws_caller_identity.peer.account_id}"
    61      auto_accept = false
    62  
    63      tags {
    64        Side = "Requester"
    65      }
    66  }
    67  
    68  // Accepter's side of the connection.
    69  resource "aws_vpc_peering_connection_accepter" "peer" {
    70      provider = "aws.peer"
    71      vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
    72      auto_accept = true
    73  
    74      tags {
    75         Side = "Accepter"
    76      }
    77  }
    78  `