github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/import_aws_iam_role_policy_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/resource"
     8  )
     9  
    10  func testAccAwsIamRolePolicyConfig(suffix string) string {
    11  	return fmt.Sprintf(`
    12  resource "aws_iam_role" "role_%[1]s" {
    13  	name = "tf_test_role_test_%[1]s"
    14  	path = "/"
    15  	assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"
    16  }
    17  
    18  resource "aws_iam_role_policy" "foo_%[1]s" {
    19  	name = "tf_test_policy_test_%[1]s"
    20  	role = "${aws_iam_role.role_%[1]s.name}"
    21  	policy = <<EOF
    22  {
    23    "Version": "2012-10-17",
    24    "Statement": {
    25      "Effect": "Allow",
    26      "Action": "*",
    27      "Resource": "*"
    28    }
    29  }
    30  EOF
    31  }
    32  `, suffix)
    33  }
    34  
    35  func TestAccAWSIAMRolePolicy_importBasic(t *testing.T) {
    36  	suffix := randomString(10)
    37  	resourceName := fmt.Sprintf("aws_iam_role_policy.foo_%s", suffix)
    38  
    39  	resource.Test(t, resource.TestCase{
    40  		PreCheck:     func() { testAccPreCheck(t) },
    41  		Providers:    testAccProviders,
    42  		CheckDestroy: testAccCheckIAMRolePolicyDestroy,
    43  		Steps: []resource.TestStep{
    44  			resource.TestStep{
    45  				Config: testAccAwsIamRolePolicyConfig(suffix),
    46  			},
    47  
    48  			resource.TestStep{
    49  				ResourceName:      resourceName,
    50  				ImportState:       true,
    51  				ImportStateVerify: true,
    52  			},
    53  		},
    54  	})
    55  }