-
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
Allow for creating a IoT Core certificate without CSR. #9283
Allow for creating a IoT Core certificate without CSR. #9283
Conversation
Does one of you have time to take a look at this PR? Thanks in advance |
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.
Hi @borisroman 👋 Thanks for this contribution. Looking pretty good, just left some items before we can get this merged. Please reach out with any questions or if you do not have time to implement them. 👍
aws/resource_aws_iot_certificate.go
Outdated
CertificateSigningRequest: aws.String(d.Get("csr").(string)), | ||
SetAsActive: aws.Bool(d.Get("active").(bool)), | ||
}) | ||
if d.Get("csr") != "" { |
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.
Since d.Get()
returns an interface, we should either check it after type assertion or switch the check to d.GetOk()
which will automatically check the value against the zero value for the type:
if d.Get("csr") != "" { | |
if _, ok := d.GetOk("csr"); ok { |
aws/resource_aws_iot_certificate.go
Outdated
log.Printf("[DEBUG] Created certificate from csr") | ||
if err != nil { | ||
log.Printf("[ERROR] %s", err) | ||
return 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.
Terraform will automatically log returned errors so the line above this is extraneous. We should also return some error context here for operators and code maintainers about when this error occurred, e.g.
return err | |
return fmt.Errorf("error creating IoT Certificate from CSR: %s", err) |
aws/resource_aws_iot_certificate.go
Outdated
|
||
if err != nil { | ||
log.Printf("[ERROR] %s", err) | ||
return 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.
Same here regarding the log message and error context 👍
return err | |
return fmt.Errorf("error creating IoT Keys and Certificate: %s", err) |
@bflad all feedback is addressed by the latest commit. |
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.
Looks great, thanks @borisroman 🚀
--- PASS: TestAccAWSIoTCertificate_csr (6.71s)
--- PASS: TestAccAWSIoTCertificate_keys_certificate (6.76s)
This has been released in version 2.23.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
Allow for creating a IoT Core certificate without CSR. Makes the CSR field optional and adds the CreateKeysAndCertificate API call.