-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Conversation
…ory is no longer registered.
Verified that |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { | |||
} | |||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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)
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! |
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! |
Community Note
Closes #11814.
Release note for CHANGELOG:
Output from acceptance testing: