Skip to content

Commit 794322a

Browse files
committed
feat(cloud_sql): Add samples for SQL Server Advanced DR switchover
1 parent 864a2dd commit 794322a

File tree

6 files changed

+245
-0
lines changed

6 files changed

+245
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START cloud_sql_sqlserver_instance_create_dr_replica]
18+
resource "google_sql_database_instance" "original-primary" {
19+
name = "sqlserver-primary-instance-name"
20+
region = "us-east1"
21+
# Specify a database version that supports Cloud SQL Enterprise Plus edition.
22+
database_version = "SQLSERVER_2022_ENTERPRISE"
23+
instance_type = "CLOUD_SQL_INSTANCE"
24+
root_password = "INSERT-PASSWORD-HERE"
25+
replica_names = ["sqlserver-replica-instance-name"]
26+
settings {
27+
tier = "db-perf-optimized-N-2"
28+
edition = "ENTERPRISE_PLUS"
29+
backup_configuration {
30+
enabled = "true"
31+
}
32+
}
33+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
34+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
35+
deletion_protection = false
36+
}
37+
38+
resource "google_sql_database_instance" "dr_replica" {
39+
name = "sqlserver-replica-instance-name"
40+
# Specify the original primary instance as the master instance.
41+
master_instance_name = google_sql_database_instance.original-primary.name
42+
# DR replica must be in a different region than the region of the primary instance.
43+
region = "us-west2"
44+
# DR replica must be the same database version as the primary instance.
45+
database_version = "SQLSERVER_2022_ENTERPRISE"
46+
instance_type = "READ_REPLICA_INSTANCE"
47+
root_password = "INSERT-PASSWORD-HERE"
48+
replica_configuration {
49+
# Make the replica a cascadable replica.
50+
cascadable_replica = true
51+
}
52+
53+
settings {
54+
# DR replica must be in the same tier as your primary instance and support Enterprise Plus edition.
55+
tier = "db-perf-optimized-N-2"
56+
edition = "ENTERPRISE_PLUS"
57+
}
58+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
59+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
60+
deletion_protection = false
61+
}
62+
# [END cloud_sql_sqlserver_instance_create_dr_replica]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: sqlserver_instance_switchover_create_dr_replica
19+
spec:
20+
skip: true
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START cloud_sql_sqlserver_instance_switchover_switchover_begin]
18+
resource "google_sql_database_instance" "original-primary" {
19+
name = "sqlserver-primary-instance-name"
20+
region = "us-east1"
21+
database_version = "SQLSERVER_2022_ENTERPRISE"
22+
instance_type = "CLOUD_SQL_INSTANCE"
23+
root_password = "INSERT-PASSWORD-HERE"
24+
replica_names = ["sqlserver-replica-instance-name"]
25+
settings {
26+
tier = "db-perf-optimized-N-2"
27+
edition = "ENTERPRISE_PLUS"
28+
backup_configuration {
29+
enabled = "true"
30+
}
31+
}
32+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
33+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
34+
deletion_protection = false
35+
}
36+
37+
resource "google_sql_database_instance" "dr_replica" {
38+
name = "sqlserver-replica-instance-name"
39+
# Remove or comment out the master_instance_name
40+
# master_instance_name = google_sql_database_instance.original-primary.name
41+
region = "us-west2"
42+
database_version = "SQLSERVER_2022_ENTERPRISE"
43+
# Change the instance type from "READ_REPLICA_INSTANCE" to "CLOUD_SQL_INSTANCE".
44+
instance_type = "CLOUD_SQL_INSTANCE"
45+
root_password = "INSERT-PASSWORD-HERE"
46+
# Add the original primary to the replica_names list
47+
replica_names = ["sqlserver-primary-instance-name"]
48+
# Remove or comment out the replica_configuration section
49+
# replica_configuration {
50+
# cascadable_replica = true
51+
# }
52+
53+
settings {
54+
tier = "db-perf-optimized-N-2"
55+
edition = "ENTERPRISE_PLUS"
56+
}
57+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
58+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
59+
deletion_protection = false
60+
}
61+
# [END cloud_sql_sqlserver_instance_switchover_switchover_begin]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: sqlserver_instance_switchover_switchover_begin
19+
spec:
20+
skip: true
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START cloud_sql_sqlserver_instance_switchover_switchover_begin]
18+
resource "google_sql_database_instance" "original-primary" {
19+
name = "sqlserver-primary-instance-name"
20+
# Set master_instance_name to the new primary instance, the original DR replica.
21+
master_instance_name = "sqlserver-replica-instance-name"
22+
region = "us-east1"
23+
database_version = "SQLSERVER_2022_ENTERPRISE"
24+
# Change the instance type from "CLOUD_SQL_INSTANCE" to "READ_REPLICA_INSTANCE".
25+
instance_type = "READ_REPLICA_INSTANCE"
26+
root_password = "INSERT-PASSWORD-HERE"
27+
# Remove values from the replica_names field, but don't remove the field itself.
28+
replica_names = []
29+
# Add replica_configuration section and set cascadable_replica to true.
30+
replica_configuration {
31+
cascadable_replica = true
32+
}
33+
settings {
34+
tier = "db-perf-optimized-N-2"
35+
edition = "ENTERPRISE_PLUS"
36+
backup_configuration {
37+
enabled = "true"
38+
}
39+
}
40+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
41+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
42+
deletion_protection = false
43+
}
44+
45+
resource "google_sql_database_instance" "dr_replica" {
46+
name = "sqlserver-replica-instance-name"
47+
region = "us-west2"
48+
database_version = "SQLSERVER_2022_ENTERPRISE"
49+
# Change the instance type from "READ_REPLICA_INSTANCE" to "CLOUD_SQL_INSTANCE".
50+
instance_type = "CLOUD_SQL_INSTANCE"
51+
root_password = "INSERT-PASSWORD-HERE"
52+
# Add the original primary to the replica_names list
53+
replica_names = ["sqlserver-primary-instance-name"]
54+
settings {
55+
tier = "db-perf-optimized-N-2"
56+
edition = "ENTERPRISE_PLUS"
57+
}
58+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
59+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
60+
deletion_protection = false
61+
}
62+
# [END cloud_sql_sqlserver_instance_switchover_switchover_begin]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: sqlserver_instance_switchover_switchover_finish
19+
spec:
20+
skip: true

0 commit comments

Comments
 (0)