Skip to content

Commit 3d3609c

Browse files
authored
provider/aws: Fixing up acceptance tests after seeing concurrent (hashicorp#10362)
failures * codecommit * cloudwatch_logs
1 parent bbf133f commit 3d3609c

3 files changed

Lines changed: 61 additions & 35 deletions

File tree

builtin/providers/aws/import_aws_cloudwatch_log_group_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ package aws
33
import (
44
"testing"
55

6+
"github.com/hashicorp/terraform/helper/acctest"
67
"github.com/hashicorp/terraform/helper/resource"
78
)
89

910
func TestAccAWSCloudWatchLogGroup_importBasic(t *testing.T) {
1011
resourceName := "aws_cloudwatch_log_group.foobar"
12+
rInt := acctest.RandInt()
1113

1214
resource.Test(t, resource.TestCase{
1315
PreCheck: func() { testAccPreCheck(t) },
1416
Providers: testAccProviders,
1517
CheckDestroy: testAccCheckAWSCloudWatchLogGroupDestroy,
1618
Steps: []resource.TestStep{
1719
resource.TestStep{
18-
Config: testAccAWSCloudWatchLogGroupConfig,
20+
Config: testAccAWSCloudWatchLogGroupConfig(rInt),
1921
},
2022

2123
resource.TestStep{

builtin/providers/aws/resource_aws_cloudwatch_log_group_test.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ import (
55
"testing"
66

77
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
8+
"github.com/hashicorp/terraform/helper/acctest"
89
"github.com/hashicorp/terraform/helper/resource"
910
"github.com/hashicorp/terraform/terraform"
1011
)
1112

1213
func TestAccAWSCloudWatchLogGroup_basic(t *testing.T) {
1314
var lg cloudwatchlogs.LogGroup
15+
rInt := acctest.RandInt()
1416

1517
resource.Test(t, resource.TestCase{
1618
PreCheck: func() { testAccPreCheck(t) },
1719
Providers: testAccProviders,
1820
CheckDestroy: testAccCheckAWSCloudWatchLogGroupDestroy,
1921
Steps: []resource.TestStep{
2022
resource.TestStep{
21-
Config: testAccAWSCloudWatchLogGroupConfig,
23+
Config: testAccAWSCloudWatchLogGroupConfig(rInt),
2224
Check: resource.ComposeTestCheckFunc(
2325
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg),
2426
resource.TestCheckResourceAttr("aws_cloudwatch_log_group.foobar", "retention_in_days", "0"),
@@ -30,21 +32,22 @@ func TestAccAWSCloudWatchLogGroup_basic(t *testing.T) {
3032

3133
func TestAccAWSCloudWatchLogGroup_retentionPolicy(t *testing.T) {
3234
var lg cloudwatchlogs.LogGroup
35+
rInt := acctest.RandInt()
3336

3437
resource.Test(t, resource.TestCase{
3538
PreCheck: func() { testAccPreCheck(t) },
3639
Providers: testAccProviders,
3740
CheckDestroy: testAccCheckAWSCloudWatchLogGroupDestroy,
3841
Steps: []resource.TestStep{
3942
resource.TestStep{
40-
Config: testAccAWSCloudWatchLogGroupConfig_withRetention,
43+
Config: testAccAWSCloudWatchLogGroupConfig_withRetention(rInt),
4144
Check: resource.ComposeTestCheckFunc(
4245
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg),
4346
resource.TestCheckResourceAttr("aws_cloudwatch_log_group.foobar", "retention_in_days", "365"),
4447
),
4548
},
4649
resource.TestStep{
47-
Config: testAccAWSCloudWatchLogGroupConfigModified_withRetention,
50+
Config: testAccAWSCloudWatchLogGroupConfigModified_withRetention(rInt),
4851
Check: resource.ComposeTestCheckFunc(
4952
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg),
5053
resource.TestCheckResourceAttr("aws_cloudwatch_log_group.foobar", "retention_in_days", "0"),
@@ -56,14 +59,15 @@ func TestAccAWSCloudWatchLogGroup_retentionPolicy(t *testing.T) {
5659

5760
func TestAccAWSCloudWatchLogGroup_multiple(t *testing.T) {
5861
var lg cloudwatchlogs.LogGroup
62+
rInt := acctest.RandInt()
5963

6064
resource.Test(t, resource.TestCase{
6165
PreCheck: func() { testAccPreCheck(t) },
6266
Providers: testAccProviders,
6367
CheckDestroy: testAccCheckAWSCloudWatchLogGroupDestroy,
6468
Steps: []resource.TestStep{
6569
resource.TestStep{
66-
Config: testAccAWSCloudWatchLogGroupConfig_multiple,
70+
Config: testAccAWSCloudWatchLogGroupConfig_multiple(rInt),
6771
Check: resource.ComposeTestCheckFunc(
6872
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.alpha", &lg),
6973
resource.TestCheckResourceAttr("aws_cloudwatch_log_group.alpha", "retention_in_days", "14"),
@@ -79,14 +83,15 @@ func TestAccAWSCloudWatchLogGroup_multiple(t *testing.T) {
7983

8084
func TestAccAWSCloudWatchLogGroup_disappears(t *testing.T) {
8185
var lg cloudwatchlogs.LogGroup
86+
rInt := acctest.RandInt()
8287

8388
resource.Test(t, resource.TestCase{
8489
PreCheck: func() { testAccPreCheck(t) },
8590
Providers: testAccProviders,
8691
CheckDestroy: testAccCheckAWSCloudWatchLogGroupDestroy,
8792
Steps: []resource.TestStep{
8893
resource.TestStep{
89-
Config: testAccAWSCloudWatchLogGroupConfig,
94+
Config: testAccAWSCloudWatchLogGroupConfig(rInt),
9095
Check: resource.ComposeTestCheckFunc(
9196
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg),
9297
testAccCheckCloudWatchLogGroupDisappears(&lg),
@@ -153,35 +158,43 @@ func testAccCheckAWSCloudWatchLogGroupDestroy(s *terraform.State) error {
153158
return nil
154159
}
155160

156-
var testAccAWSCloudWatchLogGroupConfig = `
161+
func testAccAWSCloudWatchLogGroupConfig(rInt int) string {
162+
return fmt.Sprintf(`
157163
resource "aws_cloudwatch_log_group" "foobar" {
158-
name = "foo-bar"
164+
name = "foo-bar-%d"
165+
}
166+
`, rInt)
159167
}
160-
`
161168

162-
var testAccAWSCloudWatchLogGroupConfig_withRetention = `
169+
func testAccAWSCloudWatchLogGroupConfig_withRetention(rInt int) string {
170+
return fmt.Sprintf(`
163171
resource "aws_cloudwatch_log_group" "foobar" {
164-
name = "foo-bang"
172+
name = "foo-bar-%d"
165173
retention_in_days = 365
166174
}
167-
`
175+
`, rInt)
176+
}
168177

169-
var testAccAWSCloudWatchLogGroupConfigModified_withRetention = `
178+
func testAccAWSCloudWatchLogGroupConfigModified_withRetention(rInt int) string {
179+
return fmt.Sprintf(`
170180
resource "aws_cloudwatch_log_group" "foobar" {
171-
name = "foo-bang"
181+
name = "foo-bar-%d"
182+
}
183+
`, rInt)
172184
}
173-
`
174185

175-
var testAccAWSCloudWatchLogGroupConfig_multiple = `
186+
func testAccAWSCloudWatchLogGroupConfig_multiple(rInt int) string {
187+
return fmt.Sprintf(`
176188
resource "aws_cloudwatch_log_group" "alpha" {
177-
name = "foo-bar"
189+
name = "foo-bar-%d"
178190
retention_in_days = 14
179191
}
180192
resource "aws_cloudwatch_log_group" "beta" {
181-
name = "foo-bara"
193+
name = "foo-bar-%d"
182194
}
183195
resource "aws_cloudwatch_log_group" "charlie" {
184-
name = "foo-baraa"
196+
name = "foo-bar-%d"
185197
retention_in_days = 3653
186198
}
187-
`
199+
`, rInt, rInt, rInt)
200+
}

builtin/providers/aws/resource_aws_codecommit_repository_test.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ import (
77
"github.com/aws/aws-sdk-go/aws"
88
"github.com/aws/aws-sdk-go/aws/awserr"
99
"github.com/aws/aws-sdk-go/service/codecommit"
10+
"github.com/hashicorp/terraform/helper/acctest"
1011
"github.com/hashicorp/terraform/helper/resource"
1112
"github.com/hashicorp/terraform/terraform"
1213
)
1314

1415
func TestAccAWSCodeCommitRepository_basic(t *testing.T) {
16+
rInt := acctest.RandInt()
1517
resource.Test(t, resource.TestCase{
1618
PreCheck: func() { testAccPreCheck(t) },
1719
Providers: testAccProviders,
1820
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
1921
Steps: []resource.TestStep{
2022
resource.TestStep{
21-
Config: testAccCodeCommitRepository_basic,
23+
Config: testAccCodeCommitRepository_basic(rInt),
2224
Check: resource.ComposeTestCheckFunc(
2325
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
2426
),
@@ -28,21 +30,22 @@ func TestAccAWSCodeCommitRepository_basic(t *testing.T) {
2830
}
2931

3032
func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) {
33+
rInt := acctest.RandInt()
3134
resource.Test(t, resource.TestCase{
3235
PreCheck: func() { testAccPreCheck(t) },
3336
Providers: testAccProviders,
3437
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
3538
Steps: []resource.TestStep{
3639
resource.TestStep{
37-
Config: testAccCodeCommitRepository_basic,
40+
Config: testAccCodeCommitRepository_basic(rInt),
3841
Check: resource.ComposeTestCheckFunc(
3942
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
4043
resource.TestCheckResourceAttr(
4144
"aws_codecommit_repository.test", "description", "This is a test description"),
4245
),
4346
},
4447
resource.TestStep{
45-
Config: testAccCodeCommitRepository_withChanges,
48+
Config: testAccCodeCommitRepository_withChanges(rInt),
4649
Check: resource.ComposeTestCheckFunc(
4750
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
4851
resource.TestCheckResourceAttr(
@@ -54,13 +57,14 @@ func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) {
5457
}
5558

5659
func TestAccAWSCodeCommitRepository_create_default_branch(t *testing.T) {
60+
rInt := acctest.RandInt()
5761
resource.Test(t, resource.TestCase{
5862
PreCheck: func() { testAccPreCheck(t) },
5963
Providers: testAccProviders,
6064
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
6165
Steps: []resource.TestStep{
6266
resource.TestStep{
63-
Config: testAccCodeCommitRepository_with_default_branch,
67+
Config: testAccCodeCommitRepository_with_default_branch(rInt),
6468
Check: resource.ComposeTestCheckFunc(
6569
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
6670
resource.TestCheckResourceAttr(
@@ -72,21 +76,22 @@ func TestAccAWSCodeCommitRepository_create_default_branch(t *testing.T) {
7276
}
7377

7478
func TestAccAWSCodeCommitRepository_create_and_update_default_branch(t *testing.T) {
79+
rInt := acctest.RandInt()
7580
resource.Test(t, resource.TestCase{
7681
PreCheck: func() { testAccPreCheck(t) },
7782
Providers: testAccProviders,
7883
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
7984
Steps: []resource.TestStep{
8085
resource.TestStep{
81-
Config: testAccCodeCommitRepository_basic,
86+
Config: testAccCodeCommitRepository_basic(rInt),
8287
Check: resource.ComposeTestCheckFunc(
8388
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
8489
resource.TestCheckResourceAttr(
8590
"aws_codecommit_repository.test", "default_branch", ""),
8691
),
8792
},
8893
resource.TestStep{
89-
Config: testAccCodeCommitRepository_with_default_branch,
94+
Config: testAccCodeCommitRepository_with_default_branch(rInt),
9095
Check: resource.ComposeTestCheckFunc(
9196
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
9297
resource.TestCheckResourceAttr(
@@ -154,33 +159,39 @@ func testAccCheckCodeCommitRepositoryDestroy(s *terraform.State) error {
154159
return nil
155160
}
156161

157-
const testAccCodeCommitRepository_basic = `
162+
func testAccCodeCommitRepository_basic(rInt int) string {
163+
return fmt.Sprintf(`
158164
provider "aws" {
159165
region = "us-east-1"
160166
}
161167
resource "aws_codecommit_repository" "test" {
162-
repository_name = "my_test_repository"
168+
repository_name = "test_repository_%d"
163169
description = "This is a test description"
164170
}
165-
`
171+
`, rInt)
172+
}
166173

167-
const testAccCodeCommitRepository_withChanges = `
174+
func testAccCodeCommitRepository_withChanges(rInt int) string {
175+
return fmt.Sprintf(`
168176
provider "aws" {
169177
region = "us-east-1"
170178
}
171179
resource "aws_codecommit_repository" "test" {
172-
repository_name = "my_test_repository"
180+
repository_name = "test_repository_%d"
173181
description = "This is a test description - with changes"
174182
}
175-
`
183+
`, rInt)
184+
}
176185

177-
const testAccCodeCommitRepository_with_default_branch = `
186+
func testAccCodeCommitRepository_with_default_branch(rInt int) string {
187+
return fmt.Sprintf(`
178188
provider "aws" {
179189
region = "us-east-1"
180190
}
181191
resource "aws_codecommit_repository" "test" {
182-
repository_name = "my_test_repository"
192+
repository_name = "test_repository_%d"
183193
description = "This is a test description"
184194
default_branch = "master"
185195
}
186-
`
196+
`, rInt)
197+
}

0 commit comments

Comments
 (0)