# 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: 'StoragePool'
description: |
 Storage pools act as containers for volumes. All volumes in a storage pool share the following information:
 * Location
 * Service level
 * Virtual Private Cloud (VPC) network
 * Active Directory policy
 * LDAP use for NFS volumes, if applicable
 * Customer-managed encryption key (CMEK) policy

 The capacity of the pool can be split up and assigned to volumes within the pool. Storage pools are a billable
 component of NetApp Volumes. Billing is based on the location, service level, and capacity allocated to a pool
 independent of consumption at the volume level.

 Storage pools of service level Flex are available as zonal (single zone) or regional (two zones in same region) pools.
 Zonal and regional pools are high-available within the zone. On top of that, regional pools have `replica_zone` as
 hot standby zone. All volume access is served from the `zone`. If `zone` fails, `replica_zone`
 automatically becomes the active zone. This will cause state drift in your configuration.
 If a zone switch (manual or automatic) is triggered outside of Terraform, you need to adjust the `zone`
 and `replica_zone` values to reflect the current state, or Terraform will initiate a zone switch when running
 the next apply. You can trigger a manual
 [zone switch](https://cloud.google.com/netapp/volumes/docs/configure-and-use/storage-pools/edit-or-delete-storage-pool#switch_active_and_replica_zones)
 via Terraform by swapping the value of the `zone` and `replica_zone` parameters in your HCL code.
 Note: Custom Performance FLEX storage pools are supported in beta provider currently.

references:
  guides:
    'Quickstart documentation': 'https://cloud.google.com/netapp/volumes/docs/get-started/quickstarts/create-storage-pool'
    'Regional Flex zone switch': 'https://cloud.google.com/netapp/volumes/docs/configure-and-use/storage-pools/edit-or-delete-storage-pool#switch_active_and_replica_zones'
  api: 'https://cloud.google.com/netapp/volumes/docs/reference/rest/v1/projects.locations.storagePools'
docs:
id_format: 'projects/{{project}}/locations/{{location}}/storagePools/{{name}}'
base_url: 'projects/{{project}}/locations/{{location}}/storagePools'
self_link: 'projects/{{project}}/locations/{{location}}/storagePools/{{name}}'
create_url: 'projects/{{project}}/locations/{{location}}/storagePools?storagePoolId={{name}}'
update_url: 'projects/{{project}}/locations/{{location}}/storagePools/{{name}}'
update_verb: 'PATCH'
update_mask: true
delete_url: 'projects/{{project}}/locations/{{location}}/storagePools/{{name}}'
import_format:
  - 'projects/{{project}}/locations/{{location}}/storagePools/{{name}}'
timeouts:
  insert_minutes: 45
  update_minutes: 20
  delete_minutes: 20
autogen_async: true
async:
  actions: ['create', 'delete', 'update']
  type: 'OpAsync'
  operation:
    base_url: '{{op_id}}'
  result:
    resource_inside_response: false
custom_code:
  pre_update: 'templates/terraform/pre_update/netapp_storagepool.go.tmpl'
# Skipping the sweeper since we need to sweep multiple regions
exclude_sweeper: true
examples:
  - name: 'Storage_pool_create'
    primary_resource_id: 'test_pool'
    vars:
      pool_name: 'test-pool'
      network_name: 'test-network'
      global_name: 'test-address'
parameters:
  - name: 'location'
    type: String
    description: |
      Name of the location. For zonal Flex pools specify a zone name, in all other cases a region name.
    url_param_only: true
    required: true
    immutable: true
  - name: 'name'
    type: String
    description:
      The resource name of the storage pool. Needs to be unique per location/region.
    url_param_only: true
    required: true
    immutable: true
properties:
  - name: 'serviceLevel'
    type: Enum
    description: |
      Service level of the storage pool.
    required: true
    immutable: true
    enum_values:
      - 'PREMIUM'
      - 'EXTREME'
      - 'STANDARD'
      - 'FLEX'
  - name: 'capacityGib'
    type: String
    description: |
      Capacity of the storage pool (in GiB).
    required: true
  - name: 'volumeCapacityGib'
    type: String
    description: |
      Size allocated to volumes in the storage pool (in GiB).
    output: true
  - name: 'volumeCount'
    type: Integer
    description: |
      Number of volume in the storage pool.
    output: true
  - name: 'description'
    type: String
    description: |
      An optional description of this resource.
  - name: 'labels'
    type: KeyValueLabels
    description: |
      Labels as key value pairs. Example: `{ "owner": "Bob", "department": "finance", "purpose": "testing" }`.
  - name: 'network'
    type: String
    description: |
      VPC network name with format: `projects/{{project}}/global/networks/{{network}}`
    required: true
    immutable: true
    diff_suppress_func: 'tpgresource.ProjectNumberDiffSuppress'
  - name: 'activeDirectory'
    type: String
    description: |
      Specifies the Active Directory policy to be used. Format: `projects/{{project}}/locations/{{location}}/activeDirectories/{{name}}`.
      The policy needs to be in the same location as the storage pool.
  - name: 'kmsConfig'
    type: String
    description: |
      Specifies the CMEK policy to be used for volume encryption. Format: `projects/{{project}}/locations/{{location}}/kmsConfigs/{{name}}`.
      The policy needs to be in the same location as the storage pool.
    immutable: true
  - name: 'ldapEnabled'
    type: Boolean
    description: |
      When enabled, the volumes uses Active Directory as LDAP name service for UID/GID lookups. Required to enable extended group support for NFSv3,
      using security identifiers for NFSv4.1 or principal names for kerberized NFSv4.1.
    immutable: true
  - name: 'encryptionType'
    type: String
    description: |
      Reports if volumes in the pool are encrypted using a Google-managed encryption key or CMEK.
    output: true
  - name: 'zone'
    type: String
    description: |
      Specifies the active zone for regional Flex pools. `zone` and `replica_zone` values can be swapped to initiate a
      [zone switch](https://cloud.google.com/netapp/volumes/docs/configure-and-use/storage-pools/edit-or-delete-storage-pool#switch_active_and_replica_zones).
      If you want to create a zonal Flex pool, specify a zone name for `location` and omit `zone`.
    default_from_api: true
  - name: 'replicaZone'
    type: String
    description: |
      Specifies the replica zone for regional Flex pools. `zone` and `replica_zone` values can be swapped to initiate a
      [zone switch](https://cloud.google.com/netapp/volumes/docs/configure-and-use/storage-pools/edit-or-delete-storage-pool#switch_active_and_replica_zones).
  - name: 'allowAutoTiering'
    type: Boolean
    description: |
      Optional. True if the storage pool supports Auto Tiering enabled volumes. Default is false.
      Auto-tiering can be enabled after storage pool creation but it can't be disabled once enabled.
    immutable: true
  - name: 'customPerformanceEnabled'
    type: Boolean
    description: |
      Optional. True if using Independent Scaling of capacity and performance (Hyperdisk). Default is false.
    immutable: true
    min_version: 'beta'
  - name: 'totalThroughputMibps'
    type: String
    description: |
      Optional. Custom Performance Total Throughput of the pool (in MiB/s).
    min_version: 'beta'
  - name: 'totalIops'
    type: String
    description: |
      Optional. Custom Performance Total IOPS of the pool If not provided, it will be calculated based on the totalThroughputMibps
    min_version: 'beta'
