Skip to content

Commit 08b8602

Browse files
jen20stack72
authored andcommitted
provider/aws: Generate random names for Beanstalk tests resources (hashicorp#10367)
* provider/aws: Generate name for TestAccElasticBeanstalkApplicationImport This allows tests to run concurrently. * provider/aws: Generate names for TestAWSElasticBeanstalkEnvironment_importBasic This allows tests to run concurrently.
1 parent b77dac5 commit 08b8602

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
package aws
22

33
import (
4+
"fmt"
45
"testing"
56

7+
"github.com/hashicorp/terraform/helper/acctest"
68
"github.com/hashicorp/terraform/helper/resource"
79
)
810

911
func TestAWSElasticBeanstalkApplication_importBasic(t *testing.T) {
1012
resourceName := "aws_elastic_beanstalk_application.tftest"
13+
config := fmt.Sprintf("tf-test-name-%d", acctest.RandInt())
1114

1215
resource.Test(t, resource.TestCase{
1316
PreCheck: func() { testAccPreCheck(t) },
1417
Providers: testAccProviders,
1518
CheckDestroy: testAccCheckBeanstalkAppDestroy,
1619
Steps: []resource.TestStep{
17-
resource.TestStep{
18-
Config: testAccBeanstalkAppConfig,
20+
{
21+
Config: testAccBeanstalkAppImportConfig(config),
1922
},
2023

21-
resource.TestStep{
24+
{
2225
ResourceName: resourceName,
2326
ImportState: true,
2427
ImportStateVerify: true,
2528
},
2629
},
2730
})
2831
}
32+
33+
func testAccBeanstalkAppImportConfig(name string) string {
34+
return fmt.Sprintf(`resource "aws_elastic_beanstalk_application" "tftest" {
35+
name = "%s"
36+
description = "tf-test-desc"
37+
}`, name)
38+
}
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
package aws
22

33
import (
4+
"fmt"
45
"testing"
56

7+
"github.com/hashicorp/terraform/helper/acctest"
68
"github.com/hashicorp/terraform/helper/resource"
79
)
810

911
func TestAWSElasticBeanstalkEnvironment_importBasic(t *testing.T) {
1012
resourceName := "aws_elastic_beanstalk_application.tftest"
1113

14+
applicationName := fmt.Sprintf("tf-test-name-%d", acctest.RandInt())
15+
environmentName := fmt.Sprintf("tf-test-env-name-%d", acctest.RandInt())
16+
1217
resource.Test(t, resource.TestCase{
1318
PreCheck: func() { testAccPreCheck(t) },
1419
Providers: testAccProviders,
1520
CheckDestroy: testAccCheckBeanstalkAppDestroy,
1621
Steps: []resource.TestStep{
17-
resource.TestStep{
18-
Config: testAccBeanstalkEnvConfig,
22+
{
23+
Config: testAccBeanstalkEnvImportConfig(applicationName, environmentName),
1924
},
2025

21-
resource.TestStep{
26+
{
2227
ResourceName: resourceName,
2328
ImportState: true,
2429
ImportStateVerify: true,
2530
},
2631
},
2732
})
2833
}
34+
35+
func testAccBeanstalkEnvImportConfig(appName, envName string) string {
36+
return fmt.Sprintf(`resource "aws_elastic_beanstalk_application" "tftest" {
37+
name = "%s"
38+
description = "tf-test-desc"
39+
}
40+
41+
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
42+
name = "%s"
43+
application = "${aws_elastic_beanstalk_application.tftest.name}"
44+
solution_stack_name = "64bit Amazon Linux running Python"
45+
}`, appName, envName)
46+
}

0 commit comments

Comments
 (0)