From b413b78c735f0abf3eac4099eb4fd620a1bf288d Mon Sep 17 00:00:00 2001 From: niharika-98 Date: Thu, 10 Oct 2024 10:41:37 +0000 Subject: [PATCH 1/3] Adding Bp and BPA resources with examples to backupdr product --- mmv1/products/backupdr/BackupPlan.yaml | 224 ++++++++++++++++++ .../backupdr/BackupPlanAssociation.yaml | 137 +++++++++++ .../examples/backup_dr_backup_plan.tf.tmpl | 41 ++++ .../terraform/examples/backup_dr_bpa.tf.tmpl | 48 ++++ 4 files changed, 450 insertions(+) create mode 100644 mmv1/products/backupdr/BackupPlan.yaml create mode 100644 mmv1/products/backupdr/BackupPlanAssociation.yaml create mode 100644 mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl create mode 100644 mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl diff --git a/mmv1/products/backupdr/BackupPlan.yaml b/mmv1/products/backupdr/BackupPlan.yaml new file mode 100644 index 000000000000..befae1b010e4 --- /dev/null +++ b/mmv1/products/backupdr/BackupPlan.yaml @@ -0,0 +1,224 @@ +# Copyright 2023 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- !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}} +immutable: true +delete_url: projects/{{project}}/locations/{{location}}/backupPlans/{{backup_plan_id}} +description: A backup plan defines when and how to back up a resource, including the backup's schedule, retention, and location. +references: + guides: + 'Official Documentation': 'https://cloud.google.com/backup-disaster-recovery/docs' + api: 'https://cloud.google.com/backup-disaster-recovery/docs/reference/rest' +autogen_async: true +timeouts: + insert_minutes: 20 + delete_minutes: 20 +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 +parameters: + - name: 'location' + type: String + required: true + url_param_only: true + description: | + The location for the backup plan + - name: 'backup_plan_id' + type: String + required: true + url_param_only: true + description: |- + The ID of the backup plan +properties: + - name: 'name' + type: String + description: | + The name of backup plan resource created + output: true + - name: 'description' + type: String + description: | + The description allows for additional details about `BackupPlan` and its use cases to be provided. + - name: 'backupVault' + type: String + description: | + Backup vault where the backups gets stored using this Backup plan. + required: true + - name: 'backupVaultServiceAccount' + type: String + description: | + The Google Cloud Platform Service Account to be used by the BackupVault for taking backups. + output: true + - name: 'resourceType' + type: String + description: | + The resource type to which the `BackupPlan` will be applied. Examples include, "compute.googleapis.com/Instance" and "storage.googleapis.com/Bucket". + required: true + - name: 'createTime' + type: String + description: | + When the `BackupPlan` was created. + output: true + - name: 'updateTime' + type: String + description: | + When the `BackupPlan` was last updated. + output: true + - name: 'backupRules' + type: Array + description: | + The backup rules for this `BackupPlan`. There must be at least one `BackupRule` message. + required: true + item_type: + type: NestedObject + properties: + - name: 'ruleId' + type: String + description: The unique ID of this `BackupRule`. The `rule_id` is unique per `BackupPlan`. + required: true + - name: 'backupRetentionDays' + type: Integer + description: | + Configures the duration for which backup data will be kept. The value should be greater than or equal to minimum enforced retention of the backup vault. + required: true + - name: 'standardSchedule' + type: NestedObject + description: StandardSchedule defines a schedule that runs within the confines of a defined window of days. + required: true + properties: + - name: 'recurrenceType' + type: Enum + description: RecurrenceType enumerates the applicable periodicity for the schedule. + enum_values: + - HOURLY + - DAILY + - WEEKLY + - MONTHLY + - YEARLY + required: true + - name: 'hourlyFrequency' + type: Integer + description: | + Specifies frequency for hourly backups. An hourly frequency of 2 means jobs will run every 2 hours from start time till end time defined. + This is required for `recurrence_type`, `HOURLY` and is not applicable otherwise. + - name: 'daysOfWeek' + type: Array + description: 'Specifies days of week like MONDAY or TUESDAY, on which jobs will run. This is required for `recurrence_type`, `WEEKLY` and is not applicable otherwise.' + item_type: + type: Enum + name: 'DayOfWeekEnum' + description: 'Specifies day of week' + enum_values: + - DAY_OF_WEEK_UNSPECIFIED + - MONDAY + - TUESDAY + - WEDNESDAY + - THURSDAY + - FRIDAY + - SATURDAY + - name: 'daysOfMonth' + type: 'Array' + description: 'Specifies days of months like 1, 5, or 14 on which jobs will run.' + item_type: + type: Integer + - name: 'weekDayOfMonth' + type: NestedObject + description: 'Specifies a week day of the month like FIRST SUNDAY or LAST MONDAY, on which jobs will run.' + properties: + - name: 'weekOfMonth' + type: Enum + description: 'WeekOfMonth enumerates possible weeks in the month, e.g. the first, third, or last week of the month.' + enum_values: + - WEEK_OF_MONTH_UNSPECIFIED + - FIRST + - SECOND + - THIRD + - FOURTH + - LAST + required: true + - name: 'dayOfWeek' + type: Enum + description: 'Specifies the day of the week.' + enum_values: + - DAY_OF_WEEK_UNSPECIFIED + - MONDAY + - TUESDAY + - WEDNESDAY + - THURSDAY + - FRIDAY + - SATURDAY + - SUNDAY + required: true + - name: 'months' + type: Array + description: 'Specifies values of months' + item_type: + type: Enum + name: 'MonthEnum' + description: 'Specifies the months of the year, like `FEBRUARY` and/or `MAY`, on which jobs will run.' + enum_values: + - MONTH_UNSPECIFIED + - JANUARY + - FEBRUARY + - MARCH + - APRIL + - MAY + - JUNE + - JULY + - AUGUST + - SEPTEMBER + - OCTOBER + - NOVEMBER + - DECEMBER + - name: timeZone + type: String + description: The time zone to be used when interpreting the schedule. + required: true + - name: 'backupWindow' + type: NestedObject + description: | + A BackupWindow defines the window of the day during which backup jobs will run. Jobs are queued at the beginning of the window and will be marked as + `NOT_RUN` if they do not start by the end of the window. + properties: + - name: 'startHourOfDay' + type: Integer + description: | + The hour of the day (0-23) when the window starts, for example, if the value of the start hour of the day is 6, that means the backup window starts at 6:00. + required: true + - name: 'endHourOfDay' + type: Integer + description: | + The hour of the day (1-24) when the window ends, for example, if the value of end hour of the day is 10, that means the backup window end time is 10:00. + The end hour of the day should be greater than the start diff --git a/mmv1/products/backupdr/BackupPlanAssociation.yaml b/mmv1/products/backupdr/BackupPlanAssociation.yaml new file mode 100644 index 000000000000..7bfacf3cbe6b --- /dev/null +++ b/mmv1/products/backupdr/BackupPlanAssociation.yaml @@ -0,0 +1,137 @@ +# Copyright 2023 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# 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}} +self_link: projects/{{project}}/locations/{{location}}/backupPlanAssociations/{{backup_plan_association_id}} +immutable: true +delete_url: projects/{{project}}/locations/{{location}}/backupPlanAssociations/{{backup_plan_association_id}} +description: A Backup and DR BackupPlanAssociation. +references: + guides: + 'Official Documentation': 'https://cloud.google.com/backup-disaster-recovery/docs' + api: 'https://cloud.google.com/backup-disaster-recovery/docs/reference/rest' +autogen_async: true +timeouts: + insert_minutes: 20 + delete_minutes: 20 +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 +parameters: + - name: 'location' + type: String + required: true + url_param_only: true + description: | + The location for the backupplan association + - name: 'backup_plan_association_id' + type: String + required: true + url_param_only: true + description: |- + The id of backupplan association +properties: + - name: 'resource' + type: String + description: | + The resource for which BPA needs to be created + required: true + - name: 'name' + type: String + description: | + The name of backup plan association resource created + output: true + - name: 'backupPlan' + type: String + description: | + The BP with which resource needs to be created + required: true + - name: 'resourceType' + type: String + description: | + The resource type of workload on which backupplan is applied + output: true + - name: 'createTime' + type: String + description: | + The time when the instance was created + output: true + - name: 'updateTime' + type: String + description: | + The time when the instance was updated. + output: true + - name: 'dataSource' + type: String + description: | + Resource name of data source which will be used as storage location for backups taken + output: true + - name: 'rulesConfigInfo' + type: Array + description: | + Message for rules config info + item_type: + type: NestedObject + properties: + - name: 'ruleId' + type: String + description: Backup Rule id fetched from backup plan. + output: true + - name: 'lastBackupState' + type: Enum + description: State of last backup taken. + enum_values: + - :LAST_BACKUP_STATE_UNSPECIFIED + - :FIRST_BACKUP_PENDING + - :PERMISSION_DENIED + - :SUCCEEDED + - :FAILED + default_value: :LAST_BACKUP_STATE_UNSPECIFIED + - name: 'lastBackupError' + type: NestedObject + description: google.rpc.Status object to store the last backup error + output: true + properties: + - name: 'code' + type: String + description: The status code, which should be an enum value of [google.rpc.Code] + - name: 'message' + type: String + description: A developer-facing error message, which should be in English. + - name: 'lastSuccessfulBackupConsistencyTime' + type: String + description: The point in time when the last successful backup was captured from the source + output: true diff --git a/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl b/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl new file mode 100644 index 000000000000..7a50dbe6dcb1 --- /dev/null +++ b/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl @@ -0,0 +1,41 @@ +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'] %>" + description = "This is a second backup vault built by Terraform." + backup_minimum_enforced_retention_duration = "100000s" + labels = { + foo = "bar1" + bar = "baz1" + } + annotations = { + annotations1 = "bar1" + annotations2 = "baz1" + } + force_update = "true" + 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_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_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'] %>" + backup_window { + start_hour_of_day = "<%= ctx[:vars]['start_hour_of_day'] %>" + end_hour_of_day = "<%= ctx[:vars]['end_hour_of_day'] %>" + } + } + } +} diff --git a/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl b/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl new file mode 100644 index 000000000000..0c192a9e1e35 --- /dev/null +++ b/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl @@ -0,0 +1,48 @@ +resource "google_backup_dr_backup_vault" "bv1" { + provider = google-beta + project = "<%= ctx[:vars]['project'] %>" + location = "<%= ctx[:vars]['location'] %>" + backup_vault_id = "<%= ctx[:vars]['backup_vault_name'] %>" + description = "This is a second backup vault built by Terraform." + backup_minimum_enforced_retention_duration = "100000s" + labels = { + foo = "bar1" + bar = "baz1" + } + annotations = { + annotations1 = "bar1" + annotations2 = "baz1" + } + force_update = "true" + force_delete = "true" + allow_missing = "true" +} +resource "google_backup_dr_backup_plan" "bp1" { + provider = google-beta + project = "<%= ctx[:vars]['project'] %>" + location = "<%= ctx[:vars]['location'] %>" + name = "<%= ctx[:vars]['backup_plan_name'] %>" + 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'] %>" + standard_schedule { + recurrence_type = "<%= ctx[:vars]['recurrence_type'] %>" + hourly_frequency = "<%= ctx[:vars]['hourly_frequency'] %>" + time_zone = "<%= ctx[:vars]['time_zone'] %>" + backup_window { + start_hour_of_day = "<%= ctx[:vars]['start_hour_of_day'] %>" + end_hour_of_day = "<%= ctx[:vars]['end_hour_of_day'] %>" + } + } + } +} +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'] %>" + backup_plan = [ google_backup_dr_backup_plan.bp1.name ] +} From 142b5d08d5e4684e5099a49295a98cbbc85b82ef Mon Sep 17 00:00:00 2001 From: niharika-98 Date: Mon, 14 Oct 2024 10:32:26 +0000 Subject: [PATCH 2/3] FIxing comments on BP and BPA resource creation --- mmv1/products/backupdr/BackupPlan.yaml | 18 +-- .../backupdr/BackupPlanAssociation.yaml | 20 +-- .../examples/backup_dr_backup_plan.tf.tmpl | 149 ++++++++++++++++-- .../terraform/examples/backup_dr_bpa.tf.tmpl | 28 ++-- 4 files changed, 151 insertions(+), 64 deletions(-) diff --git a/mmv1/products/backupdr/BackupPlan.yaml b/mmv1/products/backupdr/BackupPlan.yaml index befae1b010e4..b1ba65c55b24 100644 --- a/mmv1/products/backupdr/BackupPlan.yaml +++ b/mmv1/products/backupdr/BackupPlan.yaml @@ -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}} @@ -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 diff --git a/mmv1/products/backupdr/BackupPlanAssociation.yaml b/mmv1/products/backupdr/BackupPlanAssociation.yaml index 7bfacf3cbe6b..903a9277c4ea 100644 --- a/mmv1/products/backupdr/BackupPlanAssociation.yaml +++ b/mmv1/products/backupdr/BackupPlanAssociation.yaml @@ -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}} @@ -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 diff --git a/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl b/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl index 7a50dbe6dcb1..ab6cea9c0de4 100644 --- a/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl +++ b/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl @@ -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'] %>" @@ -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 } } + } } } + diff --git a/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl b/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl index 0c192a9e1e35..ed683d4dceaf 100644 --- a/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl +++ b/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl @@ -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" @@ -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 ] } From cd9a3381dd7ff53ce73ed5ea3c48cce5b6a0b02b Mon Sep 17 00:00:00 2001 From: niharika-98 Date: Mon, 14 Oct 2024 14:03:50 +0000 Subject: [PATCH 3/3] Adding name to BPA --- mmv1/products/backupdr/BackupPlan.yaml | 1 - mmv1/products/backupdr/BackupPlanAssociation.yaml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mmv1/products/backupdr/BackupPlan.yaml b/mmv1/products/backupdr/BackupPlan.yaml index b1ba65c55b24..38f00255d866 100644 --- a/mmv1/products/backupdr/BackupPlan.yaml +++ b/mmv1/products/backupdr/BackupPlan.yaml @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. ---- !ruby/object:Api::Resource name: 'BackupPlan' base_url: projects/{{project}}/locations/{{location}}/backupPlans create_url: projects/{{project}}/locations/{{location}}/backupPlans/?backup_plan_id={{backup_plan_id}} diff --git a/mmv1/products/backupdr/BackupPlanAssociation.yaml b/mmv1/products/backupdr/BackupPlanAssociation.yaml index 903a9277c4ea..043b493ea83a 100644 --- a/mmv1/products/backupdr/BackupPlanAssociation.yaml +++ b/mmv1/products/backupdr/BackupPlanAssociation.yaml @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. ---- !ruby/object:Api::Resource +name: 'BackupPlanAssociation' 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}}