provider/aws: Randomize some IAM user names to avoid conflicts in tests
This commit is contained in:
parent
dae81df157
commit
3580ae03be
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/iam"
|
"github.com/aws/aws-sdk-go/service/iam"
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -13,23 +14,27 @@ import (
|
||||||
func TestAccAWSPolicyAttachment_basic(t *testing.T) {
|
func TestAccAWSPolicyAttachment_basic(t *testing.T) {
|
||||||
var out iam.ListEntitiesForPolicyOutput
|
var out iam.ListEntitiesForPolicyOutput
|
||||||
|
|
||||||
|
user1 := fmt.Sprintf("test-user-%d", acctest.RandInt())
|
||||||
|
user2 := fmt.Sprintf("test-user-%d", acctest.RandInt())
|
||||||
|
user3 := fmt.Sprintf("test-user-%d", acctest.RandInt())
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSPolicyAttachmentDestroy,
|
CheckDestroy: testAccCheckAWSPolicyAttachmentDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSPolicyAttachConfig,
|
Config: testAccAWSPolicyAttachConfig(user1),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSPolicyAttachmentExists("aws_iam_policy_attachment.test-attach", 3, &out),
|
testAccCheckAWSPolicyAttachmentExists("aws_iam_policy_attachment.test-attach", 3, &out),
|
||||||
testAccCheckAWSPolicyAttachmentAttributes([]string{"test-user"}, []string{"test-role"}, []string{"test-group"}, &out),
|
testAccCheckAWSPolicyAttachmentAttributes([]string{user1}, []string{"test-role"}, []string{"test-group"}, &out),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSPolicyAttachConfigUpdate,
|
Config: testAccAWSPolicyAttachConfigUpdate(user1, user2, user3),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSPolicyAttachmentExists("aws_iam_policy_attachment.test-attach", 6, &out),
|
testAccCheckAWSPolicyAttachmentExists("aws_iam_policy_attachment.test-attach", 6, &out),
|
||||||
testAccCheckAWSPolicyAttachmentAttributes([]string{"test-user3", "test-user3"}, []string{"test-role2", "test-role3"}, []string{"test-group2", "test-group3"}, &out),
|
testAccCheckAWSPolicyAttachmentAttributes([]string{user3, user3}, []string{"test-role2", "test-role3"}, []string{"test-group2", "test-group3"}, &out),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -127,9 +132,10 @@ func testAccCheckAWSPolicyAttachmentAttributes(users []string, roles []string, g
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccAWSPolicyAttachConfig = `
|
func testAccAWSPolicyAttachConfig(u1 string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_iam_user" "user" {
|
resource "aws_iam_user" "user" {
|
||||||
name = "test-user"
|
name = "%s"
|
||||||
}
|
}
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "test-role"
|
name = "test-role"
|
||||||
|
@ -178,18 +184,19 @@ resource "aws_iam_policy_attachment" "test-attach" {
|
||||||
roles = ["${aws_iam_role.role.name}"]
|
roles = ["${aws_iam_role.role.name}"]
|
||||||
groups = ["${aws_iam_group.group.name}"]
|
groups = ["${aws_iam_group.group.name}"]
|
||||||
policy_arn = "${aws_iam_policy.policy.arn}"
|
policy_arn = "${aws_iam_policy.policy.arn}"
|
||||||
|
}`, u1)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
const testAccAWSPolicyAttachConfigUpdate = `
|
func testAccAWSPolicyAttachConfigUpdate(u1, u2, u3 string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "aws_iam_user" "user" {
|
resource "aws_iam_user" "user" {
|
||||||
name = "test-user"
|
name = "%s"
|
||||||
}
|
}
|
||||||
resource "aws_iam_user" "user2" {
|
resource "aws_iam_user" "user2" {
|
||||||
name = "test-user2"
|
name = "%s"
|
||||||
}
|
}
|
||||||
resource "aws_iam_user" "user3" {
|
resource "aws_iam_user" "user3" {
|
||||||
name = "test-user3"
|
name = "%s"
|
||||||
}
|
}
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "test-role"
|
name = "test-role"
|
||||||
|
@ -292,8 +299,8 @@ resource "aws_iam_policy_attachment" "test-attach" {
|
||||||
"${aws_iam_group.group3.name}"
|
"${aws_iam_group.group3.name}"
|
||||||
]
|
]
|
||||||
policy_arn = "${aws_iam_policy.policy.arn}"
|
policy_arn = "${aws_iam_policy.policy.arn}"
|
||||||
|
}`, u1, u2, u3)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
const testAccAWSPolicyPaginatedAttachConfig = `
|
const testAccAWSPolicyPaginatedAttachConfig = `
|
||||||
resource "aws_iam_user" "user" {
|
resource "aws_iam_user" "user" {
|
||||||
|
|
Loading…
Reference in New Issue