# Copyright 2024 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: 'InstantSnapshot'
api_variant_patterns:
  - 'projects/{project}/zones/{zone}/instantSnapshots/{instantSnapshot}'
kind: 'compute#instantSnapshot'
description: |
  Represents an instant snapshot resource.

  An instant snapshot is an in-place backup of a disk that can be used to rapidly create a new disk in minutes.

  Instant snapshots capture data at a specific point in time. They are optimized for rapidly restoring captured
  data to a new disk. Use instant snapshots to quickly recover data in cases where the zone and disk are still intact
  but the data on the disk has been lost or corrupted
references:
  guides:
    'Official Documentation': 'https://cloud.google.com/compute/docs/disks/instant-snapshots'
  api: 'https://cloud.google.com/compute/docs/reference/rest/v1/instantSnapshots'
docs:
base_url: 'projects/{{project}}/zones/{{zone}}/instantSnapshots'
has_self_link: true
immutable: true
timeouts:
  insert_minutes: 20
  update_minutes: 20
  delete_minutes: 20
async:
  actions: ['create', 'delete', 'update']
  type: 'OpAsync'
  operation:
    full_url: 'selfLink'
  result:
    resource_inside_response: false
collection_url_key: 'items'
iam_policy:
  parent_resource_attribute: 'name'
  example_config_body: 'templates/terraform/iam/iam_attributes.go.tmpl'
  iam_conditions_request_type: 'QUERY_PARAM'
  allowed_iam_role: 'roles/compute.storageAdmin'
  import_format:
    - 'projects/{{project}}/zones/{{zone}}/instantSnapshots/{{name}}'
sweeper:
  url_substitutions:
    - zone: "us-central1-a"
examples:
  - name: 'instant_snapshot_basic'
    primary_resource_id: 'default'
    primary_resource_name: 'fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])'
    vars:
      instance_name: 'instant-snapshot'
      disk_name: 'example-disk'
parameters:
  - name: 'sourceDisk'
    type: ResourceRef
    description: 'A reference to the disk used to create this instant snapshot.'
    required: true
    immutable: true
    diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
    custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
    resource: 'Disk'
    imports: 'name'
  - name: 'zone'
    type: ResourceRef
    description: 'A reference to the zone where the disk is located.'
    default_from_api: true
    required: false
    custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl'
    custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
    resource: 'Zone'
    imports: 'name'
properties:
  - name: 'creationTimestamp'
    type: Time
    description: 'Creation timestamp in RFC3339 text format.'
    output: true
  - name: 'name'
    type: String
    description: |
      Name of the resource; provided by the client when the resource is
      created. The name must be 1-63 characters long, and comply with
      RFC1035. Specifically, the name must be 1-63 characters long and match
      the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the
      first character must be a lowercase letter, and all following
      characters must be a dash, lowercase letter, or digit, except the last
      character, which cannot be a dash.
    required: true
    immutable: true
  - name: 'description'
    type: String
    description: 'An optional description of this resource.'
    required: false
  - name: 'sourceDiskId'
    type: String
    description: 'The ID value of the disk used to create this InstantSnapshot.'
    output: true
  - name: 'diskSizeGb'
    type: Integer
    description: 'Size of the snapshot, specified in GB.'
    output: true
  - name: 'labels'
    type: KeyValueLabels
    description: Labels to apply to this InstantSnapshot.
    update_url: 'projects/{{project}}/zones/{{zone}}/instantSnapshots/{{name}}/setLabels'
    update_verb: 'POST'
  - name: 'labelFingerprint'
    type: Fingerprint
    description: |
      The fingerprint used for optimistic locking of this resource. Used
      internally during updates.
    output: true
    update_url: 'projects/{{project}}/zones/{{zone}}/instantSnapshots/{{name}}/setLabels'
    update_verb: 'POST'
