Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cross-region replication support to AlloyDB #9012

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d787493
Add fields for secondary cluster and create basic example
199201shubhamsahu Sep 28, 2023
9c8ea97
Add custom pre create code to support creation of secondary cluster
199201shubhamsahu Sep 28, 2023
ba25c9d
Add basic tests and validation tests for secondary cluster
199201shubhamsahu Sep 28, 2023
0012c50
Add forceful deletion for secondary cluster
199201shubhamsahu Sep 28, 2023
f26c8b6
Specify clusterType=PRIMARY in examples as clusterType is a new requi…
199201shubhamsahu Sep 28, 2023
d28e93d
Add implementation for promotion of secondary cluster
199201shubhamsahu Sep 28, 2023
101cc52
Add cluster_type for tests
199201shubhamsahu Sep 28, 2023
09354d6
Add required field cluster_type for remaining tests
199201shubhamsahu Sep 28, 2023
aee6a5e
Fix tests for secondary cluster
199201shubhamsahu Sep 28, 2023
7dd152c
Comment out tests failing due to service networking issue
199201shubhamsahu Sep 28, 2023
fcefb0e
Fix cluster_type for secondary cluster test
199201shubhamsahu Sep 28, 2023
3b87a2f
Remove required:true for clusterType and set PRIMARY as default
199201shubhamsahu Sep 28, 2023
2b2df2b
Merge branch 'main' into alloydb-crr-support
199201shubhamsahu Sep 28, 2023
2d37627
Add validation and tests for basic user journeys
199201shubhamsahu Sep 29, 2023
613cc03
Update timeouts to 30 mins, reason: multiple failing tests
199201shubhamsahu Oct 2, 2023
5966f2f
Add field for secondary instance and create basic example
199201shubhamsahu Oct 3, 2023
dbb8330
Add custom pre create/update/delete code to support implementation of…
199201shubhamsahu Oct 3, 2023
4465e8b
Add tests for secondary instance
199201shubhamsahu Oct 3, 2023
6316c8c
Add test for secondary cluster promotion
199201shubhamsahu Oct 3, 2023
017d7fb
Remove legacy fmt.Printf() for warning message
199201shubhamsahu Oct 4, 2023
9c42b06
Enable generated test for secondary instance
199201shubhamsahu Oct 5, 2023
25fa414
Correct description for READ_POOL instance_type
199201shubhamsahu Oct 5, 2023
fb7688a
Merge branch 'main' into alloydb-crr-support
199201shubhamsahu Oct 5, 2023
7a7e453
Fix changes in merge resolve
199201shubhamsahu Oct 5, 2023
f809fa3
Minor: Remove spacing and unncessary comments
199201shubhamsahu Oct 5, 2023
d715a0f
Remove explicit dependency on secondary cluster from description as i…
199201shubhamsahu Oct 5, 2023
33b17f6
Remove cluster_type=PRIMARY as it is already the default value
199201shubhamsahu Oct 5, 2023
4fe8f4c
Set secondary_config.primary_cluster_names as required
199201shubhamsahu Oct 5, 2023
dbf1fdd
Remove dead code
199201shubhamsahu Oct 5, 2023
48af6b1
Fix secondary cluster basic example
199201shubhamsahu Oct 6, 2023
d733675
Fix secondary instance basic example
199201shubhamsahu Oct 6, 2023
0847d2b
Remove inital user from secondary cluster example
199201shubhamsahu Oct 9, 2023
118019b
Fix and add tests for secondary cluster
199201shubhamsahu Oct 9, 2023
afdeb16
Add deletion policy to forcefully delete the secondary cluster and th…
199201shubhamsahu Oct 9, 2023
e8e2270
Add deletion_policy to secondary instance basic example and remove in…
199201shubhamsahu Oct 9, 2023
311fff5
Fix basic tests for secondary instance
199201shubhamsahu Oct 9, 2023
43c42af
Remove changes for secondary instance and promotion, for PR to only h…
199201shubhamsahu Oct 9, 2023
276a343
Add deletion_policy = FORCE for secondary clusters
199201shubhamsahu Oct 9, 2023
66a0a68
Revert "Add deletion_policy = FORCE for secondary clusters"
199201shubhamsahu Oct 9, 2023
5278034
Remove deletion_policy, will be adding implementation and tests in se…
199201shubhamsahu Oct 9, 2023
14f82bc
Merge branch 'GoogleCloudPlatform:main' into alloydb-crr-support
199201shubhamsahu Oct 9, 2023
e6da0eb
Remove client_connection_config as it got rolled back
199201shubhamsahu Oct 9, 2023
70dcd5e
Add ImportStateVerifyIgnore to secondary cluster tests
199201shubhamsahu Oct 9, 2023
ef48b6b
Set cluster_type as immutable and remove cluster_type update validation
199201shubhamsahu Oct 9, 2023
89889d2
Remove cluster_type = PRIMARY as it is default value
199201shubhamsahu Oct 9, 2023
559ce22
Set secondaryConfig.primaryClusterName as immutable
199201shubhamsahu Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions mmv1/products/alloydb/Cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ async: !ruby/object:Api::OpAsync
base_url: '{{op_id}}'
wait_ms: 1000
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 10
update_minutes: 10
delete_minutes: 10
insert_minutes: 30
update_minutes: 30
delete_minutes: 30
result: !ruby/object:Api::OpAsync::Result
path: 'response'
status: !ruby/object:Api::OpAsync::Status
Expand Down Expand Up @@ -78,8 +78,15 @@ examples:
ignore_read_extra:
- 'reconciling'
- 'update_time'
- !ruby/object:Provider::Terraform::Examples
name: 'alloydb_secondary_cluster_basic'
primary_resource_id: 'secondary'
vars:
alloydb_primary_cluster_name: 'alloydb-primary-cluster'
alloydb_primary_instance_name: 'alloydb-primary-instance'
alloydb_secondary_cluster_name: 'alloydb-secondary-cluster'
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_create: templates/terraform/pre_create/alloydb_restore_cluster.go.erb
pre_create: templates/terraform/pre_create/alloydb_cluster.go.erb
parameters:
- !ruby/object:Api::Type::String
name: 'clusterId'
Expand Down Expand Up @@ -452,3 +459,24 @@ properties:
- !ruby/object:Api::Type::String
name: 'sourceType'
description: 'Type of migration source.'
- !ruby/object:Api::Type::Enum
199201shubhamsahu marked this conversation as resolved.
Show resolved Hide resolved
name: clusterType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: clusterType
name: clusterType # this field is output-only in the API, but used to determine creation method in Terraform

