Skip to content

Commit

Permalink
Backport Add cross-region replication support to AlloyDB
Browse files Browse the repository at this point in the history
Backport hashicorp/terraform-provider-google-beta#6474

To Create a Secondary Cluster, `cluster_type` and `secondary_config` are the additional fields to be mentioned in the cluster. The secondary cluster is dependent on the primary instance and the same needs to be added in the config using the `depends_on` field. The field continuous_backup_config.enabled needs to be set false as continuous backup is not supported for secondary clusters. The deletion_policy is set to FORCE as the secondary instance that will be created in the secondary cluster can not be deleted independently, but instead the entire secondary cluster needs to be deleted forcefully along with its secondary instance.

```
  cluster_type = "SECONDARY"
  deletion_policy = "FORCE"
  secondary_config {
    primary_cluster_name = <fully qualified primary cluster name>
    // Eg: primary_cluster_name = google_alloydb_cluster.<primary_cluster_name>.name
  }

  continuous_backup_config {
    enabled = false
  }

  depends_on = [google_alloydb_instance.<primary_instance_name>]
```

Part of [hashicorp/terraform-provider-google#13251](hashicorp/terraform-provider-google#13251)

**Release Note Template for Downstream PRs (will be copied)**

```
alloydb: added `cluster_type` and `secondary_config` fields to support secondary clusters in `google_alloydb_cluster` resource.
```

Derived from [GoogleCloudPlatform/magic-modules#9012](GoogleCloudPlatform/magic-modules#9012)
  • Loading branch information
cheftako committed Mar 25, 2024
1 parent 748a200 commit bb6e6f7
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ spec:
- startTimes
type: object
type: object
clusterType:
description: 'Immutable. The type of cluster. If not set, defaults
to PRIMARY. Default value: "PRIMARY" Possible values: ["PRIMARY",
"SECONDARY"].'
type: string
continuousBackupConfig:
description: |-
The continuous backup config for this cluster.
Expand Down Expand Up @@ -505,6 +510,19 @@ spec:
- clusterRef
- pointInTime
type: object
secondaryConfig:
description: Configuration of the secondary cluster for Cross Region
Replication. This should be set if and only if the cluster is of
type SECONDARY.
properties:
primaryClusterName:
description: |-
Immutable. Name of the primary cluster must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'.
type: string
required:
- primaryClusterName
type: object
required:
- location
- projectRef
Expand Down Expand Up @@ -796,6 +814,11 @@ spec:
- startTimes
type: object
type: object
clusterType:
description: 'Immutable. The type of cluster. If not set, defaults
to PRIMARY. Default value: "PRIMARY" Possible values: ["PRIMARY",
"SECONDARY"].'
type: string
continuousBackupConfig:
description: |-
The continuous backup config for this cluster.
Expand Down Expand Up @@ -1123,6 +1146,19 @@ spec:
- clusterRef
- pointInTime
type: object
secondaryConfig:
description: Configuration of the secondary cluster for Cross Region
Replication. This should be set if and only if the cluster is of
type SECONDARY.
properties:
primaryClusterName:
description: |-
Immutable. Name of the primary cluster must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'.
type: string
required:
- primaryClusterName
type: object
required:
- location
- projectRef
Expand Down
14 changes: 14 additions & 0 deletions pkg/clients/generated/apis/alloydb/v1beta1/alloydbcluster_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ automatedBackupPolicy:
minutes: integer
nanos: integer
seconds: integer
clusterType: string
continuousBackupConfig:
enabled: boolean
encryptionConfig:
Expand Down Expand Up @@ -149,6 +150,8 @@ restoreContinuousBackupSource:
name: string
namespace: string
pointInTime: string
secondaryConfig:
primaryClusterName: string
```
<table class="properties responsive">
Expand Down Expand Up @@ -393,6 +396,16 @@ A duration in seconds with up to nine fractional digits, terminated by 's'. Exam
<p>{% verbatim %}Seconds of minutes of the time. Currently, only the value 0 is supported.{% endverbatim %}</p>
</td>
</tr>
<tr>
<td>
<p><code>clusterType</code></p>
<p><i>Optional</i></p>
</td>
<td>
<p><code class="apitype">string</code></p>
<p>{% verbatim %}Immutable. The type of cluster. If not set, defaults to PRIMARY. Default value: "PRIMARY" Possible values: ["PRIMARY", "SECONDARY"].{% endverbatim %}</p>
</td>
</tr>
<tr>
<td>
<p><code>continuousBackupConfig</code></p>
Expand Down Expand Up @@ -892,6 +905,27 @@ projects/{project}/global/networks/{network_id}.{% endverbatim %}</p>
<p>{% verbatim %}Immutable. The point in time that this cluster is restored to, in RFC 3339 format.{% endverbatim %}</p>
</td>
</tr>
<tr>
<td>
<p><code>secondaryConfig</code></p>
<p><i>Optional</i></p>
</td>
<td>
<p><code class="apitype">object</code></p>
<p>{% verbatim %}Configuration of the secondary cluster for Cross Region Replication. This should be set if and only if the cluster is of type SECONDARY.{% endverbatim %}</p>
</td>
</tr>
<tr>
<td>
<p><code>secondaryConfig.primaryClusterName</code></p>
<p><i>Required*</i></p>
</td>
<td>
<p><code class="apitype">string</code></p>
<p>{% verbatim %}Immutable. Name of the primary cluster must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'.{% endverbatim %}</p>
</td>
</tr>
</tbody>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2012,3 +2012,29 @@ 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
}

0 comments on commit bb6e6f7

Please sign in to comment.