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

5731 save key pair fingerprint attribute from response #5732

Merged
merged 4 commits into from
Aug 30, 2018

Conversation

mahsoud
Copy link
Contributor

@mahsoud mahsoud commented Aug 30, 2018

5731 save key pair fingerprint attribute from the response to create keypair request.

Fixes #5731

Changes proposed in this pull request:

Save fingerprint to state on the response, change is minimal.

5731 save key pair fingerprint attribute from the response to create keypair request.
@@ -85,7 +85,8 @@ func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return fmt.Errorf("Error import KeyPair: %s", err)
}


d.Set("fingerprint", *resp.KeyFingerprint)
d.SetId(*resp.KeyName)
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than calling d.Set() during the create function, we generally prefer to instead have the create function return the result of the read function (which should handle d.Set() for all the attributes): https://www.terraform.io/docs/extend/best-practices/detecting-drift.html#update-state-after-modification

Can you please remove the d.Set() in the create function and have it return resourceAwsKeyPairRead(d, meta) instead? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes for sure :) thank you for directions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bflad done as requested.

@bflad bflad added bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. labels Aug 30, 2018
@bflad bflad added this to the v1.34.0 milestone Aug 30, 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.

Hi @mahsoud 👋 Thanks for reporting this and submitting the fix! I have updated the acceptance testing to ensure this is covered:

Previously:

--- FAIL: TestAccAWSKeyPair_basic (7.40s)
    testing.go:527: Step 0 error: Check failed: Check 3/4 error: aws_key_pair.a_key_pair: Attribute 'fingerprint' not found
--- PASS: TestAccAWSKeyPair_generatedName (9.86s)
--- PASS: TestAccAWSKeyPair_namePrefix (10.50s)

Now:

--- PASS: TestAccAWSKeyPair_basic (11.71s)
--- PASS: TestAccAWSKeyPair_generatedName (11.92s)
--- PASS: TestAccAWSKeyPair_namePrefix (11.41s)

@bflad bflad merged commit 49f6704 into hashicorp:master Aug 30, 2018
bflad added a commit that referenced this pull request Aug 30, 2018
@bflad
Copy link
Contributor

bflad commented Aug 30, 2018

This has been released in version 1.34.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
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_key_pair doesnt set fingerprint attribute on initial run
2 participants