github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_ebs_snapshot_ids_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/satori/uuid" 9 ) 10 11 func TestAccDataSourceAwsEbsSnapshotIds_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: testAccDataSourceAwsEbsSnapshotIdsConfig_basic, 18 Check: resource.ComposeTestCheckFunc( 19 testAccCheckAwsEbsSnapshotDataSourceID("data.aws_ebs_snapshot_ids.test"), 20 ), 21 }, 22 }, 23 }) 24 } 25 26 func TestAccDataSourceAwsEbsSnapshotIds_sorted(t *testing.T) { 27 uuid := uuid.NewV4().String() 28 29 resource.Test(t, resource.TestCase{ 30 PreCheck: func() { testAccPreCheck(t) }, 31 Providers: testAccProviders, 32 Steps: []resource.TestStep{ 33 { 34 Config: testAccDataSourceAwsEbsSnapshotIdsConfig_sorted1(uuid), 35 Check: resource.ComposeTestCheckFunc( 36 resource.TestCheckResourceAttrSet("aws_ebs_snapshot.a", "id"), 37 resource.TestCheckResourceAttrSet("aws_ebs_snapshot.b", "id"), 38 ), 39 }, 40 { 41 Config: testAccDataSourceAwsEbsSnapshotIdsConfig_sorted2(uuid), 42 Check: resource.ComposeTestCheckFunc( 43 testAccCheckAwsEbsSnapshotDataSourceID("data.aws_ebs_snapshot_ids.test"), 44 resource.TestCheckResourceAttr("data.aws_ebs_snapshot_ids.test", "ids.#", "2"), 45 resource.TestCheckResourceAttrPair( 46 "data.aws_ebs_snapshot_ids.test", "ids.0", 47 "aws_ebs_snapshot.b", "id"), 48 resource.TestCheckResourceAttrPair( 49 "data.aws_ebs_snapshot_ids.test", "ids.1", 50 "aws_ebs_snapshot.a", "id"), 51 ), 52 }, 53 }, 54 }) 55 } 56 57 func TestAccDataSourceAwsEbsSnapshotIds_empty(t *testing.T) { 58 resource.Test(t, resource.TestCase{ 59 PreCheck: func() { testAccPreCheck(t) }, 60 Providers: testAccProviders, 61 Steps: []resource.TestStep{ 62 { 63 Config: testAccDataSourceAwsEbsSnapshotIdsConfig_empty, 64 Check: resource.ComposeTestCheckFunc( 65 testAccCheckAwsEbsSnapshotDataSourceID("data.aws_ebs_snapshot_ids.empty"), 66 resource.TestCheckResourceAttr("data.aws_ebs_snapshot_ids.empty", "ids.#", "0"), 67 ), 68 }, 69 }, 70 }) 71 } 72 73 const testAccDataSourceAwsEbsSnapshotIdsConfig_basic = ` 74 resource "aws_ebs_volume" "test" { 75 availability_zone = "us-west-2a" 76 size = 1 77 } 78 79 resource "aws_ebs_snapshot" "test" { 80 volume_id = "${aws_ebs_volume.test.id}" 81 } 82 83 data "aws_ebs_snapshot_ids" "test" { 84 owners = ["self"] 85 } 86 ` 87 88 func testAccDataSourceAwsEbsSnapshotIdsConfig_sorted1(uuid string) string { 89 return fmt.Sprintf(` 90 resource "aws_ebs_volume" "test" { 91 availability_zone = "us-west-2a" 92 size = 1 93 94 count = 2 95 } 96 97 resource "aws_ebs_snapshot" "a" { 98 volume_id = "${aws_ebs_volume.test.*.id[0]}" 99 description = "tf-test-%s" 100 } 101 102 resource "aws_ebs_snapshot" "b" { 103 volume_id = "${aws_ebs_volume.test.*.id[1]}" 104 description = "tf-test-%s" 105 106 // We want to ensure that 'aws_ebs_snapshot.a.creation_date' is less than 107 // 'aws_ebs_snapshot.b.creation_date'/ so that we can ensure that the 108 // snapshots are being sorted correctly. 109 depends_on = ["aws_ebs_snapshot.a"] 110 } 111 `, uuid, uuid) 112 } 113 114 func testAccDataSourceAwsEbsSnapshotIdsConfig_sorted2(uuid string) string { 115 return testAccDataSourceAwsEbsSnapshotIdsConfig_sorted1(uuid) + fmt.Sprintf(` 116 data "aws_ebs_snapshot_ids" "test" { 117 owners = ["self"] 118 119 filter { 120 name = "description" 121 values = ["tf-test-%s"] 122 } 123 } 124 `, uuid) 125 } 126 127 const testAccDataSourceAwsEbsSnapshotIdsConfig_empty = ` 128 data "aws_ebs_snapshot_ids" "empty" { 129 owners = ["000000000000"] 130 } 131 `