Skip to content

Commit

Permalink
Tidy up ELB subnet acceptance test configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Jun 15, 2023
1 parent 9e3bf16 commit 0b48855
Showing 1 changed file with 50 additions and 184 deletions.
234 changes: 50 additions & 184 deletions internal/service/elb/load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ func TestAccELBLoadBalancer_ListenerSSLCertificateID_iamServerCertificate(t *tes
func TestAccELBLoadBalancer_Swap_subnets(t *testing.T) {
ctx := acctest.Context(t)
var conf elb.LoadBalancerDescription
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_elb.test"

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -610,21 +611,21 @@ func TestAccELBLoadBalancer_Swap_subnets(t *testing.T) {
CheckDestroy: testAccCheckLoadBalancerDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccLoadBalancerConfig_subnets,
Config: testAccLoadBalancerConfig_subnets(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoadBalancerExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "subnets.#", "2"),
),
},
{
Config: testAccLoadBalancerConfig_subnetSwap,
Config: testAccLoadBalancerConfig_subnetSwap(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoadBalancerExists(ctx, "aws_elb.test", &conf),
resource.TestCheckResourceAttr("aws_elb.test", "subnets.#", "2"),
),
},
{
Config: testAccLoadBalancerConfig_subnetCompleteSwap,
Config: testAccLoadBalancerConfig_subnetCompleteSwap(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLoadBalancerExists(ctx, "aws_elb.test", &conf),
resource.TestCheckResourceAttr("aws_elb.test", "subnets.#", "2"),
Expand Down Expand Up @@ -1605,157 +1606,107 @@ resource "aws_elb" "test" {
`, rName, acctest.TLSPEMEscapeNewlines(certificate), acctest.TLSPEMEscapeNewlines(key)))
}

const testAccLoadBalancerConfig_subnets = `
data "aws_availability_zones" "available" {
state = "available"
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}
resource "aws_vpc" "azelb" {
cidr_block = "10.1.0.0/16"
func testAccLoadBalancerConfig_baseSubnets(rName string) string {
return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags = {
Name = "terraform-testacc-elb-subnets"
}
}
resource "aws_subnet" "public_a_one" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.1.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elb-subnets-a-one"
Name = %[1]q
}
}
resource "aws_subnet" "public_b_one" {
vpc_id = aws_vpc.azelb.id
resource "aws_subnet" "test" {
count = %[2]d
cidr_block = "10.1.7.0/24"
availability_zone = data.aws_availability_zones.available.names[1]
vpc_id = aws_vpc.test.id
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index)
tags = {
Name = "tf-acc-elb-subnets-b-one"
Name = %[1]q
}
}
resource "aws_subnet" "public_a_two" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.2.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elb-subnets-a-two"
}
`, rName))
}

func testAccLoadBalancerConfig_subnets(rName string) string {
return acctest.ConfigCompose(testAccLoadBalancerConfig_baseSubnets(rName), fmt.Sprintf(`
resource "aws_elb" "test" {
subnets = [
aws_subnet.public_a_one.id,
aws_subnet.public_b_one.id,
]
name = %[1]q
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
depends_on = [aws_internet_gateway.gw]
depends_on = [aws_internet_gateway.test]
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.azelb.id
tags = {
Name = "main"
}
`, rName))
}
`

const testAccLoadBalancerConfig_subnetSwap = `
data "aws_availability_zones" "available" {
state = "available"
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}
func testAccLoadBalancerConfig_subnetSwap(rName string) string {
return acctest.ConfigCompose(testAccLoadBalancerConfig_baseSubnets(rName), fmt.Sprintf(`
resource "aws_elb" "test" {
subnets = [
aws_subnet.public_a_two.id,
aws_subnet.public_b_one.id,
]
resource "aws_vpc" "azelb" {
cidr_block = "10.1.0.0/16"
enable_dns_hostnames = true
name = %[1]q
tags = {
Name = "terraform-testacc-elb-subnet-swap"
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
}
resource "aws_subnet" "public_a_one" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.1.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elb-subnet-swap-a-one"
}
depends_on = [aws_internet_gateway.test]
}
`, rName))
}

resource "aws_subnet" "public_b_one" {
vpc_id = aws_vpc.azelb.id
func testAccLoadBalancerConfig_subnetCompleteSwap(rName string) string {
return acctest.ConfigCompose(testAccLoadBalancerConfig_baseSubnets(rName), fmt.Sprintf(`
resource "aws_subnet" "public_b_two" {
vpc_id = aws_vpc.test.id
cidr_block = "10.1.7.0/24"
cidr_block = "10.1.6.0/24"
availability_zone = data.aws_availability_zones.available.names[1]
tags = {
Name = "tf-acc-elb-subnet-swap-b-one"
}
}
resource "aws_subnet" "public_a_two" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.2.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elb-subnet-swap-a-two"
Name = %[1]q
}
}
resource "aws_elb" "test" {
subnets = [
aws_subnet.public_a_two.id,
aws_subnet.public_b_one.id,
aws_subnet.public_a_one.id,
aws_subnet.public_b_two.id,
]
name = %[1]q
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
depends_on = [aws_internet_gateway.gw]
depends_on = [aws_internet_gateway.test]
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.azelb.id
tags = {
Name = "main"
}
`, rName))
}
`

func testAccLoadBalancerConfig_desyncMitigationMode(rName string) string {
return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(`
Expand Down Expand Up @@ -1811,88 +1762,3 @@ resource "aws_elb" "test" {
}
`, rName))
}

const testAccLoadBalancerConfig_subnetCompleteSwap = `
data "aws_availability_zones" "available" {
state = "available"
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}
resource "aws_vpc" "azelb" {
cidr_block = "10.1.0.0/16"
enable_dns_hostnames = true
tags = {
Name = "terraform-testacc-elb-subnet-swap"
}
}
resource "aws_subnet" "public_a_one" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.1.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elb-subnet-swap-a-one"
}
}
resource "aws_subnet" "public_b_one" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.7.0/24"
availability_zone = data.aws_availability_zones.available.names[1]
tags = {
Name = "tf-acc-elb-subnet-swap-b-one"
}
}
resource "aws_subnet" "public_b_two" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.6.0/24"
availability_zone = data.aws_availability_zones.available.names[1]
tags = {
Name = "tf-acc-elb-subnet-swap-b-two"
}
}
resource "aws_subnet" "public_a_two" {
vpc_id = aws_vpc.azelb.id
cidr_block = "10.1.2.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elb-subnet-swap-a-two"
}
}
resource "aws_elb" "test" {
subnets = [
aws_subnet.public_a_one.id,
aws_subnet.public_b_two.id,
]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
depends_on = [aws_internet_gateway.gw]
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.azelb.id
tags = {
Name = "main"
}
}
`

0 comments on commit 0b48855

Please sign in to comment.