github.com/bradfeehan/terraform@v0.7.0-rc3.0.20170529055808-34b45c5ad841/builtin/providers/aws/data_source_aws_db_snapshot_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/acctest" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccAWSDbSnapshotDataSource_basic(t *testing.T) { 13 rInt := acctest.RandInt() 14 resource.Test(t, resource.TestCase{ 15 PreCheck: func() { testAccPreCheck(t) }, 16 Providers: testAccProviders, 17 Steps: []resource.TestStep{ 18 { 19 Config: testAccCheckAwsDbSnapshotDataSourceConfig(rInt), 20 Check: resource.ComposeTestCheckFunc( 21 testAccCheckAwsDbSnapshotDataSourceID("data.aws_db_snapshot.snapshot"), 22 ), 23 }, 24 }, 25 }) 26 } 27 28 func testAccCheckAwsDbSnapshotDataSourceID(n string) resource.TestCheckFunc { 29 return func(s *terraform.State) error { 30 rs, ok := s.RootModule().Resources[n] 31 if !ok { 32 return fmt.Errorf("Can't find Volume data source: %s", n) 33 } 34 35 if rs.Primary.ID == "" { 36 return fmt.Errorf("Snapshot data source ID not set") 37 } 38 return nil 39 } 40 } 41 42 func testAccCheckAwsDbSnapshotDataSourceConfig(rInt int) string { 43 return fmt.Sprintf(` 44 resource "aws_db_instance" "bar" { 45 allocated_storage = 10 46 engine = "MySQL" 47 engine_version = "5.6.21" 48 instance_class = "db.t1.micro" 49 name = "baz" 50 password = "barbarbarbar" 51 username = "foo" 52 skip_final_snapshot = true 53 54 # Maintenance Window is stored in lower case in the API, though not strictly 55 # documented. Terraform will downcase this to match (as opposed to throw a 56 # validation error). 57 maintenance_window = "Fri:09:00-Fri:09:30" 58 59 backup_retention_period = 0 60 61 parameter_group_name = "default.mysql5.6" 62 } 63 64 data "aws_db_snapshot" "snapshot" { 65 most_recent = "true" 66 db_snapshot_identifier = "${aws_db_snapshot.test.id}" 67 } 68 69 70 resource "aws_db_snapshot" "test" { 71 db_instance_identifier = "${aws_db_instance.bar.id}" 72 db_snapshot_identifier = "testsnapshot%d" 73 }`, rInt) 74 }