Skip to content

Commit

Permalink
tests/resource/aws_elastic_beanstalk_environment: Refactoring and mod…
Browse files Browse the repository at this point in the history
…ernization (#11702)

Previously in the acceptance testing (across entire resource):

```
--- FAIL: TestAccAWSBeanstalkEnv_basic (20.78s)
    testing.go:640: Step 0 error: errors during apply:

        Error: Error waiting for Elastic Beanstalk Environment (e-mua2t3mjij) to become ready: 2 errors occurred:
        	* 2020-01-21 07:33:24.327 +0000 UTC (e-mua2t3mjij) : Service:AmazonCloudFormation, Message:Parameter InstanceType failed to satisfy constraint: must be a valid EC2 instance type.
        	* 2020-01-21 07:33:24.426 +0000 UTC (e-mua2t3mjij) : Failed to launch environment.

--- FAIL: TestAccAWSBeanstalkEnv_settingWithJsonValue (0.73s)
    testing.go:640: Step 0 error: /opt/teamcity-agent/temp/buildTmp/tf-test536039886/main.tf:74,3-10: Attribute redefined; The argument "setting" was already set at /opt/teamcity-agent/temp/buildTmp/tf-test536039886/main.tf:68,3-10. Each argument may be set only once., and 19 other diagnostic(s)
```

The test configurations were previously written to expect either a Elastic Beanstalk compatible Default VPC (IGW, map public IPs on launch Subnets, and permissive ingress/egress NACL) or EC2-Classic. We have moved away from these expectations and the majority of this refactor is centered on supplying self-contained VPC configurations to each test.

Other changes include:

- Blocking usw2-az4 as the default instance type for EB is t2.micro and that instance type is not available in that Availability Zone, always (when that subnet is selected) triggering a launch error
- Migrating to import testing in most tests
- Migrating to resources named "test" in configurations and single resourceName variable in functions
- Migrating to single rName variable for randomization
- Using helper TestCheckFunc for ARNs
- Removing duplicate test functions and configurations

Especially given the new import testing, there are potential further fixes that could be done to this resource including properly setting the `setting` and `template_name` attributes into the Terraform state during refresh, however those changes to the resource logic are out of scope for these test fixes.

Output from acceptance testing:

```
--- PASS: TestAccAWSBeanstalkEnv_platformArn (410.22s)
--- PASS: TestAccAWSBeanstalkEnv_resource (439.66s)
--- PASS: TestAccAWSBeanstalkEnv_basic (489.82s)
--- PASS: TestAccAWSBeanstalkEnv_settingWithJsonValue (558.85s)
--- PASS: TestAccAWSBeanstalkEnv_cname_prefix (577.42s)
--- PASS: TestAccAWSBeanstalkEnv_version_label (618.65s)
--- PASS: TestAccAWSBeanstalkEnv_config (628.04s)
--- PASS: TestAccAWSBeanstalkEnv_tier (630.63s)
--- PASS: TestAccAWSBeanstalkEnv_tags (667.96s)
--- PASS: TestAccAWSBeanstalkEnv_settings_update (744.56s)
--- PASS: TestAccAWSBeanstalkEnv_template_change (768.69s)
```
  • Loading branch information
bflad authored Feb 3, 2020
1 parent ebcad10 commit e8a3576
Show file tree
Hide file tree
Showing 2 changed files with 681 additions and 509 deletions.
13 changes: 13 additions & 0 deletions aws/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ func testAccCheckResourceAttrRegionalARN(resourceName, attributeName, arnService
}
}

// testAccCheckResourceAttrRegionalARNNoAccount ensures the Terraform state exactly matches a formatted ARN with region but without account ID
func testAccCheckResourceAttrRegionalARNNoAccount(resourceName, attributeName, arnService, arnResource string) resource.TestCheckFunc {
return func(s *terraform.State) error {
attributeValue := arn.ARN{
Partition: testAccGetPartition(),
Region: testAccGetRegion(),
Resource: arnResource,
Service: arnService,
}.String()
return resource.TestCheckResourceAttr(resourceName, attributeName, attributeValue)(s)
}
}

// testAccMatchResourceAttrRegionalARN ensures the Terraform state regexp matches a formatted ARN with region
func testAccMatchResourceAttrRegionalARN(resourceName, attributeName, arnService string, arnResourceRegexp *regexp.Regexp) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down
Loading

0 comments on commit e8a3576

Please sign in to comment.