Merge pull request #5506 from hashicorp/b-aws-acc-test-updates

provider/aws: Randomize more things in the acceptance tests
This commit is contained in:
Clint 2016-03-08 10:06:33 -06:00
commit 2c48a7c4cb
4 changed files with 40 additions and 22 deletions

View File

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

View File

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

View File

@ -1050,6 +1050,10 @@ resource "aws_security_group" "bar" {
to_port = 80 to_port = 80
cidr_blocks = ["0.0.0.0/0"] 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"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccAWSIAMRolePolicy_basic(t *testing.T) { func TestAccAWSIAMRolePolicy_basic(t *testing.T) {
role := acctest.RandString(10)
policy1 := acctest.RandString(10)
policy2 := acctest.RandString(10)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckIAMRolePolicyDestroy, CheckDestroy: testAccCheckIAMRolePolicyDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccIAMRolePolicyConfig, Config: testAccIAMRolePolicyConfig(role, policy1),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckIAMRolePolicy( testAccCheckIAMRolePolicy(
"aws_iam_role.role", "aws_iam_role.role",
@ -27,7 +32,7 @@ func TestAccAWSIAMRolePolicy_basic(t *testing.T) {
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccIAMRolePolicyConfigUpdate, Config: testAccIAMRolePolicyConfigUpdate(role, policy1, policy2),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckIAMRolePolicy( testAccCheckIAMRolePolicy(
"aws_iam_role.role", "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" { resource "aws_iam_role" "role" {
name = "test_role" name = "tf_test_role_%s"
path = "/" path = "/"
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}" 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" { resource "aws_iam_role_policy" "foo" {
name = "foo_policy" name = "tf_test_policy_%s"
role = "${aws_iam_role.role.name}" role = "${aws_iam_role.role.name}"
policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}" 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" { resource "aws_iam_role" "role" {
name = "test_role" name = "tf_test_role_%s"
path = "/" path = "/"
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}" 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" { resource "aws_iam_role_policy" "foo" {
name = "foo_policy" name = "tf_test_policy_%s"
role = "${aws_iam_role.role.name}" role = "${aws_iam_role.role.name}"
policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}" policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}"
} }
resource "aws_iam_role_policy" "bar" { resource "aws_iam_role_policy" "bar" {
name = "bar_policy" name = "tf_test_policy_2_%s"
role = "${aws_iam_role.role.name}" role = "${aws_iam_role.role.name}"
policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}" policy = "{\"Version\":\"2012-10-17\",\"Statement\":{\"Effect\":\"Allow\",\"Action\":\"*\",\"Resource\":\"*\"}}"
} }
` `, role, policy1, policy2)
}