Skip to content

Commit 429f597

Browse files
update check for diff suppress (#5984) (#4261)
* update check for diff suppress * add tests * fix test resource name * import master instance too, just to verify * update cmek region Signed-off-by: Modular Magician <[email protected]>
1 parent 7c0970f commit 429f597

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

.changelog/5984.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
sql: fixed bug where `encryption_key_name` was not being propagated to the API.
3+
```

google-beta/resource_cgc_snippet_generated_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ resource "google_project_service_identity" "gcp_sa_cloud_sql" {
709709
710710
resource "google_kms_key_ring" "keyring" {
711711
name = "tf-test-keyring-name%{random_suffix}"
712-
location = "europe-north1"
712+
location = "us-central1"
713713
}
714714
715715
resource "google_kms_crypto_key" "key" {

google-beta/resource_sql_database_instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ var (
8484
)
8585

8686
func diffSuppressSqlReplicaKeyName(k, old, new string, d *schema.ResourceData) bool {
87-
if d.Get("replica_configuration") != nil {
87+
if d.Get("master_instance_name").(string) != "" {
8888
// This is a replica and the config value must be null, but the API will
8989
// return the key name of the master instance, so we'll suppress this diff
9090
return true

google-beta/resource_sql_database_instance_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,39 @@ func TestAccSqlDatabaseInstance_insights(t *testing.T) {
10271027
})
10281028
}
10291029

1030+
func TestAccSqlDatabaseInstance_encryptionKey(t *testing.T) {
1031+
t.Parallel()
1032+
1033+
context := map[string]interface{}{
1034+
"key_name": "tf-test-key-" + randString(t, 10),
1035+
"instance_name": "tf-test-sql-" + randString(t, 10),
1036+
}
1037+
1038+
vcrTest(t, resource.TestCase{
1039+
PreCheck: func() { testAccPreCheck(t) },
1040+
Providers: testAccProvidersOiCS,
1041+
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
1042+
Steps: []resource.TestStep{
1043+
{
1044+
Config: Nprintf(
1045+
testGoogleSqlDatabaseInstance_encryptionKey, context),
1046+
},
1047+
{
1048+
ResourceName: "google_sql_database_instance.replica",
1049+
ImportState: true,
1050+
ImportStateVerify: true,
1051+
ImportStateVerifyIgnore: []string{"deletion_protection"},
1052+
},
1053+
{
1054+
ResourceName: "google_sql_database_instance.master",
1055+
ImportState: true,
1056+
ImportStateVerify: true,
1057+
ImportStateVerifyIgnore: []string{"deletion_protection"},
1058+
},
1059+
},
1060+
})
1061+
}
1062+
10301063
var testGoogleSqlDatabaseInstance_basic2 = `
10311064
resource "google_sql_database_instance" "instance" {
10321065
region = "us-central1"
@@ -1662,6 +1695,70 @@ resource "google_sql_database_instance" "instance" {
16621695
}
16631696
}
16641697
`
1698+
var testGoogleSqlDatabaseInstance_encryptionKey = `
1699+
resource "google_project_service_identity" "gcp_sa_cloud_sql" {
1700+
provider = google-beta
1701+
service = "sqladmin.googleapis.com"
1702+
}
1703+
1704+
resource "google_kms_key_ring" "keyring" {
1705+
provider = google-beta
1706+
1707+
name = "%{key_name}"
1708+
location = "us-central1"
1709+
}
1710+
1711+
resource "google_kms_crypto_key" "key" {
1712+
provider = google-beta
1713+
1714+
name = "%{key_name}"
1715+
key_ring = google_kms_key_ring.keyring.id
1716+
}
1717+
1718+
resource "google_kms_crypto_key_iam_binding" "crypto_key" {
1719+
provider = google-beta
1720+
crypto_key_id = google_kms_crypto_key.key.id
1721+
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
1722+
1723+
members = [
1724+
"serviceAccount:${google_project_service_identity.gcp_sa_cloud_sql.email}",
1725+
]
1726+
}
1727+
1728+
resource "google_sql_database_instance" "master" {
1729+
provider = google-beta
1730+
name = "%{instance_name}-master"
1731+
database_version = "MYSQL_5_7"
1732+
region = "us-central1"
1733+
deletion_protection = false
1734+
encryption_key_name = google_kms_crypto_key.key.id
1735+
1736+
settings {
1737+
tier = "db-n1-standard-1"
1738+
1739+
backup_configuration {
1740+
enabled = true
1741+
start_time = "00:00"
1742+
binary_log_enabled = true
1743+
}
1744+
}
1745+
}
1746+
1747+
resource "google_sql_database_instance" "replica" {
1748+
provider = google-beta
1749+
name = "%{instance_name}-replica"
1750+
database_version = "MYSQL_5_7"
1751+
region = "us-central1"
1752+
master_instance_name = google_sql_database_instance.master.name
1753+
deletion_protection = false
1754+
1755+
settings {
1756+
tier = "db-n1-standard-1"
1757+
}
1758+
1759+
depends_on = [google_sql_database_instance.master]
1760+
}
1761+
`
16651762

16661763
func testGoogleSqlDatabaseInstance_PointInTimeRecoveryEnabled(masterID int, pointInTimeRecoveryEnabled bool) string {
16671764
return fmt.Sprintf(`

0 commit comments

Comments
 (0)