-
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
Fix aws_iam_user_ssh_key update method, set key status after creation #3390
Merged
bflad
merged 4 commits into
hashicorp:master
from
NikkeiFTLearning:aws_iam_user_ssh_key-fix-update
Feb 15, 2018
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,9 +69,10 @@ func resourceAwsIamUserSshKeyCreate(d *schema.ResourceData, meta interface{}) er | |
} | ||
|
||
d.Set("ssh_public_key_id", createResp.SSHPublicKey.SSHPublicKeyId) | ||
d.Set("fingerprint", createResp.SSHPublicKey.Fingerprint) | ||
d.SetId(*createResp.SSHPublicKey.SSHPublicKeyId) | ||
|
||
return resourceAwsIamUserSshKeyRead(d, meta) | ||
return resourceAwsIamUserSshKeyUpdate(d, meta) | ||
} | ||
|
||
func resourceAwsIamUserSshKeyRead(d *schema.ResourceData, meta interface{}) error { | ||
|
@@ -119,7 +120,7 @@ func resourceAwsIamUserSshKeyUpdate(d *schema.ResourceData, meta interface{}) er | |
} | ||
return fmt.Errorf("Error updating IAM User SSH Key %s: %s", d.Id(), err) | ||
} | ||
return resourceAwsIamUserRead(d, meta) | ||
return resourceAwsIamUserSshKeyRead(d, meta) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😬 yikes, good catch. Instead of having this only called during |
||
} | ||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package aws | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
|
@@ -112,6 +113,17 @@ func testAccCheckAWSUserSSHKeyExists(n string, res *iam.GetSSHPublicKeyOutput) r | |
|
||
*res = *resp | ||
|
||
keyStruct := resp.SSHPublicKey | ||
keyFields := strings.Fields(rs.Primary.Attributes["public_key"]) | ||
sshkey := fmt.Sprintf("%s %s", keyFields[0], keyFields[1]) | ||
|
||
if *keyStruct.Status != "Inactive" { | ||
return fmt.Errorf("Key status has wrong status should be Inactive is %s", *keyStruct.Status) | ||
} | ||
|
||
if *keyStruct.SSHPublicKeyBody != sshkey { | ||
return fmt.Errorf("Public key mismatch. \nIAM: %s\nResource: %s\n", *keyStruct.SSHPublicKeyBody, sshkey) | ||
} | ||
return nil | ||
} | ||
} | ||
|
@@ -126,6 +138,7 @@ resource "aws_iam_user_ssh_key" "user" { | |
username = "${aws_iam_user.user.name}" | ||
encoding = "SSH" | ||
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]" | ||
status = "Inactive" | ||
} | ||
` | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 really only be calling
d.Set()
duringRead
functions. Can you remove this here and move thessh_public_key_id
one above toresourceAwsIamUserSshKeyRead
? Thanks!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.
@bflad so, ssh_public_key_id set should be also removed?