Skip to content

Commit

Permalink
FIxing comments on BP and BPA resource creation
Browse files Browse the repository at this point in the history
  • Loading branch information
niharika-98 committed Oct 14, 2024
1 parent b413b78 commit 142b5d0
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 64 deletions.
18 changes: 2 additions & 16 deletions mmv1/products/backupdr/BackupPlan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

--- !ruby/object:Api::Resource
name: 'BackupPlan'
# Remove this towards GA. b/371938375
min_version: beta
base_url: projects/{{project}}/locations/{{location}}/backupPlans
create_url: projects/{{project}}/locations/{{location}}/backupPlans/?backup_plan_id={{backup_plan_id}}
self_link: projects/{{project}}/locations/{{location}}/backupPlans/{{backup_plan_id}}
Expand All @@ -27,24 +25,12 @@ references:
api: 'https://cloud.google.com/backup-disaster-recovery/docs/reference/rest'
autogen_async: true
timeouts:
insert_minutes: 20
delete_minutes: 20
insert_minutes: 60
delete_minutes: 60
examples:
- min_version: beta
name: 'backup_dr_backup_plan'
primary_resource_id: 'my-backup-plan'
vars:
project: 'my-project'
location: 'us-central1'
backup_vault_name: 'bv1'
backup_plan_name: 'my-backup-plan'
backup_rule_name: 'rule-1'
backup_retention_days: 5
recurrence_type: 'HOURLY'
hourly_frequency: 6
time_zone: "UTC"
start_hour_of_day: 5
end_hour_of_day: 20
test_env_vars:
project: :PROJECT_NAME
exclude_test: true
Expand Down
20 changes: 2 additions & 18 deletions mmv1/products/backupdr/BackupPlanAssociation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# limitations under the License.

--- !ruby/object:Api::Resource
name: 'BackupPlanAssociation'
# Remove this towards GA. b/371938375
min_version: beta
base_url: projects/{{project}}/locations/{{location}}/backupPlanAssociations
create_url: projects/{{project}}/locations/{{location}}/backupPlanAssociations/?backup_plan_association_id={{backup_plan_association_id}}
Expand All @@ -27,26 +25,12 @@ references:
api: 'https://cloud.google.com/backup-disaster-recovery/docs/reference/rest'
autogen_async: true
timeouts:
insert_minutes: 20
delete_minutes: 20
insert_minutes: 60
delete_minutes: 60
examples:
- min_version: beta
name: 'backup_dr_bpa'
primary_resource_id: 'my-backup-plan'
vars:
project: 'my-project'
location: 'us-central1'
backup_vault_name: 'bv1'
backup_plan_name: 'my-backup-plan'
backup_rule_name: 'rule-1'
backup_retention_days: 5
recurrence_type: 'HOURLY'
hourly_frequency: 6
time_zone: "UTC"
start_hour_of_day: 5
end_hour_of_day: 20
backup_plan_association_name: 'bpa1'
resource_name: 'projects/gcp-project/locations/us-central1/{instance_id}'
test_env_vars:
project: :PROJECT_NAME
exclude_test: true
Expand Down
149 changes: 134 additions & 15 deletions mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
variable "backup_rules" {
type = list(object({
rule_id = string
backup_retention_days = number
recurrence_type = string
frequency = number
time_zone = string
start_hour_of_day = number
end_hour_of_day = number
days_of_week = list(string) # Optional for WEEKLY
days_of_month = list(number) # Optional for MONTHLY
week_day_of_month = object({ # Optional for MONTHLY
week_of_month = string
day_of_week = string
})
months = list(string) # Optional for YEARLY
}))
}
default = [
{
rule_id = "rule-1"
backup_retention_days = 5
recurrence_type = "HOURLY"
frequency = 6
time_zone = "UTC"
start_hour_of_day = 0
end_hour_of_day = 24
days_of_week = []
days_of_month = []
week_day_of_month = {
week_of_month = ""
day_of_week = ""
}
months = []
},
{
rule_id = "rule-2"
backup_retention_days = 10
recurrence_type = "DAILY"
frequency = 1
time_zone = "UTC"
start_hour_of_day = 0
end_hour_of_day = 24
days_of_week = []
days_of_month = []
week_day_of_month = {
week_of_month = ""
day_of_week = ""
}
months = []
},
{
rule_id = "rule-3"
backup_retention_days = 15
recurrence_type = "WEEKLY"
frequency = 1
time_zone = "UTC"
start_hour_of_day = 0
end_hour_of_day = 24
days_of_week = ["MONDAY", "WEDNESDAY", "FRIDAY"]
days_of_month = []
week_day_of_month = {
week_of_month = ""
day_of_week = ""
}
months = []
},
{
rule_id = "rule-4"
backup_retention_days = 20
recurrence_type = "MONTHLY"
frequency = 1
time_zone = "UTC"
start_hour_of_day = 0
end_hour_of_day = 24
days_of_week = []
days_of_month = [1, 15, 30]
week_day_of_month = {
week_of_month = "FIRST"
day_of_week = "SUNDAY"
}
months = []
},
{
rule_id = "rule-5"
backup_retention_days = 30
recurrence_type = "YEARLY"
frequency = 1
time_zone = "UTC"
start_hour_of_day = 0
end_hour_of_day = 24
days_of_week = []
days_of_month = []
week_day_of_month = {
week_of_month = "FIRST"
day_of_week = "SUNDAY"
}
months = ["JANUARY", "DECEMBER"]
}
]

