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