diff --git a/builtin/providers/aws/import_aws_iam_instance_profile_test.go b/builtin/providers/aws/import_aws_iam_instance_profile_test.go new file mode 100644 index 000000000000..191f9ac85010 --- /dev/null +++ b/builtin/providers/aws/import_aws_iam_instance_profile_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSIAMInstanceProfile_importBasic(t *testing.T) { + resourceName := "aws_iam_instance_profile.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSInstanceProfileDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAwsIamInstanceProfileConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/import_aws_iam_policy_test.go b/builtin/providers/aws/import_aws_iam_policy_test.go new file mode 100644 index 000000000000..d40145b58741 --- /dev/null +++ b/builtin/providers/aws/import_aws_iam_policy_test.go @@ -0,0 +1,88 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "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/terraform" +) + +func testAccAwsIamPolicyConfig(suffix string) string { + return fmt.Sprintf(` +resource "aws_iam_policy" "test_%[1]s" { + name = "test_policy_%[1]s" + path = "/" + description = "My test policy" + policy = <:") + return + } + roleName = parts[0] policyName = parts[1] return diff --git a/builtin/providers/aws/resource_aws_iam_role_policy_test.go b/builtin/providers/aws/resource_aws_iam_role_policy_test.go index 2b2e64318c34..b4d6caeedabc 100644 --- a/builtin/providers/aws/resource_aws_iam_role_policy_test.go +++ b/builtin/providers/aws/resource_aws_iam_role_policy_test.go @@ -52,14 +52,16 @@ func testAccCheckIAMRolePolicyDestroy(s *terraform.State) error { continue } - role, name := resourceAwsIamRolePolicyParseId(rs.Primary.ID) + role, name, err := resourceAwsIamRolePolicyParseId(rs.Primary.ID) + if err != nil { + return err + } request := &iam.GetRolePolicyInput{ PolicyName: aws.String(name), RoleName: aws.String(role), } - var err error getResp, err := iamconn.GetRolePolicy(request) if err != nil { if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { @@ -96,12 +98,15 @@ func testAccCheckIAMRolePolicy( } iamconn := testAccProvider.Meta().(*AWSClient).iamconn - role, name := resourceAwsIamRolePolicyParseId(policy.Primary.ID) - _, err := iamconn.GetRolePolicy(&iam.GetRolePolicyInput{ + role, name, err := resourceAwsIamRolePolicyParseId(policy.Primary.ID) + if err != nil { + return err + } + + _, err = iamconn.GetRolePolicy(&iam.GetRolePolicyInput{ RoleName: aws.String(role), PolicyName: aws.String(name), }) - if err != nil { return err } diff --git a/builtin/providers/aws/resource_aws_iam_user_policy_test.go b/builtin/providers/aws/resource_aws_iam_user_policy_test.go index 019d82506ae2..6a48fa973cd2 100644 --- a/builtin/providers/aws/resource_aws_iam_user_policy_test.go +++ b/builtin/providers/aws/resource_aws_iam_user_policy_test.go @@ -47,7 +47,7 @@ func testAccCheckIAMUserPolicyDestroy(s *terraform.State) error { continue } - role, name := resourceAwsIamRolePolicyParseId(rs.Primary.ID) + role, name := resourceAwsIamUserPolicyParseId(rs.Primary.ID) request := &iam.GetRolePolicyInput{ PolicyName: aws.String(name),