provider/aws: Randomize tests more to reduce conflicts

- ASG placement tests
- Randomize DynamoDB names in tests
- tag the sg created in this test to help identify in the console
- randomize policy and role names
This commit is contained in:
clint shryock 2016-03-07 16:35:07 -06:00
parent d3dff2aa79
commit 5dc387354d
4 changed files with 40 additions and 22 deletions

View File

@ -240,7 +240,7 @@ func TestAccAWSAutoScalingGroup_withPlacementGroup(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
resource.TestCheckResourceAttr(
"aws_autoscaling_group.bar", "placement_group", "test"),
"aws_autoscaling_group.bar", "placement_group", "tf_placement_test"),
),
},
},
@ -751,11 +751,11 @@ resource "aws_autoscaling_group" "bar" {
const testAccAWSAutoScalingGroupConfig_withPlacementGroup = `
resource "aws_launch_configuration" "foobar" {
image_id = "ami-21f78e11"
instance_type = "t2.micro"
instance_type = "c3.large"
}
resource "aws_placement_group" "test" {
name = "test"
name = "tf_placement_test"
strategy = "cluster"
}

View File

@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
@ -19,7 +20,7 @@ func TestAccAWSDynamoDbTable_basic(t *testing.T) {
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSDynamoDbConfigInitialState,
Config: testAccAWSDynamoDbConfigInitialState(),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table"),
),
@ -41,7 +42,7 @@ func TestAccAWSDynamoDbTable_streamSpecification(t *testing.T) {
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSDynamoDbConfigStreamSpecification,
Config: testAccAWSDynamoDbConfigStreamSpecification(),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table"),
resource.TestCheckResourceAttr(
@ -280,9 +281,10 @@ func dynamoDbAttributesToMap(attributes *[]*dynamodb.AttributeDefinition) map[st
return attrmap
}
const testAccAWSDynamoDbConfigInitialState = `
func testAccAWSDynamoDbConfigInitialState() string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "TerraformTestTable"
name = "TerraformTestTable-%d"
read_capacity = 10
write_capacity = 20
hash_key = "TestTableHashKey"
@ -317,7 +319,8 @@ resource "aws_dynamodb_table" "basic-dynamodb-table" {
projection_type = "KEYS_ONLY"
}
}
`
`, acctest.RandInt())
}
const testAccAWSDynamoDbConfigAddSecondaryGSI = `
resource "aws_dynamodb_table" "basic-dynamodb-table" {
@ -359,9 +362,10 @@ resource "aws_dynamodb_table" "basic-dynamodb-table" {
}
`
const testAccAWSDynamoDbConfigStreamSpecification = `
func testAccAWSDynamoDbConfigStreamSpecification() string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "TerraformTestStreamTable"
name = "TerraformTestStreamTable-%d"
read_capacity = 10
write_capacity = 20
hash_key = "TestTableHashKey"
@ -398,4 +402,5 @@ resource "aws_dynamodb_table" "basic-dynamodb-table" {
stream_enabled = true
stream_view_type = "KEYS_ONLY"
}
`
`, acctest.RandInt())
}

View File

@ -1050,6 +1050,10 @@ resource "aws_security_group" "bar" {
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "tf_elb_sg_test"
}
}
`

View File

@ -7,18 +7,23 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSIAMRolePolicy_basic(t *testing.T) {
role := acctest.RandString(10)
policy1 := acctest.RandString(10)
policy2 := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIAMRolePolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccIAMRolePolicyConfig,
Config: testAccIAMRolePolicyConfig(role, policy1),
Check: resource.ComposeTestCheckFunc(
testAccCheckIAMRolePolicy(
"aws_iam_role.role",
@ -27,7 +32,7 @@ func TestAccAWSIAMRolePolicy_basic(t *testing.T) {
),
},
resource.TestStep{
Config: testAccIAMRolePolicyConfigUpdate,
Config: testAccIAMRolePolicyConfigUpdate(role, policy1, policy2),
Check: resource.ComposeTestCheckFunc(
testAccCheckIAMRolePolicy(
"aws_iam_role.role",
@ -105,36 +110,40 @@ func testAccCheckIAMRolePolicy(
}
}
const testAccIAMRolePolicyConfig = `
func testAccIAMRolePolicyConfig(role, policy1 string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "role" {
name = "test_role"
name = "tf_test_role_%s"
path = "/"
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}"
}
resource "aws_iam_role_policy" "foo" {
name = "foo_policy"
name = "tf_test_policy_%s"
role = "${aws_iam_role.role.name}"
policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}"
}
`
`, role, policy1)
}
const testAccIAMRolePolicyConfigUpdate = `
func testAccIAMRolePolicyConfigUpdate(role, policy1, policy2 string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "role" {
name = "test_role"
name = "tf_test_role_%s"
path = "/"
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}"
}
resource "aws_iam_role_policy" "foo" {
name = "foo_policy"
name = "tf_test_policy_%s"
role = "${aws_iam_role.role.name}"
policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}"
}
resource "aws_iam_role_policy" "bar" {
name = "bar_policy"
name = "tf_test_policy_2_%s"
role = "${aws_iam_role.role.name}"
policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}"
}
`
`, role, policy1, policy2)
}