github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_availability_zone_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 TestAccDataSourceAwsAvailabilityZone(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 Steps: []resource.TestStep{ 16 resource.TestStep{ 17 Config: testAccDataSourceAwsAvailabilityZoneConfig, 18 Check: resource.ComposeTestCheckFunc( 19 testAccDataSourceAwsAvailabilityZoneCheck("data.aws_availability_zone.by_name"), 20 ), 21 }, 22 }, 23 }) 24 } 25 26 func testAccDataSourceAwsAvailabilityZoneCheck(name string) resource.TestCheckFunc { 27 return func(s *terraform.State) error { 28 rs, ok := s.RootModule().Resources[name] 29 if !ok { 30 return fmt.Errorf("root module has no resource called %s", name) 31 } 32 33 attr := rs.Primary.Attributes 34 35 if attr["name"] != "us-west-2a" { 36 return fmt.Errorf("bad name %s", attr["name"]) 37 } 38 if attr["name_suffix"] != "a" { 39 return fmt.Errorf("bad name_suffix %s", attr["name_suffix"]) 40 } 41 if attr["region"] != "us-west-2" { 42 return fmt.Errorf("bad region %s", attr["region"]) 43 } 44 45 return nil 46 } 47 } 48 49 const testAccDataSourceAwsAvailabilityZoneConfig = ` 50 provider "aws" { 51 region = "us-west-2" 52 } 53 54 data "aws_availability_zone" "by_name" { 55 name = "us-west-2a" 56 } 57 `