Added aws_iam_role import. Now that we read the assume_role_policy it highlights all of the tests that change this, so I've fixed a bunch of those while i'm in here. (#7617)
This commit is contained in:
parent
25f1c6dc02
commit
6c2949fdac
|
@ -0,0 +1,28 @@
|
||||||
|
package aws
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccAWSRole_importBasic(t *testing.T) {
|
||||||
|
resourceName := "aws_iam_role.role"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSRoleDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSRoleConfig,
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -121,7 +121,7 @@ func testAccCheckAWSInstanceProfileExists(n string, res *iam.GetInstanceProfileO
|
||||||
const testAccAwsIamInstanceProfileConfig = `
|
const testAccAwsIamInstanceProfileConfig = `
|
||||||
resource "aws_iam_role" "test" {
|
resource "aws_iam_role" "test" {
|
||||||
name = "test"
|
name = "test"
|
||||||
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\"}]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_instance_profile" "test" {
|
resource "aws_iam_instance_profile" "test" {
|
||||||
|
@ -133,7 +133,7 @@ resource "aws_iam_instance_profile" "test" {
|
||||||
const testAccAWSInstanceProfilePrefixNameConfig = `
|
const testAccAWSInstanceProfilePrefixNameConfig = `
|
||||||
resource "aws_iam_role" "test" {
|
resource "aws_iam_role" "test" {
|
||||||
name = "test"
|
name = "test"
|
||||||
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\"}]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_instance_profile" "test" {
|
resource "aws_iam_instance_profile" "test" {
|
||||||
|
|
|
@ -114,21 +114,7 @@ resource "aws_iam_user" "user" {
|
||||||
}
|
}
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "test-role"
|
name = "test-role"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_group" "group" {
|
resource "aws_iam_group" "group" {
|
||||||
|
@ -175,60 +161,15 @@ resource "aws_iam_user" "user3" {
|
||||||
}
|
}
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "test-role"
|
name = "test-role"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "aws_iam_role" "role2" {
|
resource "aws_iam_role" "role2" {
|
||||||
name = "test-role2"
|
name = "test-role2"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
}
|
}
|
||||||
resource "aws_iam_role" "role3" {
|
resource "aws_iam_role" "role3" {
|
||||||
name = "test-role3"
|
name = "test-role3"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
}
|
}
|
||||||
resource "aws_iam_group" "group" {
|
resource "aws_iam_group" "group" {
|
||||||
name = "test-group"
|
name = "test-group"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -20,6 +21,10 @@ func resourceAwsIamRole() *schema.Resource {
|
||||||
Update: resourceAwsIamRoleUpdate,
|
Update: resourceAwsIamRoleUpdate,
|
||||||
Delete: resourceAwsIamRoleDelete,
|
Delete: resourceAwsIamRoleDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"arn": &schema.Schema{
|
"arn": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -174,6 +179,10 @@ 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
|
||||||
}
|
}
|
||||||
|
policy, _ := url.QueryUnescape(*role.AssumeRolePolicyDocument)
|
||||||
|
if err := d.Set("assume_role_policy", aws.String(policy)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,21 +91,7 @@ func testAccCheckAWSRolePolicyAttachmentAttributes(policies []string, out *iam.L
|
||||||
const testAccAWSRolePolicyAttachConfig = `
|
const testAccAWSRolePolicyAttachConfig = `
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "test-role"
|
name = "test-role"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_policy" "policy" {
|
resource "aws_iam_policy" "policy" {
|
||||||
|
@ -136,21 +122,7 @@ resource "aws_iam_role_policy_attachment" "test-attach" {
|
||||||
const testAccAWSRolePolicyAttachConfigUpdate = `
|
const testAccAWSRolePolicyAttachConfigUpdate = `
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "test-role"
|
name = "test-role"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_policy" "policy" {
|
resource "aws_iam_policy" "policy" {
|
||||||
|
|
|
@ -115,7 +115,7 @@ func testAccIAMRolePolicyConfig(role, policy1 string) string {
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "tf_test_role_%s"
|
name = "tf_test_role_%s"
|
||||||
path = "/"
|
path = "/"
|
||||||
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}"
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy" "foo" {
|
resource "aws_iam_role_policy" "foo" {
|
||||||
|
@ -131,7 +131,7 @@ func testAccIAMRolePolicyConfigUpdate(role, policy1, policy2 string) string {
|
||||||
resource "aws_iam_role" "role" {
|
resource "aws_iam_role" "role" {
|
||||||
name = "tf_test_role_%s"
|
name = "tf_test_role_%s"
|
||||||
path = "/"
|
path = "/"
|
||||||
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}"
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy" "foo" {
|
resource "aws_iam_role_policy" "foo" {
|
||||||
|
|
|
@ -167,7 +167,7 @@ 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\"}]}"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -175,29 +175,14 @@ 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\"}]}"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testAccAWSRolePre = `
|
const testAccAWSRolePre = `
|
||||||
resource "aws_iam_role" "role_update_test" {
|
resource "aws_iam_role" "role_update_test" {
|
||||||
name = "tf_old_name"
|
name = "tf_old_name"
|
||||||
path = "/test/"
|
path = "/test/"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy" "role_update_test" {
|
resource "aws_iam_role_policy" "role_update_test" {
|
||||||
|
@ -232,21 +217,7 @@ const testAccAWSRolePost = `
|
||||||
resource "aws_iam_role" "role_update_test" {
|
resource "aws_iam_role" "role_update_test" {
|
||||||
name = "tf_new_name"
|
name = "tf_new_name"
|
||||||
path = "/test/"
|
path = "/test/"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
|
||||||
{
|
|
||||||
"Version": "2012-10-17",
|
|
||||||
"Statement": [
|
|
||||||
{
|
|
||||||
"Action": "sts:AssumeRole",
|
|
||||||
"Principal": {
|
|
||||||
"Service": "ec2.amazonaws.com"
|
|
||||||
},
|
|
||||||
"Effect": "Allow",
|
|
||||||
"Sid": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy" "role_update_test" {
|
resource "aws_iam_role_policy" "role_update_test" {
|
||||||
|
|
Loading…
Reference in New Issue