|
| 1 | +package google |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 7 | +) |
| 8 | + |
| 9 | +func TestAccDataSourceSqlDatabase_basic(t *testing.T) { |
| 10 | + t.Parallel() |
| 11 | + |
| 12 | + context := map[string]interface{}{ |
| 13 | + "random_suffix": randString(t, 10), |
| 14 | + } |
| 15 | + |
| 16 | + vcrTest(t, resource.TestCase{ |
| 17 | + PreCheck: func() { testAccPreCheck(t) }, |
| 18 | + Providers: testAccProviders, |
| 19 | + CheckDestroy: testAccSqlDatabaseDestroyProducer(t), |
| 20 | + Steps: []resource.TestStep{ |
| 21 | + { |
| 22 | + Config: testAccDataSourceSqlDatabase_basic(context), |
| 23 | + Check: resource.ComposeTestCheckFunc( |
| 24 | + checkDataSourceStateMatchesResourceStateWithIgnores( |
| 25 | + "data.google_sql_database.qa", |
| 26 | + "google_sql_database.db", |
| 27 | + map[string]struct{}{ |
| 28 | + "deletion_policy": {}, |
| 29 | + }, |
| 30 | + ), |
| 31 | + ), |
| 32 | + }, |
| 33 | + }, |
| 34 | + }) |
| 35 | +} |
| 36 | + |
| 37 | +func testAccDataSourceSqlDatabase_basic(context map[string]interface{}) string { |
| 38 | + return Nprintf(` |
| 39 | +resource "google_sql_database_instance" "main" { |
| 40 | + name = "tf-test-instance-%{random_suffix}" |
| 41 | + database_version = "POSTGRES_14" |
| 42 | + region = "us-central1" |
| 43 | +
|
| 44 | + settings { |
| 45 | + tier = "db-f1-micro" |
| 46 | + } |
| 47 | +
|
| 48 | + deletion_protection = false |
| 49 | +} |
| 50 | +
|
| 51 | +resource "google_sql_database" "db" { |
| 52 | + name = "tf-test-db-%{random_suffix}" |
| 53 | + instance = google_sql_database_instance.main.name |
| 54 | + depends_on = [ |
| 55 | + google_sql_database_instance.main |
| 56 | + ] |
| 57 | +} |
| 58 | +
|
| 59 | +data "google_sql_database" "qa" { |
| 60 | + name = google_sql_database.db.name |
| 61 | + instance = google_sql_database_instance.main.name |
| 62 | + depends_on = [ |
| 63 | + google_sql_database.db |
| 64 | + ] |
| 65 | +} |
| 66 | +`, context) |
| 67 | +} |
0 commit comments