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

New Resource: CloudFront Public Key #5737

Merged
merged 14 commits into from
Sep 12, 2018

Conversation

saravanan30erd
Copy link
Contributor

Fixes #4096

Output from acceptance testing:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSCloudFrontPublicKey_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSCloudFrontPublicKey_ -timeout 120m
=== RUN   TestAccAWSCloudFrontPublicKey_basic
--- PASS: TestAccAWSCloudFrontPublicKey_basic (27.79s)
=== RUN   TestAccAWSCloudFrontPublicKey_namePrefix
--- PASS: TestAccAWSCloudFrontPublicKey_namePrefix (26.84s)
=== RUN   TestAccAWSCloudFrontPublicKey_update
--- PASS: TestAccAWSCloudFrontPublicKey_update (46.40s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	101.079s
...

@bflad bflad added new-resource Introduces a new resource. service/cloudfront Issues and PRs that pertain to the cloudfront service. labels Aug 31, 2018
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 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
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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())
Copy link
Contributor

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 {
Copy link
Contributor

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 bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Sep 12, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Sep 12, 2018
@saravanan30erd
Copy link
Contributor Author

@bflad thanks for the feedback. its done 👍

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 12, 2018
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, @saravanan30erd! 🚀

3 tests passed (all tests)
--- PASS: TestAccAWSCloudFrontPublicKey_basic (6.00s)
--- PASS: TestAccAWSCloudFrontPublicKey_namePrefix (6.12s)
--- PASS: TestAccAWSCloudFrontPublicKey_update (10.39s)

@bflad bflad merged commit ad83a91 into hashicorp:master Sep 12, 2018
@bflad bflad added this to the v1.36.0 milestone Sep 12, 2018
bflad added a commit that referenced this pull request Sep 12, 2018
@saravanan30erd saravanan30erd deleted the cloudfront-pubkey branch September 12, 2018 19:39
@bflad
Copy link
Contributor

bflad commented Sep 13, 2018

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.

@ghost
Copy link

ghost commented Apr 3, 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 Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/cloudfront Issues and PRs that pertain to the cloudfront service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Support CloudFront Public Keys
2 participants