Skip to content

Commit

Permalink
Allow underscores in IAM user and group names (#9684)
Browse files Browse the repository at this point in the history
* Allow underscores in IAM user and group names

* Add notes to iam_user and iam_group docs that names are not distinguished by case
  • Loading branch information
bandesz authored and stack72 committed Oct 28, 2016
1 parent 990a1ba commit 46cb7b4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions builtin/providers/aws/resource_aws_iam_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ func resourceAwsIamGroupDelete(d *schema.ResourceData, meta interface{}) error {

func validateAwsIamGroupName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9A-Za-z=,.@-]+$`).MatchString(value) {
if !regexp.MustCompile(`^[0-9A-Za-z=,.@\-_]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only alphanumeric characters, hyphens, commas, periods, @ symbols and equals signs allowed in %q: %q",
"only alphanumeric characters, hyphens, underscores, commas, periods, @ symbols and equals signs allowed in %q: %q",
k, value))
}
return
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/resource_aws_iam_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func TestValidateIamGroupName(t *testing.T) {
validNames := []string{
"test-group",
"test_group",
"testgroup123",
"TestGroup",
"Test-Group",
Expand All @@ -34,7 +35,6 @@ func TestValidateIamGroupName(t *testing.T) {
" ",
":",
";",
"testgroup_123",
"test name",
"/slash-at-the-beginning",
"slash-at-the-end/",
Expand Down
4 changes: 2 additions & 2 deletions builtin/providers/aws/resource_aws_iam_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ func resourceAwsIamUserDelete(d *schema.ResourceData, meta interface{}) error {

func validateAwsIamUserName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9A-Za-z=,.@-]+$`).MatchString(value) {
if !regexp.MustCompile(`^[0-9A-Za-z=,.@\-_]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only alphanumeric characters, hyphens, commas, periods, @ symbols and equals signs allowed in %q: %q",
"only alphanumeric characters, hyphens, underscores, commas, periods, @ symbols and equals signs allowed in %q: %q",
k, value))
}
return
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/resource_aws_iam_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
func TestValidateIamUserName(t *testing.T) {
validNames := []string{
"test-user",
"test_user",
"testuser123",
"TestUser",
"Test-User",
Expand All @@ -35,7 +36,6 @@ func TestValidateIamUserName(t *testing.T) {
" ",
":",
";",
"testuser_123",
"test name",
"/slash-at-the-beginning",
"slash-at-the-end/",
Expand Down
8 changes: 4 additions & 4 deletions website/source/docs/providers/aws/r/iam_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ resource "aws_iam_group" "developers" {

The following arguments are supported:

* `name` - (Required) The group's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-.`.
* `name` - (Required) The group's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. Group names are not distinguished by case. For example, you cannot create groups named both "ADMINS" and "admins".
* `path` - (Optional, default "/") Path in which to create the group.

## Attributes Reference
Expand All @@ -37,11 +37,11 @@ The following attributes are exported:
* `unique_id` - The [unique ID][1] assigned by AWS.

[1]: https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html#GUIDs

## Import

IAM Groups can be imported using the `name`, e.g.
IAM Groups can be imported using the `name`, e.g.

```
$ terraform import aws_iam_group.developers developers
```
```
4 changes: 2 additions & 2 deletions website/source/docs/providers/aws/r/iam_user.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EOF

The following arguments are supported:

* `name` - (Required) The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-.`.
* `name` - (Required) The user's name. The name must consist of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: `=,.@-_.`. User names are not distinguished by case. For example, you cannot create users named both "TESTUSER" and "testuser".
* `path` - (Optional, default "/") Path in which to create the user.
* `force_destroy` - (Optional, default false) When destroying this user, destroy
even if it has non-Terraform-managed IAM access keys. Without `force_destroy`
Expand All @@ -64,7 +64,7 @@ The following attributes are exported:

## Import

IAM Users can be imported using the `name`, e.g.
IAM Users can be imported using the `name`, e.g.

```
$ terraform import aws_iam_user.lb loadbalancer
Expand Down

0 comments on commit 46cb7b4

Please sign in to comment.