-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Add name_prefix
to aws_iam_instance_profile
and aws_iam_role
#6939
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
|
@@ -23,18 +24,23 @@ func resourceAwsIamInstanceProfile() *schema.Resource { | |
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"create_date": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"unique_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
ConflictsWith: []string{"name_prefix"}, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
// https://github.com/boto/botocore/blob/2485f5c/botocore/data/iam/2010-05-08/service-2.json#L8196-L8201 | ||
value := v.(string) | ||
|
@@ -49,12 +55,33 @@ func resourceAwsIamInstanceProfile() *schema.Resource { | |
return | ||
}, | ||
}, | ||
|
||
"name_prefix": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
// https://github.com/boto/botocore/blob/2485f5c/botocore/data/iam/2010-05-08/service-2.json#L8196-L8201 | ||
value := v.(string) | ||
if len(value) > 64 { | ||
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. This value probably isn't correct... are there any guarantees made about the length of the string returned by the |
||
errors = append(errors, fmt.Errorf( | ||
"%q cannot be longer than 64 characters, name is limited to 128", k)) | ||
} | ||
if !regexp.MustCompile("^[\\w+=,.@-]+$").MatchString(value) { | ||
errors = append(errors, fmt.Errorf( | ||
"%q must match [\\w+=,.@-]", k)) | ||
} | ||
return | ||
}, | ||
}, | ||
|
||
"path": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "/", | ||
ForceNew: true, | ||
}, | ||
|
||
"roles": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Required: true, | ||
|
@@ -67,7 +94,15 @@ func resourceAwsIamInstanceProfile() *schema.Resource { | |
|
||
func resourceAwsIamInstanceProfileCreate(d *schema.ResourceData, meta interface{}) error { | ||
iamconn := meta.(*AWSClient).iamconn | ||
name := d.Get("name").(string) | ||
|
||
var name string | ||
if v, ok := d.GetOk("name"); ok { | ||
name = v.(string) | ||
} else if v, ok := d.GetOk("name_prefix"); ok { | ||
name = resource.PrefixedUniqueId(v.(string)) | ||
} else { | ||
name = resource.UniqueId() | ||
} | ||
|
||
request := &iam.CreateInstanceProfileInput{ | ||
InstanceProfileName: aws.String(name), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
|
@@ -23,14 +24,18 @@ func resourceAwsIamRole() *schema.Resource { | |
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"unique_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
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. Again this needs to be computed so that when we don't set it as part of our config, the Read can still set it and allow it to not cause Updates :) |
||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
ConflictsWith: []string{"name_prefix"}, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
// https://github.com/boto/botocore/blob/2485f5c/botocore/data/iam/2010-05-08/service-2.json#L8329-L8334 | ||
value := v.(string) | ||
|
@@ -45,12 +50,33 @@ func resourceAwsIamRole() *schema.Resource { | |
return | ||
}, | ||
}, | ||
|
||
"name_prefix": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { | ||
// https://github.com/boto/botocore/blob/2485f5c/botocore/data/iam/2010-05-08/service-2.json#L8329-L8334 | ||
value := v.(string) | ||
if len(value) > 32 { | ||
errors = append(errors, fmt.Errorf( | ||
"%q cannot be longer than 32 characters, name is limited to 64", k)) | ||
} | ||
if !regexp.MustCompile("^[\\w+=,.@-]*$").MatchString(value) { | ||
errors = append(errors, fmt.Errorf( | ||
"%q must match [\\w+=,.@-]", k)) | ||
} | ||
return | ||
}, | ||
}, | ||
|
||
"path": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "/", | ||
ForceNew: true, | ||
}, | ||
|
||
"assume_role_policy": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
|
@@ -61,7 +87,15 @@ func resourceAwsIamRole() *schema.Resource { | |
|
||
func resourceAwsIamRoleCreate(d *schema.ResourceData, meta interface{}) error { | ||
iamconn := meta.(*AWSClient).iamconn | ||
name := d.Get("name").(string) | ||
|
||
var name string | ||
if v, ok := d.GetOk("name"); ok { | ||
name = v.(string) | ||
} else if v, ok := d.GetOk("name_prefix"); ok { | ||
name = resource.PrefixedUniqueId(v.(string)) | ||
} else { | ||
name = resource.UniqueId() | ||
} | ||
|
||
request := &iam.CreateRoleInput{ | ||
Path: aws.String(d.Get("path").(string)), | ||
|
@@ -93,6 +127,7 @@ func resourceAwsIamRoleRead(d *schema.ResourceData, meta interface{}) error { | |
} | ||
return resourceAwsIamRoleReadResult(d, getResp.Role) | ||
} | ||
|
||
func resourceAwsIamRoleUpdate(d *schema.ResourceData, meta interface{}) error { | ||
iamconn := meta.(*AWSClient).iamconn | ||
|
||
|
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.
@joshuaspence as you do not specify a name but do specify a name_prefix, you need to make name Computed. This means that when we set it in the Read, we will not get any alternative plan
Doing this locally gave me this: