Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_elastic_beanstalk_environment: Handle Terminated status on deletion, use IAM Instance Profile and custom service role in testing #15158

Merged
merged 1 commit into from
Sep 22, 2020

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Sep 15, 2020

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #15155

Release note for CHANGELOG:

* resource/aws_elastic_beanstalk_environment: Skip `Terminated` status errors on deletion

Previously:

=== CONT  TestAccAWSBeanstalkEnv_basic
TestAccAWSBeanstalkEnv_basic: resource_aws_elastic_beanstalk_environment_test.go:81: Step 1/2 error: terraform failed: exit status 1
stderr:
Error: Error waiting for Elastic Beanstalk Environment (e-scpzxse7ei) to become ready: 2 errors occurred:
  * 2020-09-15 07:48:42.231 +0000 UTC (e-scpzxse7ei) : Environment must have instance profile associated with it.
  * 2020-09-15 07:48:42.343 +0000 UTC (e-scpzxse7ei) : Failed to launch environment.
TestAccAWSBeanstalkEnv_basic: testing_new.go:22: WARNING: destroy failed, so remote objects may still exist and be subject to billing
TestAccAWSBeanstalkEnv_basic: testing_new.go:22: failed to destroy: terraform failed: exit status 1
stderr:
Error: error waiting for Elastic Beanstalk Environment "e-scpzxse7ei" to be ready before terminating: unexpected state 'Terminated', wanted target 'Ready'. last error: %!s(<nil>)
--- FAIL: TestAccAWSBeanstalkEnv_basic (31.41s)

After fixing the IAM Instance Profile error, received these two types of failures still:

=== CONT  TestAccAWSBeanstalkEnv_tier
    resource_aws_elastic_beanstalk_environment_test.go:118: Step 1/2 error: terraform failed: exit status 1

        stderr:

        Error: Error waiting for Elastic Beanstalk Environment (e-3tebzj5j3h) to become ready: 1 error occurred:
          * 2020-09-15 17:10:28.142 +0000 UTC (e-3tebzj5j3h) : Failed to launch environment.

    testing_new.go:22: WARNING: destroy failed, so remote objects may still exist and be subject to billing
    testing_new.go:22: failed to destroy: terraform failed: exit status 1

        stderr:

        Error: error waiting for Elastic Beanstalk Environment "e-3tebzj5j3h" to be ready before terminating: unexpected state 'Terminated', wanted target 'Ready'. last error: %!s(<nil>)

To handle the destroy error, added the Terminating and Terminated handling to the resource deletion polling. Looking in the console, the opaque Failed to launch environment. error details were found in this other INFO level event:

Operation failed because the environment needs a service role. You made the call without one, and you're missing the permission to create a service-linked role for this account. Repeat the call and provide a service role. Alternatively, ask your account administrator to create the account's service-linked role, and then repeat the call.

These test configurations were dependent on the Elastic Beanstalk IAM Service-Linked Role since they did not declare a custom IAM Role for the service role. While the credentials in use did have permissions, there was a delay before the EB created SLR was ready, introducing a few test failures until the rest would succeed once the SLR was propagated. This SLR is also challenging because the TestAccAWSIAMServiceLinkedRole_basic testing explicitly deletes it. Rather than keep reliance on this flaky shared resource, instead opted to customize the service role.

Output from acceptance testing:

--- PASS: TestAccAWSBeanstalkEnv_basic (462.19s)
--- PASS: TestAccAWSBeanstalkEnv_cname_prefix (632.10s)
--- PASS: TestAccAWSBeanstalkEnv_config (519.50s)
--- PASS: TestAccAWSBeanstalkEnv_platformArn (465.62s)
--- PASS: TestAccAWSBeanstalkEnv_resource (502.50s)
--- PASS: TestAccAWSBeanstalkEnv_settingWithJsonValue (381.12s)
--- PASS: TestAccAWSBeanstalkEnv_settings_update (716.57s)
--- PASS: TestAccAWSBeanstalkEnv_tags (694.50s)
--- PASS: TestAccAWSBeanstalkEnv_template_change (612.67s)
--- PASS: TestAccAWSBeanstalkEnv_tier (726.73s)
--- PASS: TestAccAWSBeanstalkEnv_version_label (534.55s)

@bflad bflad added bug Addresses a defect in current functionality. technical-debt Addresses areas of the codebase that need refactoring or redesign. labels Sep 15, 2020
@bflad bflad requested a review from a team September 15, 2020 18:51
@ghost ghost added size/L Managed by automation to categorize the size of a PR. service/elasticbeanstalk Issues and PRs that pertain to the elasticbeanstalk service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Sep 15, 2020
…on deletion, use IAM Instance Profile and custom service role in testing

Reference: #15155

Previously:

