Skip to content

Commit

Permalink
Merge pull request #15008 from terraform-providers/t-gov-elasti-subgrp
Browse files Browse the repository at this point in the history
tests/provider: Fix hardcoded AZs (elasticache subnet grp)
  • Loading branch information
YakDriver authored Sep 8, 2020
2 parents 7035c19 + f84f4c8 commit acdb900
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions aws/resource_aws_elasticache_subnet_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) {
var csg elasticache.CacheSubnetGroup
config := fmt.Sprintf(testAccAWSElasticacheSubnetGroupConfig, acctest.RandInt())
resourceName := "aws_elasticache_subnet_group.test"

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -23,7 +22,7 @@ func TestAccAWSElasticacheSubnetGroup_basic(t *testing.T) {
CheckDestroy: testAccCheckAWSElasticacheSubnetGroupDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAWSElasticacheSubnetGroupConfig(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheSubnetGroupExists(resourceName, &csg),
resource.TestCheckResourceAttr(
Expand All @@ -45,16 +44,14 @@ func TestAccAWSElasticacheSubnetGroup_update(t *testing.T) {
var csg elasticache.CacheSubnetGroup
resourceName := "aws_elasticache_subnet_group.test"
rInt := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPre, rInt)
postConfig := fmt.Sprintf(testAccAWSElasticacheSubnetGroupUpdateConfigPost, rInt)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSElasticacheSubnetGroupDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Config: testAccAWSElasticacheSubnetGroupUpdateConfigPre(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheSubnetGroupExists(resourceName, &csg),
testAccCheckAWSElastiCacheSubnetGroupAttrs(&csg, resourceName, 1),
Expand All @@ -68,7 +65,7 @@ func TestAccAWSElasticacheSubnetGroup_update(t *testing.T) {
"description"},
},
{
Config: postConfig,
Config: testAccAWSElasticacheSubnetGroupUpdateConfigPost(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheSubnetGroupExists(resourceName, &csg),
testAccCheckAWSElastiCacheSubnetGroupAttrs(&csg, resourceName, 2),
Expand Down Expand Up @@ -154,7 +151,8 @@ func testAccCheckAWSElastiCacheSubnetGroupAttrs(csg *elasticache.CacheSubnetGrou
}
}

var testAccAWSElasticacheSubnetGroupConfig = `
func testAccAWSElasticacheSubnetGroupConfig(rInt int) string {
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "192.168.0.0/16"
Expand All @@ -166,7 +164,7 @@ resource "aws_vpc" "foo" {
resource "aws_subnet" "foo" {
vpc_id = aws_vpc.foo.id
cidr_block = "192.168.0.0/20"
availability_zone = "us-west-2a"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elasticache-subnet-group"
Expand All @@ -180,8 +178,11 @@ resource "aws_elasticache_subnet_group" "test" {
name = "tf-TEST-cache-subnet-%03d"
subnet_ids = [aws_subnet.foo.id]
}
`
var testAccAWSElasticacheSubnetGroupUpdateConfigPre = `
`, rInt))
}

func testAccAWSElasticacheSubnetGroupUpdateConfigPre(rInt int) string {
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "10.0.0.0/16"
Expand All @@ -193,7 +194,7 @@ resource "aws_vpc" "foo" {
resource "aws_subnet" "foo" {
vpc_id = aws_vpc.foo.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-west-2a"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elasticache-subnet-group-update-foo"
Expand All @@ -205,21 +206,23 @@ resource "aws_elasticache_subnet_group" "test" {
description = "tf-test-cache-subnet-group-descr"
subnet_ids = [aws_subnet.foo.id]
}
`
`, rInt))
}

var testAccAWSElasticacheSubnetGroupUpdateConfigPost = `
func testAccAWSElasticacheSubnetGroupUpdateConfigPost(rInt int) string {
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform-testacc-elasticache-subnet-group-update"
Name = "terraform-testacc-elasticache-subnet-group-update"
}
}
resource "aws_subnet" "foo" {
vpc_id = aws_vpc.foo.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-west-2a"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elasticache-subnet-group-update-foo"
Expand All @@ -229,7 +232,7 @@ resource "aws_subnet" "foo" {
resource "aws_subnet" "test" {
vpc_id = aws_vpc.foo.id
cidr_block = "10.0.2.0/24"
availability_zone = "us-west-2a"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "tf-acc-elasticache-subnet-group-update-test"
Expand All @@ -244,4 +247,5 @@ resource "aws_elasticache_subnet_group" "test" {
aws_subnet.test.id,
]
}
`
`, rInt))
}

0 comments on commit acdb900

Please sign in to comment.