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_batch_job_queue: Prevent panic when ComputeEnvironmentOrder is updated outside Terraform #12632

Merged
merged 1 commit into from
Apr 29, 2020

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Apr 2, 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 #8083

Release note for CHANGELOG:

* resource/aws_batch_job_queue: Prevent panic when ComputeEnvironmentOrder is updated outside Terraform

Also modernizes the testing.

Previously:

=== CONT  TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate
panic: runtime error: index out of range [1] with length 1

goroutine 1306 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsBatchJobQueueRead(0xc001117c70, 0x62e4cc0, 0xc0003bcf00, 0xc001117c70, 0x0)
  /Users/bflad/src/github.com/terraform-providers/terraform-provider-aws-deux/aws/resource_aws_batch_job_queue.go:110 +0x55a
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0005df580, 0xc00104ae60, 0x62e4cc0, 0xc0003bcf00, 0xc000c7ec30, 0x0, 0x0)
  /Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.8.0/helper/schema/resource.go:455 +0x119

Output from acceptance testing:

--- PASS: TestAccAWSBatchJobQueue_basic (85.28s)
--- PASS: TestAccAWSBatchJobQueue_disappears (87.06s)
--- PASS: TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate (98.67s)
--- PASS: TestAccAWSBatchJobQueue_Priority (120.72s)
--- PASS: TestAccAWSBatchJobQueue_State (127.15s)

…der is updated outside Terraform

Reference: #8083

Also modernizes the testing.

Previously:

```
=== CONT  TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate
panic: runtime error: index out of range [1] with length 1

goroutine 1306 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsBatchJobQueueRead(0xc001117c70, 0x62e4cc0, 0xc0003bcf00, 0xc001117c70, 0x0)
  /Users/bflad/src/github.com/terraform-providers/terraform-provider-aws-deux/aws/resource_aws_batch_job_queue.go:110 +0x55a
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0005df580, 0xc00104ae60, 0x62e4cc0, 0xc0003bcf00, 0xc000c7ec30, 0x0, 0x0)
  /Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.8.0/helper/schema/resource.go:455 +0x119
```

Output from acceptance testing:

```
--- PASS: TestAccAWSBatchJobQueue_basic (85.28s)
--- PASS: TestAccAWSBatchJobQueue_disappears (87.06s)
--- PASS: TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate (98.67s)
--- PASS: TestAccAWSBatchJobQueue_Priority (120.72s)
--- PASS: TestAccAWSBatchJobQueue_State (127.15s)
```
@bflad bflad added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. labels Apr 2, 2020
@bflad bflad requested a review from a team April 2, 2020 14:52
@ghost ghost added needs-triage Waiting for first response or review from a maintainer. service/batch Issues and PRs that pertain to the batch service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XL Managed by automation to categorize the size of a PR. labels Apr 2, 2020
@bflad bflad removed the needs-triage Waiting for first response or review from a maintainer. label Apr 2, 2020
Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

--- PASS: TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate (79.65s)
--- PASS: TestAccAWSBatchJobQueue_disappears (79.84s)
--- PASS: TestAccAWSBatchJobQueue_basic (82.40s)
--- PASS: TestAccAWSBatchJobQueue_Priority (96.07s)
--- PASS: TestAccAWSBatchJobQueue_State (96.14s)

resourceName := "aws_batch_job_queue.test_queue"
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/8083
func TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate(t *testing.T) {
var jobQueue1 batch.JobQueueDetail
Copy link
Contributor

Choose a reason for hiding this comment

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

Since there's only one job queue involved in this test, does it need the 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I find appending the number from the start helps reduce code churn should the test be extended to need multiple later on, but we'll want to setup something to enforce the naming of these if its a concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could also do something like always require it to be a slice, e.g. var jobQueues []*batch.JobQueueDetail, then adjust ...Exists functions to append and ones reading the information like ...Recreated functions to require a two index parameters, e.g. ...Recreated(jobQueues, 0, 1)

Copy link
Contributor Author

@bflad bflad Apr 29, 2020

Choose a reason for hiding this comment

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

Even better, honestly, would be not handling the API object at all in most cases. Its typically added now to avoid the churn in case its needed later on, but we could switch up the testing a little to enable generic versions of the various functions like ...Recreated/...NotRecreated that use state attributes across TestStep or more generically understands the apply difference (update vs destroy/create). It'd be best if the SDK provided that functionality though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for all the comments here. 😄 Here's a reference implementation to my previous comment: hashicorp/terraform-plugin-sdk#329

@bflad bflad added this to the v2.60.0 milestone Apr 29, 2020
@bflad bflad merged commit 6facb73 into master Apr 29, 2020
@bflad bflad deleted the b-aws_batch_job_queue-ceo-panic branch April 29, 2020 10:41
bflad added a commit that referenced this pull request Apr 29, 2020
@ghost
Copy link

ghost commented May 1, 2020

This has been released in version 2.60.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!

adamdecaf pushed a commit to adamdecaf/terraform-provider-aws that referenced this pull request May 28, 2020
…der is updated outside Terraform (hashicorp#12632)

Reference: hashicorp#8083

Also modernizes the testing.

Previously:

```
=== CONT  TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate
panic: runtime error: index out of range [1] with length 1

goroutine 1306 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsBatchJobQueueRead(0xc001117c70, 0x62e4cc0, 0xc0003bcf00, 0xc001117c70, 0x0)
  /Users/bflad/src/github.com/terraform-providers/terraform-provider-aws-deux/aws/resource_aws_batch_job_queue.go:110 +0x55a
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0005df580, 0xc00104ae60, 0x62e4cc0, 0xc0003bcf00, 0xc000c7ec30, 0x0, 0x0)
  /Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.8.0/helper/schema/resource.go:455 +0x119
```

Output from acceptance testing:

```
--- PASS: TestAccAWSBatchJobQueue_basic (85.28s)
--- PASS: TestAccAWSBatchJobQueue_disappears (87.06s)
--- PASS: TestAccAWSBatchJobQueue_ComputeEnvironments_ExternalOrderUpdate (98.67s)
--- PASS: TestAccAWSBatchJobQueue_Priority (120.72s)
--- PASS: TestAccAWSBatchJobQueue_State (127.15s)
```
@ghost
Copy link

ghost commented May 29, 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 and limited conversation to collaborators May 29, 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. crash Results from or addresses a Terraform crash or kernel panic. service/batch Issues and PRs that pertain to the batch service. size/XL Managed by automation to categorize the size of a PR. 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.

Crash at Aws Batch - Compute Environment Order.
2 participants