github.com/ves/terraform@v0.8.0-beta2/builtin/providers/aws/resource_aws_opsworks_permission_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/acctest" 8 "github.com/hashicorp/terraform/helper/resource" 9 ) 10 11 func TestAccAWSOpsworksPermission(t *testing.T) { 12 rName := fmt.Sprintf("test-user-%d", acctest.RandInt()) 13 roleName := fmt.Sprintf("tf-ops-user-profile-%d", acctest.RandInt()) 14 resource.Test(t, resource.TestCase{ 15 PreCheck: func() { testAccPreCheck(t) }, 16 Providers: testAccProviders, 17 Steps: []resource.TestStep{ 18 resource.TestStep{ 19 Config: testAccAwsOpsworksPermissionCreate(rName, roleName), 20 Check: resource.ComposeTestCheckFunc( 21 resource.TestCheckResourceAttr( 22 "aws_opsworks_permission.tf-acc-perm", "allow_ssh", "true", 23 ), 24 resource.TestCheckResourceAttr( 25 "aws_opsworks_permission.tf-acc-perm", "allow_sudo", "true", 26 ), 27 resource.TestCheckResourceAttr( 28 "aws_opsworks_permission.tf-acc-perm", "level", "iam_only", 29 ), 30 ), 31 }, 32 }, 33 }) 34 } 35 36 func testAccAwsOpsworksPermissionCreate(rn, roleName string) string { 37 return fmt.Sprintf(` 38 resource "aws_opsworks_permission" "tf-acc-perm" { 39 stack_id = "${aws_opsworks_stack.tf-acc.id}" 40 41 allow_ssh = true 42 allow_sudo = true 43 user_arn = "${aws_opsworks_user_profile.user.user_arn}" 44 level = "iam_only" 45 } 46 47 resource "aws_opsworks_user_profile" "user" { 48 user_arn = "${aws_iam_user.user.arn}" 49 ssh_username = "${aws_iam_user.user.name}" 50 } 51 52 resource "aws_iam_user" "user" { 53 name = "%s" 54 path = "/" 55 } 56 57 %s 58 `, rn, testAccAwsOpsworksStackConfigNoVpcCreate(rn)) 59 }