github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/data_source_aws_vpc_endpoint_test.go (about) 1 // make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccDataSourceAwsVpcEndpoint_' 2 package aws 3 4 import ( 5 "fmt" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccDataSourceAwsVpcEndpoint_basic(t *testing.T) { 13 resource.Test(t, resource.TestCase{ 14 PreCheck: func() { testAccPreCheck(t) }, 15 Providers: testAccProviders, 16 Steps: []resource.TestStep{ 17 resource.TestStep{ 18 Config: testAccDataSourceAwsVpcEndpointConfig, 19 Check: resource.ComposeTestCheckFunc( 20 testAccDataSourceAwsVpcEndpointCheckExists("data.aws_vpc_endpoint.s3"), 21 ), 22 ExpectNonEmptyPlan: true, 23 }, 24 }, 25 }) 26 } 27 28 func TestAccDataSourceAwsVpcEndpoint_withRouteTable(t *testing.T) { 29 resource.Test(t, resource.TestCase{ 30 PreCheck: func() { testAccPreCheck(t) }, 31 Providers: testAccProviders, 32 Steps: []resource.TestStep{ 33 resource.TestStep{ 34 Config: testAccDataSourceAwsVpcEndpointWithRouteTableConfig, 35 Check: resource.ComposeTestCheckFunc( 36 testAccDataSourceAwsVpcEndpointCheckExists("data.aws_vpc_endpoint.s3"), 37 resource.TestCheckResourceAttr( 38 "data.aws_vpc_endpoint.s3", "route_table_ids.#", "1"), 39 ), 40 ExpectNonEmptyPlan: true, 41 }, 42 }, 43 }) 44 } 45 46 func testAccDataSourceAwsVpcEndpointCheckExists(name string) resource.TestCheckFunc { 47 return func(s *terraform.State) error { 48 rs, ok := s.RootModule().Resources[name] 49 if !ok { 50 return fmt.Errorf("root module has no resource called %s", name) 51 } 52 53 vpceRs, ok := s.RootModule().Resources["aws_vpc_endpoint.s3"] 54 if !ok { 55 return fmt.Errorf("can't find aws_vpc_endpoint.s3 in state") 56 } 57 58 attr := rs.Primary.Attributes 59 60 if attr["id"] != vpceRs.Primary.Attributes["id"] { 61 return fmt.Errorf( 62 "id is %s; want %s", 63 attr["id"], 64 vpceRs.Primary.Attributes["id"], 65 ) 66 } 67 68 return nil 69 } 70 } 71 72 const testAccDataSourceAwsVpcEndpointConfig = ` 73 provider "aws" { 74 region = "us-west-2" 75 } 76 77 resource "aws_vpc" "foo" { 78 cidr_block = "10.1.0.0/16" 79 80 tags { 81 Name = "terraform-testacc-vpc-endpoint-data-source-foo" 82 } 83 } 84 85 resource "aws_vpc_endpoint" "s3" { 86 vpc_id = "${aws_vpc.foo.id}" 87 service_name = "com.amazonaws.us-west-2.s3" 88 } 89 90 data "aws_vpc_endpoint" "s3" { 91 vpc_id = "${aws_vpc.foo.id}" 92 service_name = "com.amazonaws.us-west-2.s3" 93 state = "available" 94 95 depends_on = ["aws_vpc_endpoint.s3"] 96 } 97 ` 98 99 const testAccDataSourceAwsVpcEndpointWithRouteTableConfig = ` 100 provider "aws" { 101 region = "us-west-2" 102 } 103 104 resource "aws_vpc" "foo" { 105 cidr_block = "10.1.0.0/16" 106 107 tags { 108 Name = "terraform-testacc-vpc-endpoint-data-source-foo" 109 } 110 } 111 112 resource "aws_route_table" "rt" { 113 vpc_id = "${aws_vpc.foo.id}" 114 } 115 116 resource "aws_vpc_endpoint" "s3" { 117 vpc_id = "${aws_vpc.foo.id}" 118 service_name = "com.amazonaws.us-west-2.s3" 119 route_table_ids = ["${aws_route_table.rt.id}"] 120 } 121 122 data "aws_vpc_endpoint" "s3" { 123 vpc_id = "${aws_vpc.foo.id}" 124 service_name = "com.amazonaws.us-west-2.s3" 125 state = "available" 126 127 depends_on = ["aws_vpc_endpoint.s3"] 128 } 129 `