# 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: 'ParameterVersion'
description: |
  A Parameter Version resource that stores the actual value of the parameter.
references:
  guides:
  api: 'https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions'
docs:
base_url: '{{parameter}}/versions'
self_link: '{{parameter}}/versions/{{parameter_version_id}}'
create_url: '{{parameter}}/versions?parameter_version_id={{parameter_version_id}}'
update_verb: 'PATCH'
update_mask: true
import_format:
  - 'projects/{{%project}}/locations/global/parameters/{{%parameter_id}}/versions/{{%parameter_version_id}}'
timeouts:
  insert_minutes: 20
  update_minutes: 20
  delete_minutes: 20
examples:
  - name: 'parameter_version_basic'
    primary_resource_id: 'parameter-version-basic'
    vars:
      parameter_id: 'parameter'
      parameter_version_id: 'parameter_version'
  - name: 'parameter_version_with_json_format'
    primary_resource_id: 'parameter-version-with-json-format'
    vars:
      parameter_id: 'parameter'
      parameter_version_id: 'parameter_version'
  - name: 'parameter_version_with_kms_key'
    primary_resource_id: 'parameter-version-with-kms-key'
    vars:
      parameter_id: 'parameter'
      parameter_version_id: 'parameter_version'
      kms_key: 'kms-key'
    test_vars_overrides:
      'kms_key': 'acctest.BootstrapKMSKey(t).CryptoKey.Name'
    bootstrap_iam:
      - member: "serviceAccount:service-{project_number}@gcp-sa-pm.iam.gserviceaccount.com"
        role: "roles/cloudkms.cryptoKeyEncrypterDecrypter"
  - name: 'parameter_version_with_yaml_format'
    primary_resource_id: 'parameter-version-with-yaml-format'
    vars:
      parameter_id: 'parameter'
      parameter_version_id: 'parameter_version'
custom_code:
  custom_import: 'templates/terraform/custom_import/parameter_manager_parameter_version.go.tmpl'
parameters:
  - name: 'parameter'
    type: ResourceRef
    description: |
      Parameter Manager Parameter resource.
    url_param_only: true
    required: true
    immutable: true
    resource: 'Parameter'
    imports: 'name'
  - name: 'parameter_version_id'
    type: String
    description: |
      Version ID of the Parameter Version Resource. This must be unique within the Parameter.
    url_param_only: true
    required: true
    immutable: true
properties:
  - name: 'name'
    type: String
    description: |
      The resource name of the Parameter Version. Format:
      `projects/{{project}}/locations/global/parameters/{{parameter_id}}/versions/{{parameter_version_id}}`
    output: true
  - name: 'createTime'
    type: String
    description: |
      The time at which the Parameter Version was created.
    output: true
  - name: 'updateTime'
    type: String
    description: |
      The time at which the Parameter Version was updated.
    output: true
  - name: 'disabled'
    type: Boolean
    description: |
      The current state of Parameter Version. This field is only applicable for updating Parameter Version.
  - name: 'payload'
    type: NestedObject
    description: |
      The payload content of a ParameterVersion resource.
    flatten_object: true
    required: true
    immutable: true
    custom_flatten: 'templates/terraform/custom_flatten/parameter_version_parameter_data.go.tmpl'
    properties:
      - name: 'parameter_data'
        type: String
        description: |
          The Parameter data.
        api_name: data
        required: true
        immutable: true
        sensitive: true
        custom_expand: 'templates/terraform/custom_expand/base64.go.tmpl'
  - name: 'kmsKeyVersion'
    type: String
    output: true
    description: |
      The resource name of the Cloud KMS CryptoKeyVersion used to decrypt parameter version payload. Format
      `projects/{{project}}/locations/global/keyRings/{{key_ring}}/cryptoKeys/{{crypto_key}}/cryptoKeyVersions/{{crypto_key_version}}`
