diff --git a/mmv1/products/backupdr/BackupPlan.yaml b/mmv1/products/backupdr/BackupPlan.yaml new file mode 100644 index 000000000000..38f00255d866 --- /dev/null +++ b/mmv1/products/backupdr/BackupPlan.yaml @@ -0,0 +1,209 @@ +# 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. + +name: 'BackupPlan' +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: 60 + delete_minutes: 60 +examples: + - min_version: beta + name: 'backup_dr_backup_plan' + primary_resource_id: 'my-backup-plan' + 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..043b493ea83a --- /dev/null +++ b/mmv1/products/backupdr/BackupPlanAssociation.yaml @@ -0,0 +1,121 @@ +# 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. + +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}} +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: 60 + delete_minutes: 60 +examples: + - min_version: beta + name: 'backup_dr_bpa' + primary_resource_id: 'my-backup-plan' + 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..ab6cea9c0de4 --- /dev/null +++ b/mmv1/templates/terraform/examples/backup_dr_backup_plan.tf.tmpl @@ -0,0 +1,160 @@ +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" { + 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[:vars]['primary_resource_id'] %>" { + location = "us-central1" + backup_plan_id = "bp-tf20" + resource_type = "compute.googleapis.com/Instance" + 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 + + standard_schedule { + 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 = 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 new file mode 100644 index 000000000000..ed683d4dceaf --- /dev/null +++ b/mmv1/templates/terraform/examples/backup_dr_bpa.tf.tmpl @@ -0,0 +1,46 @@ +resource "google_backup_dr_backup_vault" "bv1" { + provider = google-beta + project = "<%= ctx[:vars]['project'] %>" + 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" + 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 + location = "us-central1" + name = "bp1" + resource_type = "compute.googleapis.com/Instance" + backup_vault = [ google_backup_dr_backup_vault.bv1.name ] + backup_rules { + rule_id = "rule-1" + backup_retention_days = "10" + standard_schedule { + recurrence_type = "HOURLY + hourly_frequency = "8" + time_zone = UTC" + backup_window { + start_hour_of_day = "0" + end_hour_of_day = "24" + } + } + } +} +resource "google_backup_dr_backup_plan_association" "bpa1" { + provider = google-beta + location = "us-central1" + name = "bpa1" + resource = "projects/my-project/locations/us-central1/instances/{instance_id}" + backup_plan = [ google_backup_dr_backup_plan.bp1.name ] +}