github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/aws/data_source_aws_efs_file_system_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 TestAccDataSourceAwsEfsFileSystem(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 Steps: []resource.TestStep{ 16 { 17 Config: testAccDataSourceAwsEfsFileSystemConfig, 18 Check: resource.ComposeTestCheckFunc( 19 testAccDataSourceAwsEfsFileSystemCheck("data.aws_efs_file_system.by_creation_token"), 20 testAccDataSourceAwsEfsFileSystemCheck("data.aws_efs_file_system.by_id"), 21 ), 22 }, 23 }, 24 }) 25 } 26 27 func testAccDataSourceAwsEfsFileSystemCheck(name string) resource.TestCheckFunc { 28 return func(s *terraform.State) error { 29 rs, ok := s.RootModule().Resources[name] 30 if !ok { 31 return fmt.Errorf("root module has no resource called %s", name) 32 } 33 34 efsRs, ok := s.RootModule().Resources["aws_efs_file_system.test"] 35 if !ok { 36 return fmt.Errorf("can't find aws_efs_file_system.test in state") 37 } 38 39 attr := rs.Primary.Attributes 40 41 if attr["creation_token"] != efsRs.Primary.Attributes["creation_token"] { 42 return fmt.Errorf( 43 "creation_token is %s; want %s", 44 attr["creation_token"], 45 efsRs.Primary.Attributes["creation_token"], 46 ) 47 } 48 49 if attr["id"] != efsRs.Primary.Attributes["id"] { 50 return fmt.Errorf( 51 "file_system_id is %s; want %s", 52 attr["id"], 53 efsRs.Primary.Attributes["id"], 54 ) 55 } 56 57 return nil 58 } 59 } 60 61 const testAccDataSourceAwsEfsFileSystemConfig = ` 62 resource "aws_efs_file_system" "test" {} 63 64 data "aws_efs_file_system" "by_creation_token" { 65 creation_token = "${aws_efs_file_system.test.creation_token}" 66 } 67 68 data "aws_efs_file_system" "by_id" { 69 file_system_id = "${aws_efs_file_system.test.id}" 70 } 71 `