resource "google_backup_dr_backup_vault" "my-backup-vault" {
provider = google-beta
project = "<%= ctx[:vars]['project'] %>"
location = "<%= ctx[:vars]['location'] %>"
backup_vault_id = "<%= ctx[:vars]['backup_vault_name'] %>"
Expand All @@ -17,25 +117,44 @@ resource "google_backup_dr_backup_vault" "my-backup-vault" {
force_delete = "true"
allow_missing = "true"
}
resource "google_backup_dr_backup_plan" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
project = "<%= ctx[:vars]['project'] %>"
location = "<%= ctx[:vars]['location'] %>"
name = "<%= ctx[:vars]['backup_plan_name'] %>"

resource "google_backup_dr_backup_plan" "<%= ctx[:vars]['primary_resource_id'] %>" {
location = "us-central1"
backup_plan_id = "bp-tf20"
resource_type = "compute.googleapis.com/Instance"
backup_vault = [google_backup_dr_backup_vault.my-backup-vault.name]
backup_rules {
rule_id = "<%= ctx[:vars]['backup_rule_name'] %>"
backup_vault = "projects/nkuravi-consumer-billing-test/locations/us-central1/backupVaults/bv1"

dynamic "backup_rules" {
for_each = var.backup_rules
content {
rule_id = backup_rules.value.rule_id
backup_retention_days = backup_rules.value.backup_retention_days

backup_retention_days = "<%= ctx[:vars]['backup_retention_days'] %>"
standard_schedule {
recurrence_type = "<%= ctx[:vars]['recurrence_type'] %>"
hourly_frequency = "<%= ctx[:vars]['hourly_frequency'] %>"
time_zone = "<%= ctx[:vars]['time_zone'] %>"
recurrence_type = backup_rules.value.recurrence_type

hourly_frequency = backup_rules.value.recurrence_type == "HOURLY" ? backup_rules.value.frequency : null
days_of_week = backup_rules.value.recurrence_type == "WEEKLY" ? backup_rules.value.days_of_week : []
days_of_month = backup_rules.value.recurrence_type == "MONTHLY" ? backup_rules.value.days_of_month : []
months = backup_rules.value.recurrence_type == "YEARLY" ? backup_rules.value.months : []

# Conditionally include week_day_of_month block
dynamic "week_day_of_month" {
for_each = backup_rules.value.recurrence_type == "YEARLY" ? [1] : []
content {
week_of_month = backup_rules.value.week_day_of_month.week_of_month
day_of_week = backup_rules.value.week_day_of_month.day_of_week
}
}

time_zone = backup_rules.value.time_zone

backup_window {
start_hour_of_day = "<%= ctx[:vars]['start_hour_of_day'] %>"
end_hour_of_day = "<%= ctx[:vars]['end_hour_of_day'] %>"
start_hour_of_day = backup_rules.value.start_hour_of_day
end_hour_of_day = backup_rules.value.end_hour_of_day
}
}
}
}
}

28 changes: 13 additions & 15 deletions mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "google_backup_dr_backup_vault" "bv1" {
provider = google-beta
project = "<%= ctx[:vars]['project'] %>"
location = "<%= ctx[:vars]['location'] %>"
location = "us-central1"
backup_vault_id = "<%= ctx[:vars]['backup_vault_name'] %>"
description = "This is a second backup vault built by Terraform."
backup_minimum_enforced_retention_duration = "100000s"
Expand All @@ -19,30 +19,28 @@ resource "google_backup_dr_backup_vault" "bv1" {
}
resource "google_backup_dr_backup_plan" "bp1" {
provider = google-beta
project = "<%= ctx[:vars]['project'] %>"
location = "<%= ctx[:vars]['location'] %>"
name = "<%= ctx[:vars]['backup_plan_name'] %>"
location = "us-central1"
name = "bp1"
resource_type = "compute.googleapis.com/Instance"
backup_vault = [ google_backup_dr_backup_vault.bv1.name ]
backup_rules {
rule_id = "<%= ctx[:vars]['backup_rule_name'] %>"
backup_retention_days = "<%= ctx[:vars]['backup_retention_days'] %>"
rule_id = "rule-1"
backup_retention_days = "10"
standard_schedule {
recurrence_type = "<%= ctx[:vars]['recurrence_type'] %>"
hourly_frequency = "<%= ctx[:vars]['hourly_frequency'] %>"
time_zone = "<%= ctx[:vars]['time_zone'] %>"
recurrence_type = "HOURLY
hourly_frequency = "8"
time_zone = UTC"
backup_window {
start_hour_of_day = "<%= ctx[:vars]['start_hour_of_day'] %>"
end_hour_of_day = "<%= ctx[:vars]['end_hour_of_day'] %>"
start_hour_of_day = "0"
end_hour_of_day = "24"
}
}
}
}
resource "google_backup_dr_backup_plan_association" "bpa1" {
provider = google-beta
project = "<%= ctx[:vars]['project'] %>"
location = "<%= ctx[:vars]['location'] %>"
name = "<%= ctx[:vars]['backup_plan_association_name'] %>"
resource = "<%= ctx[:vars]['resource_name'] %>"
location = "us-central1"
name = "bpa1"
resource = "projects/my-project/locations/us-central1/instances/{instance_id}"
backup_plan = [ google_backup_dr_backup_plan.bp1.name ]
}

0 comments on commit 142b5d0

Please sign in to comment.