# 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: 'Folder'
kind: 'storage#folder'
base_url: 'b/{{bucket}}/folders'
self_link: 'b/{{bucket}}/folders/{{%name}}'
id_format: '{{bucket}}/{{name}}'
delete_url: 'b/{{bucket}}/folders/{{%name}}'
create_url: 'b/{{bucket}}/folders'
has_self_link: true
timeouts:
  insert_minutes: 20
  update_minutes: 20
  delete_minutes: 20
exclude_sweeper: true
import_format:
  - '{{bucket}}/folders/{{%name}}'
  - '{{bucket}}/{{%name}}'
examples:
  - name: 'storage_folder_basic'
    primary_resource_id: 'folder'
    vars:
      bucket_name: 'my-bucket'
    ignore_read_extra:
      - 'force_destroy'
description: |
  A Google Cloud Storage Folder.

  The Folder resource represents a folder in a Cloud Storage bucket with hierarchical namespace enabled
references:
  guides:
    'Official Documentation': 'https://cloud.google.com/storage/docs/folders-overview'
  api: 'https://cloud.google.com/storage/docs/json_api/v1/folders'
custom_code:
  custom_import: templates/terraform/custom_import/storage_folder.go.tmpl
  custom_update: templates/terraform/custom_update/storage_folder_update.go.tmpl
  custom_delete: templates/terraform/custom_delete/storage_folder_delete.go.tmpl
virtual_fields:
  - name: 'force_destroy'
    description:
      If set to true, items within folder if any will be force destroyed.
    type: Boolean
    default_value: false
parameters:
  - name: 'bucket'
    resource: 'Bucket'
    imports: 'name'
    description: 'The name of the bucket that contains the folder.'
    required: true
    immutable: true
    url_param_only: true
  - name: 'name'
    description: |
      The name of the folder expressed as a path. Must include
      trailing '/'. For example, `example_dir/example_dir2/`, `example@#/`, `a-b/d-f/`.
    required: true
    immutable: true
    # The API returns values with trailing slashes, even if not
    # provided. Enforcing trailing slashes prevents diffs and ensures
    # consistent output.
    validation:
      regex: '/$'
properties:
  - name: createTime
    type: String
    description: |
      The timestamp at which this folder was created.
    output: true
  - name: updateTime
    type: String
    description: |
      The timestamp at which this folder was most recently updated.
    output: true
  - name: metageneration
    type: String
    description: |
      The metadata generation of the folder.
    output: true
