-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
New Resource: CloudFront Public Key #5737
Conversation
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 submitting this @saravanan30erd 😄 A few minor things then we should be able to get this in. Please let us know if you have any questions or do not have time to implement the feedback.
return err | ||
} | ||
|
||
var publicKeyConfig *cloudfront.PublicKeyConfig |
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.
Declaring this variable seems extraneous and should also be protected by nil
checks to prevent panics, e.g.
if output == nil || output.PublicKey == nil || output.PublicKey.PublicKeyConfig == nil {
log.Printf("[WARN] No PublicKey found: %s, removing from state", d.Id())
d.SetId("")
return nil
}
publicKeyConfig := output.PublicKey.PublicKeyConfig
d.Set("encoded_key", publicKeyConfig.EncodedKey) | ||
d.Set("name", publicKeyConfig.Name) | ||
|
||
if publicKeyConfig.Comment != 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.
We should prefer to always call d.Set()
as it can handle *string
set to nil
just fine and helps catch the case where the comment is removed outside of Terraform.
d.Set("comment", publicKeyConfig.Comment) | ||
} | ||
|
||
if publicKeyConfig.CallerReference != 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.
Same here -- we should prefer to always call d.Set()
as it can handle *string
set to nil
just fine.
_, err := conn.DeletePublicKey(request) | ||
if err != nil { | ||
if isAWSErr(err, cloudfront.ErrCodeNoSuchPublicKey, "") { | ||
log.Printf("[WARN] No PublicKey found: %s, removing from state", d.Id()) |
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.
This log line and the d.SetId("")
are extraneous in the delete function. 👍
} | ||
|
||
_, err := conn.GetPublicKey(params) | ||
if 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.
We should prefer to catch the specific error we want and ensure we return other errors, e.g.
_, err := conn.GetPublicKey(params)
if isAWSErr(err, cloudfront.ErrCodeNoSuchPublicKey, "") {
continue
}
if err != nil {
return err
}
return fmt.Errorf("CloudFront PublicKey (%s) was not deleted", rs.Primary.ID)
@bflad thanks for the feedback. its done 👍 |
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, @saravanan30erd! 🚀
3 tests passed (all tests)
--- PASS: TestAccAWSCloudFrontPublicKey_basic (6.00s)
--- PASS: TestAccAWSCloudFrontPublicKey_namePrefix (6.12s)
--- PASS: TestAccAWSCloudFrontPublicKey_update (10.39s)
This has been released in version 1.36.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
Fixes #4096
Output from acceptance testing: