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

r/aws_workspaces_directory: Fix panic if previously registered directory is no longer registered #11837

Merged
merged 1 commit into from
Feb 23, 2020

Conversation

ewbankkit
Copy link
Contributor

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 #11814.

Release note for CHANGELOG:

resource/aws_workspaces_directory: Fix panic if previously registered directory is no longer registered

Output from acceptance testing:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAwsWorkspacesDirectory'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAwsWorkspacesDirectory -timeout 120m
=== RUN   TestAccAwsWorkspacesDirectory
=== RUN   TestAccAwsWorkspacesDirectory/basic
=== RUN   TestAccAwsWorkspacesDirectory/disappears
=== RUN   TestAccAwsWorkspacesDirectory/subnetIds
--- PASS: TestAccAwsWorkspacesDirectory (2056.41s)
    --- PASS: TestAccAwsWorkspacesDirectory/basic (662.88s)
    --- PASS: TestAccAwsWorkspacesDirectory/disappears (784.63s)
    --- PASS: TestAccAwsWorkspacesDirectory/subnetIds (608.90s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	2056.456s

@ewbankkit ewbankkit requested a review from a team January 31, 2020 16:33
@ghost ghost added size/M Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. service/workspaces Issues and PRs that pertain to the workspaces service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Jan 31, 2020
@ewbankkit
Copy link
Contributor Author

Copy link
Contributor

@Tensho Tensho left a comment

Choose a reason for hiding this comment

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

Great stuff 👍 TBH, I even didn't think about the case, when a TF managed resource could be deleted manually and that should be handled with the resource drop from the state on Read. I will add a similar check to other workspace resources I've contributed to. Thank you 🙇

d.Set("directory_id", dir.DirectoryId)
d.Set("subnet_ids", dir.SubnetIds)
d.Set("self_service_permissions", flattenSelfServicePermissions(dir.SelfservicePermissions))
if err := d.Set("self_service_permissions", flattenSelfServicePermissions(dir.SelfservicePermissions)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, could you explain what are the circumstances when Set() may return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the type of the data passed to Set() isn't compatible with the schema type declared for the attribute it's possible to get an error (e.g. passing a map[string]interface{} when a *schema.Set is expected.
To be safe, anytime a "complex" type is being set we should really check errors (although there are many places in the code that isn't done).
Silent failure can lead to attributes not being set correctly in state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thank you 🙇

@@ -205,7 +210,7 @@ func resourceAwsWorkspacesDirectoryDelete(d *schema.ResourceData, meta interface

err := workspacesDirectoryDelete(d.Id(), conn)
if err != nil {
return err
return fmt.Errorf("error deleting workspaces directory (%s): %s", d.Id(), err)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -201,6 +232,8 @@ func testAccCheckAwsWorkspacesDirectoryExists(n string) resource.TestCheckFunc {
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's worth to check the length here too, isn't it?

func testAccCheckAwsWorkspacesDirectoryExists(n string) resource.TestCheckFunc {
func testAccCheckAwsWorkspacesDirectoryDisappears(v *workspaces.WorkspaceDirectory) resource.TestCheckFunc {
return func(s *terraform.State) error {
return workspacesDirectoryDelete(aws.StringValue(v.DirectoryId), testAccProvider.Meta().(*AWSClient).workspacesconn)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear from the test helper name that it just deletes the resource under the test and doesn't check anything actually. But the framework expects TestCheckFunc type, so nothing better to do here 🤷‍♂

@@ -66,6 +67,7 @@ func TestAccAwsWorkspacesDirectory(t *testing.T) {
}

func testAccAwsWorkspacesDirectory_basic(t *testing.T) {
var v workspaces.WorkspaceDirectory
Copy link
Contributor

Choose a reason for hiding this comment

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

Good point 👍 I guess this should be added in a separate PR with the actual usage of v in checks. I know it's a good pattern to test TF state along with the actual resource one, however, it doesn't make sense without those tests.

@bflad bflad added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 11, 2020
@bflad bflad self-assigned this Feb 11, 2020
@bflad bflad added this to the v2.51.0 milestone Feb 23, 2020
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Thanks for this fix, looks good to me, @ewbankkit 🚀

Output from acceptance testing:

--- PASS: TestAccAwsWorkspacesDirectory (1658.93s)
    --- PASS: TestAccAwsWorkspacesDirectory/basic (524.67s)
    --- PASS: TestAccAwsWorkspacesDirectory/disappears (572.09s)
    --- PASS: TestAccAwsWorkspacesDirectory/subnetIds (562.17s)

@bflad bflad merged commit 8271366 into hashicorp:master Feb 23, 2020
bflad added a commit that referenced this pull request Feb 23, 2020
@ewbankkit ewbankkit deleted the issue-11814 branch February 23, 2020 22:57
@ghost
Copy link

ghost commented Feb 28, 2020

This has been released in version 2.51.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 Mar 27, 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 Mar 27, 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/workspaces Issues and PRs that pertain to the workspaces service. size/M 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.

Panic if previously registered directory is no longer registered.
3 participants