diff --git a/builtin/providers/aws/resource_aws_ami_launch_permission_test.go b/builtin/providers/aws/resource_aws_ami_launch_permission_test.go index 4f67d48fb6c4..c886077e1157 100644 --- a/builtin/providers/aws/resource_aws_ami_launch_permission_test.go +++ b/builtin/providers/aws/resource_aws_ami_launch_permission_test.go @@ -15,18 +15,25 @@ type testLaunchPermission struct { func TestAccAWSAMILaunchPermission_Basic(t *testing.T) { tlp := &testLaunchPermission{} + getAccountId := func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).stsconn + res, err := conn.GetCallerIdentity(&sts.GetCallerIdentityInput{}) + if err != nil { + t.Fatalf("could not initialize ami launch permission test: %s", err) + } + tlp.AccountID = *res.Account + return nil + } + r.Test(t, r.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - conn := testAccProvider.Meta().(*AWSClient).stsconn - res, err := conn.GetCallerIdentity(&sts.GetCallerIdentityInput{}) - if err != nil { - t.Fatalf("could not initialize ami launch permission test: %s", err) - } - tlp.AccountID = *res.Account - }, + PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []r.TestStep{ + // First step is a way to get the aws provider initialized so we can use its account id + r.TestStep{ + Config: testAccAWSAMILaunchPermissionConfig(nil), + Check: r.ComposeTestCheckFunc(getAccountId), + }, r.TestStep{ Config: testAccAWSAMILaunchPermissionConfig(tlp), Check: r.ComposeTestCheckFunc( @@ -82,7 +89,7 @@ func testAccAWSAMILaunchPermissionDestroyed(tlp *testLaunchPermission) r.TestChe } func testAccAWSAMILaunchPermissionConfig(tlp *testLaunchPermission) string { - return fmt.Sprintf(` + base := ` provider "aws" { region = "us-east-1" } @@ -127,6 +134,13 @@ resource "aws_ami_from_instance" "test" { description = "Testing Terraform aws_ami_from_instance resource" source_instance_id = "${aws_instance.test.id}" } +` + + if tlp == nil { + return base + } + + return base + fmt.Sprintf(` resource "aws_ami_launch_permission" "self-test" { image_id = "${aws_ami_from_instance.test.id}"