Skip to content

Commit

Permalink
Add a real '_basic' acceptance test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit Ewbank authored and Kit Ewbank committed Jun 10, 2019
1 parent 6b74170 commit d5f72ee
Showing 1 changed file with 75 additions and 77 deletions.
152 changes: 75 additions & 77 deletions aws/resource_aws_vpc_endpoint_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,38 @@ func TestAccAWSVpcEndpointService_basic(t *testing.T) {
CheckDestroy: testAccCheckVpcEndpointServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccVpcEndpointServiceConfig_basic(rName1),
Config: testAccVpcEndpointServiceConfig_basic(rName1, rName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcEndpointServiceExists(resourceName, &svcCfg),
resource.TestCheckResourceAttr(resourceName, "acceptance_required", "false"),
resource.TestCheckResourceAttr(resourceName, "network_load_balancer_arns.#", "1"),
resource.TestCheckResourceAttr(resourceName, "allowed_principals.#", "0"),
resource.TestCheckResourceAttr(resourceName, "manages_vpc_endpoints", "false"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSVpcEndpointService_AllowedPrincipalsAndTags(t *testing.T) {
var svcCfg ec2.ServiceConfiguration
resourceName := "aws_vpc_endpoint_service.test"
rName1 := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
rName2 := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcEndpointServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccVpcEndpointServiceConfig_allowedPrincipalsAndTags(rName1, rName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcEndpointServiceExists(resourceName, &svcCfg),
resource.TestCheckResourceAttr(resourceName, "acceptance_required", "false"),
Expand All @@ -111,7 +142,7 @@ func TestAccAWSVpcEndpointService_basic(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccVpcEndpointServiceConfig_modified(rName1, rName2),
Config: testAccVpcEndpointServiceConfig_allowedPrincipalsAndTagsUpdated(rName1, rName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcEndpointServiceExists(resourceName, &svcCfg),
resource.TestCheckResourceAttr(resourceName, "acceptance_required", "true"),
Expand All @@ -129,7 +160,8 @@ func TestAccAWSVpcEndpointService_basic(t *testing.T) {
func TestAccAWSVpcEndpointService_removed(t *testing.T) {
var svcCfg ec2.ServiceConfiguration
resourceName := "aws_vpc_endpoint_service.test"
rName := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
rName1 := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
rName2 := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))

testDestroy := func(*terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
Expand All @@ -147,7 +179,7 @@ func TestAccAWSVpcEndpointService_removed(t *testing.T) {
CheckDestroy: testAccCheckVpcEndpointServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccVpcEndpointServiceConfig_basic(rName),
Config: testAccVpcEndpointServiceConfig_basic(rName1, rName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcEndpointServiceExists(resourceName, &svcCfg),
testDestroy,
Expand Down Expand Up @@ -215,7 +247,7 @@ func testAccCheckVpcEndpointServiceExists(n string, svcCfg *ec2.ServiceConfigura
}
}

func testAccVpcEndpointServiceConfig_basic(rName string) string {
func testAccVpcEndpointServiceConfig_base(rName1, rName2 string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
Expand Down Expand Up @@ -243,6 +275,24 @@ resource "aws_lb" "test1" {
}
}
resource "aws_lb" "test2" {
name = %[2]q
subnets = [
"${aws_subnet.test1.id}",
"${aws_subnet.test2.id}",
]
load_balancer_type = "network"
internal = true
idle_timeout = 60
enable_deletion_protection = false
tags = {
Name = %[2]q
}
}
data "aws_availability_zones" "available" {}
resource "aws_subnet" "test1" {
Expand All @@ -266,97 +316,45 @@ resource "aws_subnet" "test2" {
}
data "aws_caller_identity" "current" {}
`, rName1, rName2)
}

func testAccVpcEndpointServiceConfig_basic(rName1, rName2 string) string {
return testAccVpcEndpointServiceConfig_base(rName1, rName2) + fmt.Sprintf(`
resource "aws_vpc_endpoint_service" "test" {
acceptance_required = false
network_load_balancer_arns = [
"${aws_lb.test1.arn}",
]
allowed_principals = [
"${data.aws_caller_identity.current.arn}",
]
tags = {
Environment = "test"
Usage = "original"
Name = %[1]q
}
}
`, rName)
`)
}

func testAccVpcEndpointServiceConfig_modified(rName1, rName2 string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = %[1]q
}
}
resource "aws_lb" "test1" {
name = %[1]q
func testAccVpcEndpointServiceConfig_allowedPrincipalsAndTags(rName1, rName2 string) string {
return testAccVpcEndpointServiceConfig_base(rName1, rName2) + fmt.Sprintf(`
resource "aws_vpc_endpoint_service" "test" {
acceptance_required = false
subnets = [
"${aws_subnet.test1.id}",
"${aws_subnet.test2.id}",
network_load_balancer_arns = [
"${aws_lb.test1.arn}",
]
load_balancer_type = "network"
internal = true
idle_timeout = 60
enable_deletion_protection = false
tags = {
Name = %[1]q
}
}
resource "aws_lb" "test2" {
name = %[2]q
subnets = [
"${aws_subnet.test1.id}",
"${aws_subnet.test2.id}",
allowed_principals = [
"${data.aws_caller_identity.current.arn}",
]
load_balancer_type = "network"
internal = true
idle_timeout = 60
enable_deletion_protection = false
tags = {
Name = %[2]q
}
}
data "aws_availability_zones" "available" {}
resource "aws_subnet" "test1" {
vpc_id = "${aws_vpc.test.id}"
cidr_block = "10.0.1.0/24"
availability_zone = "${data.aws_availability_zones.available.names[0]}"
tags = {
Name = %[1]q
Environment = "test"
Usage = "original"
Name = %[1]q
}
}
resource "aws_subnet" "test2" {
vpc_id = "${aws_vpc.test.id}"
cidr_block = "10.0.2.0/24"
availability_zone = "${data.aws_availability_zones.available.names[1]}"
tags = {
Name = %[1]q
}
`, rName1)
}

data "aws_caller_identity" "current" {}
func testAccVpcEndpointServiceConfig_allowedPrincipalsAndTagsUpdated(rName1, rName2 string) string {
return testAccVpcEndpointServiceConfig_base(rName1, rName2) + fmt.Sprintf(`
resource "aws_vpc_endpoint_service" "test" {
acceptance_required = true
Expand All @@ -372,5 +370,5 @@ resource "aws_vpc_endpoint_service" "test" {
Name = %[1]q
}
}
`, rName1, rName2)
`, rName1)
}

0 comments on commit d5f72ee

Please sign in to comment.