github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_caller_identity_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccAWSCallerIdentity_basic(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 Steps: []resource.TestStep{ 16 { 17 Config: testAccCheckAwsCallerIdentityConfig_basic, 18 Check: resource.ComposeTestCheckFunc( 19 testAccCheckAwsCallerIdentityAccountId("data.aws_caller_identity.current"), 20 ), 21 }, 22 }, 23 }) 24 } 25 26 func testAccCheckAwsCallerIdentityAccountId(n string) resource.TestCheckFunc { 27 return func(s *terraform.State) error { 28 rs, ok := s.RootModule().Resources[n] 29 if !ok { 30 return fmt.Errorf("Can't find AccountID resource: %s", n) 31 } 32 33 if rs.Primary.ID == "" { 34 return fmt.Errorf("Account Id resource ID not set.") 35 } 36 37 expected := testAccProvider.Meta().(*AWSClient).accountid 38 if rs.Primary.Attributes["account_id"] != expected { 39 return fmt.Errorf("Incorrect Account ID: expected %q, got %q", expected, rs.Primary.Attributes["account_id"]) 40 } 41 42 if rs.Primary.Attributes["user_id"] == "" { 43 return fmt.Errorf("UserID expected to not be nil") 44 } 45 46 if rs.Primary.Attributes["arn"] == "" { 47 return fmt.Errorf("ARN expected to not be nil") 48 } 49 50 return nil 51 } 52 } 53 54 const testAccCheckAwsCallerIdentityConfig_basic = ` 55 data "aws_caller_identity" "current" { } 56 `