Fixed ##10079 exposing aws_iam_role create_date attribute (#10091)

This commit is contained in:
Ninir 2016-11-14 10:33:53 +01:00 committed by Paul Stack
parent 0bb8ab9afb
commit d8e846c895
3 changed files with 30 additions and 16 deletions

View File

@ -21,17 +21,17 @@ func resourceAwsIamRole() *schema.Resource {
Delete: resourceAwsIamRoleDelete, Delete: resourceAwsIamRoleDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"arn": &schema.Schema{ "arn": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"unique_id": &schema.Schema{ "unique_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"name": &schema.Schema{ "name": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
@ -52,7 +52,7 @@ func resourceAwsIamRole() *schema.Resource {
}, },
}, },
"name_prefix": &schema.Schema{ "name_prefix": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
@ -71,17 +71,22 @@ func resourceAwsIamRole() *schema.Resource {
}, },
}, },
"path": &schema.Schema{ "path": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: "/", Default: "/",
ForceNew: true, ForceNew: true,
}, },
"assume_role_policy": &schema.Schema{ "assume_role_policy": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, 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 { if err := d.Set("unique_id", role.RoleId); err != nil {
return err return err
} }
if err := d.Set("create_date", role.CreateDate.Format(time.RFC3339)); err != nil {
return err
}
return nil return nil
} }

View File

@ -20,11 +20,14 @@ func TestAccAWSRole_basic(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRoleDestroy, CheckDestroy: testAccCheckAWSRoleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSRoleConfig, Config: testAccAWSRoleConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists("aws_iam_role.role", &conf), testAccCheckAWSRoleExists("aws_iam_role.role", &conf),
testAccCheckAWSRoleAttributes(&conf), testAccCheckAWSRoleAttributes(&conf),
resource.TestCheckResourceAttrSet(
"aws_iam_role.role", "create_date",
),
), ),
}, },
}, },
@ -41,7 +44,7 @@ func TestAccAWSRole_namePrefix(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRoleDestroy, CheckDestroy: testAccCheckAWSRoleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSRolePrefixNameConfig, Config: testAccAWSRolePrefixNameConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists("aws_iam_role.role", &conf), testAccCheckAWSRoleExists("aws_iam_role.role", &conf),
@ -61,14 +64,14 @@ func TestAccAWSRole_testNameChange(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRoleDestroy, CheckDestroy: testAccCheckAWSRoleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSRolePre, Config: testAccAWSRolePre,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists("aws_iam_role.role_update_test", &conf), testAccCheckAWSRoleExists("aws_iam_role.role_update_test", &conf),
), ),
}, },
resource.TestStep{ {
Config: testAccAWSRolePost, Config: testAccAWSRolePost,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists("aws_iam_role.role_update_test", &conf), testAccCheckAWSRoleExists("aws_iam_role.role_update_test", &conf),
@ -165,17 +168,17 @@ func testAccCheckAWSRoleAttributes(role *iam.GetRoleOutput) resource.TestCheckFu
const testAccAWSRoleConfig = ` const testAccAWSRoleConfig = `
resource "aws_iam_role" "role" { resource "aws_iam_role" "role" {
name = "test-role" name = "test-role"
path = "/" path = "/"
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}" assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}"
} }
` `
const testAccAWSRolePrefixNameConfig = ` const testAccAWSRolePrefixNameConfig = `
resource "aws_iam_role" "role" { resource "aws_iam_role" "role" {
name_prefix = "test-role-" name_prefix = "test-role-"
path = "/" path = "/"
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}" assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}"
} }
` `

View File

@ -45,5 +45,8 @@ The following arguments are supported:
## Attributes Reference ## Attributes Reference
The following attributes are exported:
* `arn` - The Amazon Resource Name (ARN) specifying the role. * `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. * `unique_id` - The stable and unique string identifying the role.