values:
- :PRIMARY
- :SECONDARY
default_value: :PRIMARY
199201shubhamsahu marked this conversation as resolved.
Show resolved Hide resolved
immutable: true
description: |
The type of cluster. If not set, defaults to PRIMARY.
- !ruby/object:Api::Type::NestedObject
name: "secondaryConfig"
199201shubhamsahu marked this conversation as resolved.
Show resolved Hide resolved
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:
- !ruby/object:Api::Type::String
name: "primaryClusterName"
199201shubhamsahu marked this conversation as resolved.
Show resolved Hide resolved
immutable: true
required: true
199201shubhamsahu marked this conversation as resolved.
Show resolved Hide resolved
description: |
Name of the primary cluster must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
resource "google_alloydb_cluster" "primary" {
cluster_id = "<%= ctx[:vars]['alloydb_primary_cluster_name'] %>"
location = "us-central1"
network = google_compute_network.default.id
}

resource "google_alloydb_instance" "primary" {
cluster = google_alloydb_cluster.primary.name
instance_id = "<%= ctx[:vars]['alloydb_primary_instance_name'] %>"
instance_type = "PRIMARY"

machine_config {
cpu_count = 2
}

depends_on = [google_service_networking_connection.vpc_connection]
}

resource "google_alloydb_cluster" "<%= ctx[:primary_resource_id] %>" {
cluster_id = "<%= ctx[:vars]['alloydb_secondary_cluster_name'] %>"
location = "us-east1"
network = google_compute_network.default.id
cluster_type = "SECONDARY"

continuous_backup_config {
enabled = false
}

secondary_config {
primary_cluster_name = google_alloydb_cluster.primary.name
}

depends_on = [google_alloydb_instance.primary]
}

data "google_project" "project" {}

resource "google_compute_network" "default" {
name = "<%= ctx[:vars]['alloydb_secondary_cluster_name'] %>"
}

resource "google_compute_global_address" "private_ip_alloc" {
name = "<%= ctx[:vars]['alloydb_secondary_cluster_name'] %>"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}

resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,36 @@ if backupSource != nil || continuousBackupSource != nil {
}
restoreClusterRequestBody["cluster"] = cluster
obj = restoreClusterRequestBody
}
}


// Read the secondary cluster config to call the api for creating secondary cluster

var secondaryConfig interface{}
var clusterType interface{}

if val, ok := obj["secondaryConfig"]; ok {
secondaryConfig = val
}

if val, ok := obj["clusterType"]; ok {
rileykarson marked this conversation as resolved.
Show resolved Hide resolved
clusterType = val
}

if clusterType == "SECONDARY" {
if secondaryConfig != nil {
199201shubhamsahu marked this conversation as resolved.
Show resolved Hide resolved
// Use createsecondary API if this is a secondary cluster
url = strings.Replace(url, "clusters?clusterId", "clusters:createsecondary?cluster_id", 1)

// Validation error if secondary_config is not defined
} else {
return fmt.Errorf("Error creating cluster. Can not create secondary cluster without secondary_config field.")
}
}

// Validation error if secondary_config is defined but, cluster type is not secondary
199201shubhamsahu marked this conversation as resolved.
Show resolved Hide resolved
if secondaryConfig != nil {
if clusterType != "SECONDARY" {
return fmt.Errorf("Error creating cluster. Add {cluster_type: \"SECONDARY\"} if attempting to create a secondary cluster, otherwise remove the secondary_config.")
}
}
Loading