provider/aws: Update IAM Role Policy Attachment Acctests
Leaked resources may prevent this resource from correctly passing acceptance tests. Seeding the policy names with random integer suffixes allows tests to pass regardless of resource leaks. ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSRolePolicyAttachment_basic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/22 19:58:58 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSRolePolicyAttachment_basic -timeout 120m === RUN TestAccAWSRolePolicyAttachment_basic --- PASS: TestAccAWSRolePolicyAttachment_basic (31.98s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 31.989s ```
This commit is contained in:
parent
c105784c60
commit
ea40ef9596
|
@ -7,30 +7,35 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSRolePolicyAttachment_basic(t *testing.T) {
|
func TestAccAWSRolePolicyAttachment_basic(t *testing.T) {
|
||||||
var out iam.ListAttachedRolePoliciesOutput
|
var out iam.ListAttachedRolePoliciesOutput
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
testPolicy := fmt.Sprintf("test-policy-%d", rInt)
|
||||||
|
testPolicy2 := fmt.Sprintf("test-policy2-%d", rInt)
|
||||||
|
testPolicy3 := fmt.Sprintf("test-policy3-%d", rInt)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSRolePolicyAttachmentDestroy,
|
CheckDestroy: testAccCheckAWSRolePolicyAttachmentDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSRolePolicyAttachConfig,
|
Config: testAccAWSRolePolicyAttachConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSRolePolicyAttachmentExists("aws_iam_role_policy_attachment.test-attach", 1, &out),
|
testAccCheckAWSRolePolicyAttachmentExists("aws_iam_role_policy_attachment.test-attach", 1, &out),
|
||||||
testAccCheckAWSRolePolicyAttachmentAttributes([]string{"test-policy"}, &out),
|
testAccCheckAWSRolePolicyAttachmentAttributes([]string{testPolicy}, &out),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSRolePolicyAttachConfigUpdate,
|
Config: testAccAWSRolePolicyAttachConfigUpdate(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSRolePolicyAttachmentExists("aws_iam_role_policy_attachment.test-attach", 2, &out),
|
testAccCheckAWSRolePolicyAttachmentExists("aws_iam_role_policy_attachment.test-attach", 2, &out),
|
||||||
testAccCheckAWSRolePolicyAttachmentAttributes([]string{"test-policy2", "test-policy3"}, &out),
|
testAccCheckAWSRolePolicyAttachmentAttributes([]string{testPolicy2, testPolicy3}, &out),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -88,9 +93,10 @@ func testAccCheckAWSRolePolicyAttachmentAttributes(policies []string, out *iam.L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccAWSRolePolicyAttachConfig = `
|
func testAccAWSRolePolicyAttachConfig(rInt int) string {
|
||||||
resource "aws_iam_role" "role" {
|
return fmt.Sprintf(`
|
||||||
name = "test-role"
|
resource "aws_iam_role" "role" {
|
||||||
|
name = "test-role-%d"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = <<EOF
|
||||||
{
|
{
|
||||||
"Version": "2012-10-17",
|
"Version": "2012-10-17",
|
||||||
|
@ -106,10 +112,10 @@ resource "aws_iam_role" "role" {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_policy" "policy" {
|
resource "aws_iam_policy" "policy" {
|
||||||
name = "test-policy"
|
name = "test-policy-%d"
|
||||||
description = "A test policy"
|
description = "A test policy"
|
||||||
policy = <<EOF
|
policy = <<EOF
|
||||||
{
|
{
|
||||||
|
@ -125,17 +131,18 @@ resource "aws_iam_policy" "policy" {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy_attachment" "test-attach" {
|
resource "aws_iam_role_policy_attachment" "test-attach" {
|
||||||
role = "${aws_iam_role.role.name}"
|
role = "${aws_iam_role.role.name}"
|
||||||
policy_arn = "${aws_iam_policy.policy.arn}"
|
policy_arn = "${aws_iam_policy.policy.arn}"
|
||||||
|
}`, rInt, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
const testAccAWSRolePolicyAttachConfigUpdate = `
|
func testAccAWSRolePolicyAttachConfigUpdate(rInt int) string {
|
||||||
resource "aws_iam_role" "role" {
|
return fmt.Sprintf(`
|
||||||
name = "test-role"
|
resource "aws_iam_role" "role" {
|
||||||
|
name = "test-role-%d"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = <<EOF
|
||||||
{
|
{
|
||||||
"Version": "2012-10-17",
|
"Version": "2012-10-17",
|
||||||
|
@ -151,10 +158,10 @@ resource "aws_iam_role" "role" {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_policy" "policy" {
|
resource "aws_iam_policy" "policy" {
|
||||||
name = "test-policy"
|
name = "test-policy-%d"
|
||||||
description = "A test policy"
|
description = "A test policy"
|
||||||
policy = <<EOF
|
policy = <<EOF
|
||||||
{
|
{
|
||||||
|
@ -170,10 +177,10 @@ resource "aws_iam_policy" "policy" {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_policy" "policy2" {
|
resource "aws_iam_policy" "policy2" {
|
||||||
name = "test-policy2"
|
name = "test-policy2-%d"
|
||||||
description = "A test policy"
|
description = "A test policy"
|
||||||
policy = <<EOF
|
policy = <<EOF
|
||||||
{
|
{
|
||||||
|
@ -189,10 +196,10 @@ resource "aws_iam_policy" "policy2" {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_policy" "policy3" {
|
resource "aws_iam_policy" "policy3" {
|
||||||
name = "test-policy3"
|
name = "test-policy3-%d"
|
||||||
description = "A test policy"
|
description = "A test policy"
|
||||||
policy = <<EOF
|
policy = <<EOF
|
||||||
{
|
{
|
||||||
|
@ -208,15 +215,15 @@ resource "aws_iam_policy" "policy3" {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy_attachment" "test-attach" {
|
resource "aws_iam_role_policy_attachment" "test-attach" {
|
||||||
role = "${aws_iam_role.role.name}"
|
role = "${aws_iam_role.role.name}"
|
||||||
policy_arn = "${aws_iam_policy.policy2.arn}"
|
policy_arn = "${aws_iam_policy.policy2.arn}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy_attachment" "test-attach2" {
|
resource "aws_iam_role_policy_attachment" "test-attach2" {
|
||||||
role = "${aws_iam_role.role.name}"
|
role = "${aws_iam_role.role.name}"
|
||||||
policy_arn = "${aws_iam_policy.policy3.arn}"
|
policy_arn = "${aws_iam_policy.policy3.arn}"
|
||||||
|
}`, rInt, rInt, rInt, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
Loading…
Reference in New Issue