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

resource/aws_iam_access_key: Add create_date attribute #17318

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/17318.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_iam_access_key: Add `create_date` attribute
```
21 changes: 15 additions & 6 deletions aws/resource_aws_iam_access_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"encoding/base64"
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
Expand Down Expand Up @@ -51,14 +52,18 @@ func resourceAwsIamAccessKey() *schema.Resource {
ForceNew: true,
Optional: true,
},
"key_fingerprint": {
"create_date": {
Type: schema.TypeString,
Computed: true,
},
"encrypted_secret": {
Type: schema.TypeString,
Computed: true,
},
"key_fingerprint": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -148,12 +153,16 @@ func resourceAwsIamAccessKeyRead(d *schema.ResourceData, meta interface{}) error

func resourceAwsIamAccessKeyReadResult(d *schema.ResourceData, key *iam.AccessKeyMetadata) error {
d.SetId(aws.StringValue(key.AccessKeyId))
if err := d.Set("user", key.UserName); err != nil {
return err
}
if err := d.Set("status", key.Status); err != nil {
return err

if key.CreateDate != nil {
d.Set("create_date", aws.TimeValue(key.CreateDate).Format(time.RFC3339))
} else {
d.Set("create_date", nil)
}

d.Set("status", key.Status)
d.Set("user", key.UserName)

return nil
}

Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_iam_access_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccAWSAccessKey_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAccessKeyExists("aws_iam_access_key.a_key", &conf),
testAccCheckAWSAccessKeyAttributes(&conf, "Active"),
testAccCheckResourceAttrRfc3339("aws_iam_access_key.a_key", "create_date"),
resource.TestCheckResourceAttrSet("aws_iam_access_key.a_key", "secret"),
),
},
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/iam_access_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Valid values are `Active` and `Inactive`.

In addition to all arguments above, the following attributes are exported:

* `create_date` - Date and time in [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8) that the access key was created.
* `id` - The access key ID.
* `user` - The IAM user associated with this access key.
* `key_fingerprint` - The fingerprint of the PGP key used to encrypt
Expand Down