From d8e846c895c9d6cfd120ef906af1372616466901 Mon Sep 17 00:00:00 2001 From: Ninir Date: Mon, 14 Nov 2016 10:33:53 +0100 Subject: [PATCH] Fixed ##10079 exposing aws_iam_role create_date attribute (#10091) --- .../providers/aws/resource_aws_iam_role.go | 20 +++++++++++----- .../aws/resource_aws_iam_role_test.go | 23 +++++++++++-------- .../providers/aws/r/iam_role.html.markdown | 3 +++ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/builtin/providers/aws/resource_aws_iam_role.go b/builtin/providers/aws/resource_aws_iam_role.go index 0ae039aa8..9f8fc1de5 100644 --- a/builtin/providers/aws/resource_aws_iam_role.go +++ b/builtin/providers/aws/resource_aws_iam_role.go @@ -21,17 +21,17 @@ func resourceAwsIamRole() *schema.Resource { Delete: resourceAwsIamRoleDelete, Schema: map[string]*schema.Schema{ - "arn": &schema.Schema{ + "arn": { Type: schema.TypeString, Computed: true, }, - "unique_id": &schema.Schema{ + "unique_id": { Type: schema.TypeString, Computed: true, }, - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Optional: true, Computed: true, @@ -52,7 +52,7 @@ func resourceAwsIamRole() *schema.Resource { }, }, - "name_prefix": &schema.Schema{ + "name_prefix": { Type: schema.TypeString, Optional: true, ForceNew: true, @@ -71,17 +71,22 @@ func resourceAwsIamRole() *schema.Resource { }, }, - "path": &schema.Schema{ + "path": { Type: schema.TypeString, Optional: true, Default: "/", ForceNew: true, }, - "assume_role_policy": &schema.Schema{ + "assume_role_policy": { Type: schema.TypeString, Required: true, }, + + "create_date": { + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -174,6 +179,9 @@ func resourceAwsIamRoleReadResult(d *schema.ResourceData, role *iam.Role) error if err := d.Set("unique_id", role.RoleId); err != nil { return err } + if err := d.Set("create_date", role.CreateDate.Format(time.RFC3339)); err != nil { + return err + } return nil } diff --git a/builtin/providers/aws/resource_aws_iam_role_test.go b/builtin/providers/aws/resource_aws_iam_role_test.go index ee3945e37..aa3613b8c 100644 --- a/builtin/providers/aws/resource_aws_iam_role_test.go +++ b/builtin/providers/aws/resource_aws_iam_role_test.go @@ -20,11 +20,14 @@ func TestAccAWSRole_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckAWSRoleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccAWSRoleConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSRoleExists("aws_iam_role.role", &conf), testAccCheckAWSRoleAttributes(&conf), + resource.TestCheckResourceAttrSet( + "aws_iam_role.role", "create_date", + ), ), }, }, @@ -41,7 +44,7 @@ func TestAccAWSRole_namePrefix(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckAWSRoleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccAWSRolePrefixNameConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSRoleExists("aws_iam_role.role", &conf), @@ -61,14 +64,14 @@ func TestAccAWSRole_testNameChange(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckAWSRoleDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccAWSRolePre, Check: resource.ComposeTestCheckFunc( testAccCheckAWSRoleExists("aws_iam_role.role_update_test", &conf), ), }, - resource.TestStep{ + { Config: testAccAWSRolePost, Check: resource.ComposeTestCheckFunc( testAccCheckAWSRoleExists("aws_iam_role.role_update_test", &conf), @@ -165,17 +168,17 @@ func testAccCheckAWSRoleAttributes(role *iam.GetRoleOutput) resource.TestCheckFu const testAccAWSRoleConfig = ` resource "aws_iam_role" "role" { - name = "test-role" - path = "/" - assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}" + name = "test-role" + path = "/" + assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}" } ` const testAccAWSRolePrefixNameConfig = ` resource "aws_iam_role" "role" { - name_prefix = "test-role-" - path = "/" - assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}" + name_prefix = "test-role-" + path = "/" + assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}" } ` diff --git a/website/source/docs/providers/aws/r/iam_role.html.markdown b/website/source/docs/providers/aws/r/iam_role.html.markdown index c9862dd07..bc7511b16 100644 --- a/website/source/docs/providers/aws/r/iam_role.html.markdown +++ b/website/source/docs/providers/aws/r/iam_role.html.markdown @@ -45,5 +45,8 @@ The following arguments are supported: ## Attributes Reference +The following attributes are exported: + * `arn` - The Amazon Resource Name (ARN) specifying the role. +* `create_date` - The creation date of the IAM role. * `unique_id` - The stable and unique string identifying the role.