Skip to content

Commit 8a31066

Browse files
coderGo93Edgar López
andauthored
INTMDB-181: Detects unnecessary changes changes for azure/gcp encryption at rest (#412)
* fix: deleted some parameters what will be empty in response * fix: set project id in read Co-authored-by: Edgar López <[email protected]>
1 parent 98097d2 commit 8a31066

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

mongodbatlas/resource_mongodbatlas_encryption_at_rest.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,40 @@ func resourceMongoDBAtlasEncryptionAtRestRead(d *schema.ResourceData, meta inter
223223

224224
values = flattenAzureVault(&resp.AzureKeyVault)
225225
if !counterEmptyValues(values) {
226+
azure, azureOk := d.GetOk("azure_key_vault")
227+
if azureOk {
228+
azure2 := azure.(map[string]interface{})
229+
values["secret"] = cast.ToString(azure2["secret"])
230+
if v, sa := values["secret"]; sa {
231+
if v.(string) == "" {
232+
delete(values, "secret")
233+
}
234+
}
235+
}
226236
if err = d.Set("azure_key_vault", values); err != nil {
227237
return fmt.Errorf(errorAlertEncryptionAtRestSetting, "azure_key_vault", d.Id(), err)
228238
}
229239
}
230240

231241
values = flattenGCPKms(&resp.GoogleCloudKms)
232242
if !counterEmptyValues(values) {
243+
gcp, gcpOk := d.GetOk("google_cloud_kms")
244+
if gcpOk {
245+
gcp2 := gcp.(map[string]interface{})
246+
values["service_account_key"] = cast.ToString(gcp2["service_account_key"])
247+
if v, sa := values["service_account_key"]; sa {
248+
if v.(string) == "" {
249+
delete(values, "service_account_key")
250+
}
251+
}
252+
}
233253
if err = d.Set("google_cloud_kms", values); err != nil {
234254
return fmt.Errorf(errorAlertEncryptionAtRestSetting, "google_cloud_kms", d.Id(), err)
235255
}
236256
}
257+
if err = d.Set("project_id", d.Id()); err != nil {
258+
return fmt.Errorf(errorAlertEncryptionAtRestSetting, "project_id", d.Id(), err)
259+
}
237260

238261
return nil
239262
}

0 commit comments

Comments
 (0)