more aws acc test fixes (#12568)
* provider/aws: fix TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity * provider/aws: Randomize to fix TestAccDataSourceAwsVpc_basic
This commit is contained in:
parent
3fdeacdca7
commit
d24c761bbb
|
@ -2,24 +2,28 @@ package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccDataSourceAwsVpc_basic(t *testing.T) {
|
func TestAccDataSourceAwsVpc_basic(t *testing.T) {
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
cidr := fmt.Sprintf("172.%d.0.0/16", rand.Intn(16))
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccDataSourceAwsVpcConfig,
|
Config: testAccDataSourceAwsVpcConfig(cidr),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id"),
|
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id", cidr),
|
||||||
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_cidr"),
|
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_cidr", cidr),
|
||||||
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_tag"),
|
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_tag", cidr),
|
||||||
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_filter"),
|
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_filter", cidr),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -27,14 +31,16 @@ func TestAccDataSourceAwsVpc_basic(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccDataSourceAwsVpc_ipv6Associated(t *testing.T) {
|
func TestAccDataSourceAwsVpc_ipv6Associated(t *testing.T) {
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
cidr := fmt.Sprintf("172.%d.0.0/16", rand.Intn(16))
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccDataSourceAwsVpcConfigIpv6,
|
Config: testAccDataSourceAwsVpcConfigIpv6(cidr),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id"),
|
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id", cidr),
|
||||||
resource.TestCheckResourceAttrSet(
|
resource.TestCheckResourceAttrSet(
|
||||||
"data.aws_vpc.by_id", "ipv6_association_id"),
|
"data.aws_vpc.by_id", "ipv6_association_id"),
|
||||||
resource.TestCheckResourceAttrSet(
|
resource.TestCheckResourceAttrSet(
|
||||||
|
@ -45,7 +51,7 @@ func TestAccDataSourceAwsVpc_ipv6Associated(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc {
|
func testAccDataSourceAwsVpcCheck(name, cidr string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[name]
|
rs, ok := s.RootModule().Resources[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -67,8 +73,8 @@ func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr["cidr_block"] != "172.16.0.0/16" {
|
if attr["cidr_block"] != cidr {
|
||||||
return fmt.Errorf("bad cidr_block %s", attr["cidr_block"])
|
return fmt.Errorf("bad cidr_block %s, expected: %s", attr["cidr_block"], cidr)
|
||||||
}
|
}
|
||||||
if attr["tags.Name"] != "terraform-testacc-vpc-data-source" {
|
if attr["tags.Name"] != "terraform-testacc-vpc-data-source" {
|
||||||
return fmt.Errorf("bad Name tag %s", attr["tags.Name"])
|
return fmt.Errorf("bad Name tag %s", attr["tags.Name"])
|
||||||
|
@ -78,13 +84,14 @@ func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccDataSourceAwsVpcConfigIpv6 = `
|
func testAccDataSourceAwsVpcConfigIpv6(cidr string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-west-2"
|
region = "us-west-2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_vpc" "test" {
|
resource "aws_vpc" "test" {
|
||||||
cidr_block = "172.16.0.0/16"
|
cidr_block = "%s"
|
||||||
assign_generated_ipv6_cidr_block = true
|
assign_generated_ipv6_cidr_block = true
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
|
@ -94,16 +101,17 @@ resource "aws_vpc" "test" {
|
||||||
|
|
||||||
data "aws_vpc" "by_id" {
|
data "aws_vpc" "by_id" {
|
||||||
id = "${aws_vpc.test.id}"
|
id = "${aws_vpc.test.id}"
|
||||||
|
}`, cidr)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
const testAccDataSourceAwsVpcConfig = `
|
func testAccDataSourceAwsVpcConfig(cidr string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-west-2"
|
region = "us-west-2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_vpc" "test" {
|
resource "aws_vpc" "test" {
|
||||||
cidr_block = "172.16.0.0/16"
|
cidr_block = "%s"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-vpc-data-source"
|
Name = "terraform-testacc-vpc-data-source"
|
||||||
|
@ -129,5 +137,5 @@ data "aws_vpc" "by_filter" {
|
||||||
name = "cidr"
|
name = "cidr"
|
||||||
values = ["${aws_vpc.test.cidr_block}"]
|
values = ["${aws_vpc.test.cidr_block}"]
|
||||||
}
|
}
|
||||||
|
}`, cidr)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
|
@ -472,13 +472,15 @@ func TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity(t *testing.T) {
|
||||||
var group autoscaling.Group
|
var group autoscaling.Group
|
||||||
var tg elbv2.TargetGroup
|
var tg elbv2.TargetGroup
|
||||||
|
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity,
|
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity(rInt),
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
Check: resource.ComposeAggregateTestCheckFunc(
|
||||||
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
||||||
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
|
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
|
||||||
|
@ -1386,7 +1388,8 @@ resource "aws_autoscaling_group" "bar" {
|
||||||
`, name)
|
`, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity = `
|
func testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-west-2"
|
region = "us-west-2"
|
||||||
}
|
}
|
||||||
|
@ -1420,7 +1423,7 @@ resource "aws_alb_listener" "test_listener" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_alb_target_group" "test" {
|
resource "aws_alb_target_group" "test" {
|
||||||
name = "tf-example-alb-tg"
|
name = "tf-alb-test-%d"
|
||||||
port = 80
|
port = 80
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
vpc_id = "${aws_vpc.default.id}"
|
vpc_id = "${aws_vpc.default.id}"
|
||||||
|
@ -1431,6 +1434,10 @@ resource "aws_alb_target_group" "test" {
|
||||||
timeout = "2"
|
timeout = "2"
|
||||||
interval = "5"
|
interval = "5"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "main" {
|
resource "aws_subnet" "main" {
|
||||||
|
@ -1522,8 +1529,8 @@ resource "aws_autoscaling_group" "bar" {
|
||||||
force_delete = true
|
force_delete = true
|
||||||
termination_policies = ["OldestInstance"]
|
termination_policies = ["OldestInstance"]
|
||||||
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
||||||
|
}`, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
func testAccAWSAutoScalingGroupConfigWithSuspendedProcesses(name string) string {
|
func testAccAWSAutoScalingGroupConfigWithSuspendedProcesses(name string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
|
|
Loading…
Reference in New Issue