github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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 return nil 43 } 44 } 45 46 const testAccCheckAwsCallerIdentityConfig_basic = ` 47 data "aws_caller_identity" "current" { } 48 `