```
=== CONT  TestAccAWSBeanstalkEnv_basic
TestAccAWSBeanstalkEnv_basic: resource_aws_elastic_beanstalk_environment_test.go:81: Step 1/2 error: terraform failed: exit status 1
stderr:
Error: Error waiting for Elastic Beanstalk Environment (e-scpzxse7ei) to become ready: 2 errors occurred:
  * 2020-09-15 07:48:42.231 +0000 UTC (e-scpzxse7ei) : Environment must have instance profile associated with it.
  * 2020-09-15 07:48:42.343 +0000 UTC (e-scpzxse7ei) : Failed to launch environment.
TestAccAWSBeanstalkEnv_basic: testing_new.go:22: WARNING: destroy failed, so remote objects may still exist and be subject to billing
TestAccAWSBeanstalkEnv_basic: testing_new.go:22: failed to destroy: terraform failed: exit status 1
stderr:
Error: error waiting for Elastic Beanstalk Environment "e-scpzxse7ei" to be ready before terminating: unexpected state 'Terminated', wanted target 'Ready'. last error: %!s(<nil>)
--- FAIL: TestAccAWSBeanstalkEnv_basic (31.41s)
```

After fixing the IAM Instance Profile error, received these two types of failures still:

```
=== CONT  TestAccAWSBeanstalkEnv_tier
    resource_aws_elastic_beanstalk_environment_test.go:118: Step 1/2 error: terraform failed: exit status 1

        stderr:

        Error: Error waiting for Elastic Beanstalk Environment (e-3tebzj5j3h) to become ready: 1 error occurred:
          * 2020-09-15 17:10:28.142 +0000 UTC (e-3tebzj5j3h) : Failed to launch environment.

    testing_new.go:22: WARNING: destroy failed, so remote objects may still exist and be subject to billing
    testing_new.go:22: failed to destroy: terraform failed: exit status 1

        stderr:

        Error: error waiting for Elastic Beanstalk Environment "e-3tebzj5j3h" to be ready before terminating: unexpected state 'Terminated', wanted target 'Ready'. last error: %!s(<nil>)
```

To handle the destroy error, added the `Terminating` and `Terminated` handling to the resource deletion polling. Looking in the console, the opaque `Failed to launch environment.` error details were found in this other `INFO` level event:

```
Operation failed because the environment needs a service role. You made the call without one, and you're missing the permission to create a service-linked role for this account. Repeat the call and provide a service role. Alternatively, ask your account administrator to create the account's service-linked role, and then repeat the call.
```

These test configurations were dependent on the Elastic Beanstalk IAM Service-Linked Role since they did not declare a custom IAM Role for the service role. While the credentials in use did have permissions, there was a delay before the EB created SLR was ready, introducing a few test failures until the rest would succeed once the SLR was propagated. This SLR is also challenging because the `TestAccAWSIAMServiceLinkedRole_basic` testing explicitly deletes it. Rather than keep reliance on this flaky shared resource, instead opted to customize the service role.

Output from acceptance testing:

```
--- PASS: TestAccAWSBeanstalkEnv_basic (462.19s)
--- PASS: TestAccAWSBeanstalkEnv_cname_prefix (632.10s)
--- PASS: TestAccAWSBeanstalkEnv_config (519.50s)
--- PASS: TestAccAWSBeanstalkEnv_platformArn (465.62s)
--- PASS: TestAccAWSBeanstalkEnv_resource (502.50s)
--- PASS: TestAccAWSBeanstalkEnv_settingWithJsonValue (381.12s)
--- PASS: TestAccAWSBeanstalkEnv_settings_update (716.57s)
--- PASS: TestAccAWSBeanstalkEnv_tags (694.50s)
--- PASS: TestAccAWSBeanstalkEnv_template_change (612.67s)
--- PASS: TestAccAWSBeanstalkEnv_tier (726.73s)
--- PASS: TestAccAWSBeanstalkEnv_version_label (534.55s)
```
@bflad bflad force-pushed the t-aws_elastic_beanstalk_environment-instance-profile branch from 038e650 to 7694c1b Compare September 15, 2020 19:00
Copy link
Contributor

@anGie44 anGie44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🙌 , LGTM.

Output of acceptance tests:

--- PASS: TestAccAWSBeanstalkEnv_resource (357.80s)
--- PASS: TestAccAWSBeanstalkEnv_settingWithJsonValue (395.57s)
--- PASS: TestAccAWSBeanstalkEnv_config (488.91s)
--- PASS: TestAccAWSBeanstalkEnv_basic (496.17s)
--- PASS: TestAccAWSBeanstalkEnv_cname_prefix (543.40s)
--- PASS: TestAccAWSBeanstalkEnv_platformArn (597.47s)
--- PASS: TestAccAWSBeanstalkEnv_template_change (598.45s)
--- PASS: TestAccAWSBeanstalkEnv_tier (627.33s)
--- PASS: TestAccAWSBeanstalkEnv_settings_update (677.82s)
--- PASS: TestAccAWSBeanstalkEnv_tags (749.96s)
--- PASS: TestAccAWSBeanstalkEnv_version_label (802.65s)

@bflad bflad added this to the v3.8.0 milestone Sep 22, 2020
@bflad bflad merged commit 7a85ec3 into master Sep 22, 2020
@bflad bflad deleted the t-aws_elastic_beanstalk_environment-instance-profile branch September 22, 2020 16:28
@ghost
Copy link

ghost commented Sep 24, 2020

This has been released in version 3.8.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Oct 22, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/elasticbeanstalk Issues and PRs that pertain to the elasticbeanstalk service. size/L Managed by automation to categorize the size of a PR. technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests/resource/aws_elastic_beanstalk_environment: Missing Instance Profile
2 participants