Skip to content

Commit

Permalink
Collecting account id after provider is "ready".
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Sickles committed Jun 28, 2016
1 parent 7837786 commit 03547e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 16 additions & 0 deletions builtin/providers/aws/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/aws/aws-sdk-go/service/sts"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
Expand Down Expand Up @@ -43,3 +44,18 @@ func testAccPreCheck(t *testing.T) {
os.Setenv("AWS_DEFAULT_REGION", "us-west-2")
}
}

// Relies on env vars in pre check
func testAccPreGetCallerIdentity(t *testing.T) string {
c := &Config{}
iclient, err := c.Client()
if err != nil {
t.Fatalf("could not initialize aws client: %s", err)
}
client := iclient.(AWSClient)
res, err := client.stsconn.GetCallerIdentity(&sts.GetCallerIdentityInput{})
if err != nil {
t.Fatalf("could not collect aws caller identity: %s", err)
}
return *res.Account
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws

import (
"fmt"
"github.com/aws/aws-sdk-go/service/sts"
r "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"testing"
Expand All @@ -15,15 +14,11 @@ type testLaunchPermission struct {

func TestAccAWSAMILaunchPermission_Basic(t *testing.T) {
tlp := &testLaunchPermission{}

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
tlp.AccountID = testAccPreGetCallerIdentity(t)
},
Providers: testAccProviders,
Steps: []r.TestStep{
Expand Down

0 comments on commit 03547e5

Please sign in to comment.