# Copyright 2025 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: 'RestoreChannel'
description: |
  A RestoreChannel imposes constraints on where backups can be restored.
  The RestoreChannel should be in the same project and region
  as the backups. The backups can only be restored in the
  destination_project.
references:
  guides:
    'Official Documentation': 'https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke'
  api: 'https://cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/reference/rest/v1/projects.locations.restoreChannels'
docs:
base_url: 'projects/{{project}}/locations/{{location}}/restoreChannels'
create_url: 'projects/{{project}}/locations/{{location}}/restoreChannels?restoreChannelId={{name}}'
update_verb: 'PATCH'
update_mask: true
timeouts:
  insert_minutes: 5
  update_minutes: 5
  delete_minutes: 5
autogen_async: true
async:
  actions: ['create', 'delete', 'update']
  type: 'OpAsync'
  operation:
    base_url: '{{op_id}}'
  result:
    resource_inside_response: true
custom_code:
examples:
  - name: 'gkebackup_restorechannel_basic'
    primary_resource_id: 'basic'
    primary_resource_name: 'fmt.Sprintf("tf-test-basic-channel%s", context["random_suffix"])'
    vars:
      name: 'basic-channel'
      destination_project: 'projects/24240755850'
    test_vars_overrides:
      'destination_project': '"projects/24240755850"'
    test_env_vars:
      project: 'PROJECT_NAME'
parameters:
  - name: 'location'
    type: String
    description: |
      The region of the Restore Channel.
    url_param_only: true
    required: true
    immutable: true
properties:
  - name: 'name'
    type: String
    description: |
      The full name of the RestoreChannel Resource.
    required: true
    immutable: true
    custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl'
    custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.tmpl'
  - name: 'uid'
    type: String
    description: |
      Server generated, unique identifier of UUID format.
    output: true
  - name: 'destinationProject'
    type: String
    description: |
      The project where Backups will be restored.
      The format is `projects/{project}`.
      {project} can only be a project number.
    required: true
    immutable: true
  - name: 'description'
    type: String
    description: |
      User specified descriptive string for this RestoreChannel.
  - name: 'labels'
    type: KeyValueLabels
    description: |
      Description: A set of custom labels supplied by the user.
      A list of key->value pairs.
      Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
  - name: 'etag'
    type: String
    description: |
      etag is used for optimistic concurrency control as a way to help prevent simultaneous
      updates of a restore channel from overwriting each other. It is strongly suggested that
      systems make use of the 'etag' in the read-modify-write cycle to perform RestoreChannel updates
      in order to avoid race conditions: An etag is returned in the response to restoreChannels.get,
      and systems are expected to put that etag in the request to restoreChannels.patch or
      restoreChannels.delete to ensure that their change will be applied to the same version of the resource.
    output: true
  - name: 'destinationProjectId'
    type: String
    description: |
      The project_id where Backups will be restored.
      Example Project ID: "my-project-id".
    output: true
