Skip to content

Commit 9be75af

Browse files
feat(backupdr): introducing associations attached with csql instances (#908)
* introducing associations attached with csql instances * introducing sql instance instantiation * end with new line * terraform fmt * adding csql backup_plan * terraform fmt * increasing hourly freq * adding test.yaml files for backupdr resources.
1 parent 7d450b4 commit 9be75af

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

backupdr/backup_plan/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ resource "google_backup_dr_backup_plan" "default" {
4848
backup_plan_id = "my-bp"
4949
resource_type = "compute.googleapis.com/Instance"
5050
backup_vault = google_backup_dr_backup_vault.default.name
51+
# log_retention_days = 2 # Only applicable for Cloud SQL
5152

5253
backup_rules {
5354
rule_id = "rule-1"

backupdr/backup_plan/test.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2023 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: backup_plan
19+
spec:
20+
skip: true

backupdr/backup_plan_association/main.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ resource "google_compute_disk" "default" {
5959
zone = "us-central1-a"
6060
}
6161

62+
resource "google_sql_database_instance" "default" {
63+
name = "instance-test"
64+
database_version = "MYSQL_8_0_41"
65+
region = "us-central1"
66+
settings {
67+
tier = "db-f1-micro"
68+
backup_configuration {
69+
enabled = true
70+
}
71+
}
72+
lifecycle {
73+
ignore_changes = [
74+
settings[0].backup_configuration[0].enabled,
75+
]
76+
}
77+
deletion_protection = false
78+
}
79+
6280
resource "google_backup_dr_backup_vault" "default" {
6381
provider = google-beta
6482
location = "us-central1"
@@ -129,6 +147,31 @@ resource "google_backup_dr_backup_plan" "disk_default" {
129147
}
130148
}
131149

150+
resource "google_backup_dr_backup_plan" "csql_default" {
151+
provider = google-beta
152+
location = "us-central1"
153+
backup_plan_id = "my-csql-bp"
154+
resource_type = "sqladmin.googleapis.com/Instance"
155+
backup_vault = google_backup_dr_backup_vault.default.name
156+
log_retention_days = 2
157+
158+
backup_rules {
159+
rule_id = "rule-1"
160+
backup_retention_days = 7
161+
162+
standard_schedule {
163+
recurrence_type = "HOURLY"
164+
hourly_frequency = 6
165+
time_zone = "UTC"
166+
167+
backup_window {
168+
start_hour_of_day = 0
169+
end_hour_of_day = 23
170+
}
171+
}
172+
}
173+
}
174+
132175
# [START backupdr_create_backupplanassociation]
133176

134177
# Before creating a backup plan association, you need to create backup plan (google_backup_dr_backup_plan)
@@ -158,3 +201,18 @@ resource "google_backup_dr_backup_plan_association" "disk_association" {
158201
}
159202

160203
# [END backupdr_create_backupplanassociation_disk]
204+
205+
# [START backupdr_create_backupplanassociation_csql]
206+
207+
# Before creating a backup plan association, you need to create backup plan (google_backup_dr_backup_plan)
208+
# and Cloud SQL Instance (google_sql_database_instance).
209+
resource "google_backup_dr_backup_plan_association" "csql_association" {
210+
provider = google-beta
211+
location = "us-central1"
212+
backup_plan_association_id = "my-csql-bpa"
213+
resource = "projects/${google_sql_database_instance.default.project}/instances/${google_sql_database_instance.default.name}"
214+
resource_type = "sqladmin.googleapis.com/Instance"
215+
backup_plan = google_backup_dr_backup_plan.csql_default.name
216+
}
217+
218+
# [END backupdr_create_backupplanassociation_csql]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2023 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: backup_plan_association
19+
spec:
20+
skip: true

backupdr/backup_vault/test.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2023 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: backup_vault
19+
spec:
20+
skip: true

0 commit comments

Comments
 (0)