From edfb0773d79092b3fa3f8f7853376c1432c89788 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 10 Oct 2023 12:48:08 -0400 Subject: [PATCH] Add cross-region replication support to AlloyDB (#9012) (#1571) [upstream:79d5d56903e5ad2b38e9f855164132e5c53da8f6] Signed-off-by: Modular Magician --- .../services/alloydb/alloydb_cluster.go | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tfplan2cai/converters/google/resources/services/alloydb/alloydb_cluster.go b/tfplan2cai/converters/google/resources/services/alloydb/alloydb_cluster.go index 873daccf5..db806f388 100644 --- a/tfplan2cai/converters/google/resources/services/alloydb/alloydb_cluster.go +++ b/tfplan2cai/converters/google/resources/services/alloydb/alloydb_cluster.go @@ -114,6 +114,18 @@ func GetAlloydbClusterApiObject(d tpgresource.TerraformResourceData, config *tra } else if v, ok := d.GetOkExists("automated_backup_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(automatedBackupPolicyProp)) && (ok || !reflect.DeepEqual(v, automatedBackupPolicyProp)) { obj["automatedBackupPolicy"] = automatedBackupPolicyProp } + clusterTypeProp, err := expandAlloydbClusterClusterType(d.Get("cluster_type"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("cluster_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(clusterTypeProp)) && (ok || !reflect.DeepEqual(v, clusterTypeProp)) { + obj["clusterType"] = clusterTypeProp + } + secondaryConfigProp, err := expandAlloydbClusterSecondaryConfig(d.Get("secondary_config"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("secondary_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(secondaryConfigProp)) && (ok || !reflect.DeepEqual(v, secondaryConfigProp)) { + obj["secondaryConfig"] = secondaryConfigProp + } labelsProp, err := expandAlloydbClusterEffectiveLabels(d.Get("effective_labels"), d, config) if err != nil { return nil, err @@ -603,6 +615,33 @@ func expandAlloydbClusterAutomatedBackupPolicyEnabled(v interface{}, d tpgresour return v, nil } +func expandAlloydbClusterClusterType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandAlloydbClusterSecondaryConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedPrimaryClusterName, err := expandAlloydbClusterSecondaryConfigPrimaryClusterName(original["primary_cluster_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPrimaryClusterName); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["primaryClusterName"] = transformedPrimaryClusterName + } + + return transformed, nil +} + +func expandAlloydbClusterSecondaryConfigPrimaryClusterName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandAlloydbClusterEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { if v == nil { return map[string]string{}, nil