# 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: 'Service'
description: |
  A managed metastore service that serves metadata queries.
references:
  guides:
    'Official Documentation': 'https://cloud.google.com/dataproc-metastore/docs/overview'
  api: 'https://cloud.google.com/dataproc-metastore/docs/reference/rest/v1/projects.locations.services'
docs:
base_url: 'projects/{{project}}/locations/{{location}}/services'
self_link: 'projects/{{project}}/locations/{{location}}/services/{{service_id}}'
create_url: 'projects/{{project}}/locations/{{location}}/services?serviceId={{service_id}}'
update_verb: 'PATCH'
update_mask: true
import_format:
  - 'projects/{{project}}/locations/{{location}}/services/{{service_id}}'
timeouts:
  insert_minutes: 75
  update_minutes: 75
  delete_minutes: 75
autogen_async: true
async:
  actions: ['create', 'delete', 'update']
  type: 'OpAsync'
  operation:
    base_url: '{{op_id}}'
    timeouts:
      insert_minutes: 75
      update_minutes: 75
      delete_minutes: 75
  result:
    resource_inside_response: false
iam_policy:
  method_name_separator: ':'
  parent_resource_attribute: 'service_id'
  example_config_body: 'templates/terraform/iam/iam_attributes.go.tmpl'
  import_format:
    - 'projects/{{project}}/locations/{{location}}/services/{{service_id}}'
    - '{{service_id}}'
custom_code:
examples:
  - name: 'dataproc_metastore_service_basic'
    primary_resource_id: 'default'
    primary_resource_name: 'fmt.Sprintf("tf-test-metastore-srv%s", context["random_suffix"])'
    vars:
      metastore_service_name: 'metastore-srv'
  - name: 'dataproc_metastore_service_deletion_protection'
    primary_resource_id: 'default'
    primary_resource_name: 'fmt.Sprintf("tf-test-metastore-srv%s", context["random_suffix"])'
    vars:
      metastore_service_name: 'metastore-srv'
      deletion_protection: 'true'
    test_vars_overrides:
      'deletion_protection': 'false'
    oics_vars_overrides:
      'deletion_protection': 'false'
  - name: 'dataproc_metastore_service_cmek_test'
    primary_resource_id: 'default'
    vars:
      metastore_service_name: 'example-service'
      'kms_key_name': 'acctest.BootstrapKMSKeyWithPurposeInLocationAndName(t, "ENCRYPT_DECRYPT", "us-central1", "tf-bootstrap-metastore-service-key1").CryptoKey.Name'
    exclude_docs: true
    skip_vcr: true
  - name: 'dataproc_metastore_service_cmek_example'
    primary_resource_id: 'default'
    vars:
      metastore_service_name: 'example-service'
      key_name: 'example-key'
      keyring_name: 'example-keyring'
    exclude_test: true
  - name: 'dataproc_metastore_service_endpoint'
    primary_resource_id: 'endpoint'
    vars:
      metastore_service_name: 'metastore-endpoint'
    exclude_docs: true
  - name: 'dataproc_metastore_service_aux'
    primary_resource_id: 'aux'
    vars:
      metastore_service_name: 'metastore-aux'
    exclude_docs: true
  - name: 'dataproc_metastore_service_metadata'
    primary_resource_id: 'metadata'
    vars:
      metastore_service_name: 'metastore-metadata'
    exclude_docs: true
  - name: 'dataproc_metastore_service_private_service_connect'
    primary_resource_id: 'default'
    vars:
      metastore_service_name: 'metastore-srv'
      network_name: 'my-network'
      subnet_name: 'my-subnetwork'
    exclude_test: true
  - name: 'dataproc_metastore_service_private_service_connect_custom_routes'
    primary_resource_id: 'default'
    min_version: 'beta'
    vars:
      metastore_service_name: 'metastore-srv'
      network_name: 'my-network'
      subnet_name: 'my-subnetwork'
    exclude_test: true
  - name: 'dataproc_metastore_service_telemetry'
    primary_resource_id: 'telemetry'
    vars:
      metastore_service_name: 'ms-telemetry'
    exclude_docs: true
  - name: 'dataproc_metastore_service_dpms2'
    primary_resource_id: 'dpms2'
    vars:
      metastore_service_name: 'ms-dpms2'
  - name: 'dataproc_metastore_service_dpms2_scaling_factor'
    primary_resource_id: 'dpms2_scaling_factor'
    vars:
      metastore_service_name: 'ms-dpms2sf'
  - name: 'dataproc_metastore_service_dpms2_scaling_factor_lt1'
    primary_resource_id: 'dpms2_scaling_factor_lt1'
    vars:
      metastore_service_name: 'ms-dpms2sflt1'
    exclude_docs: true
  - name: 'dataproc_metastore_service_scheduled_backup'
    primary_resource_id: 'backup'
    vars:
      metastore_service_name: 'backup'
  - name: 'dataproc_metastore_service_autoscaling_max_scaling_factor'
    primary_resource_id: 'test_resource'
    vars:
      metastore_service_name: 'test-service'
  - name: 'dataproc_metastore_service_autoscaling_min_and_max_scaling_factor'
    primary_resource_id: 'test_resource'
    vars:
      metastore_service_name: 'test-service'
  - name: 'dataproc_metastore_service_autoscaling_min_scaling_factor'
    primary_resource_id: 'test_resource'
    vars:
      metastore_service_name: 'test-service'
  - name: 'dataproc_metastore_service_autoscaling_no_limit_config'
    primary_resource_id: 'test_resource'
    vars:
      metastore_service_name: 'test-service'
parameters:
  - name: 'serviceId'
    type: String
    description: |
      The ID of the metastore service. The id must contain only letters (a-z, A-Z), numbers (0-9), underscores (_),
      and hyphens (-). Cannot begin or end with underscore or hyphen. Must consist of between
      3 and 63 characters.
    url_param_only: true
    required: true
    immutable: true
  - name: 'location'
    type: String
    description: |
      The location where the metastore service should reside.
      The default value is `global`.
    url_param_only: true
    immutable: true
    default_value: "global"
properties:
  - name: 'name'
    type: String
    description: |
      The relative resource name of the metastore service.
    output: true
  - name: 'createTime'
    type: Time
    description: |
      Output only. The time when the metastore service was created.
    output: true
  - name: 'updateTime'
    type: Time
    description: |
      Output only. The time when the metastore service was last updated.
    output: true
  - name: 'labels'
    type: KeyValueLabels
    description: 'User-defined labels for the metastore service.'
  # This is an x-product resource reference.
  - name: 'network'
    type: String
    description: |
      The relative resource name of the VPC network on which the instance can be accessed. It is specified in the following form:

      "projects/{projectNumber}/global/networks/{network_id}".
    immutable: true
    default_from_api: true
  - name: 'endpointUri'
    type: String
    description: |
      The URI of the endpoint used to access the metastore service.
    output: true
  - name: 'port'
    type: Integer
    description: |
      The TCP port at which the metastore service is reached. Default: 9083.
    default_from_api: true
  - name: 'state'
    type: String
    description: |
      The current state of the metastore service.
    output: true
  - name: 'stateMessage'
    type: String
    description: |
      Additional information about the current state of the metastore service, if available.
    output: true
  - name: 'artifactGcsUri'
    type: String
    description: |
      A Cloud Storage URI (starting with gs://) that specifies where artifacts related to the metastore service are stored.
    output: true
  - name: 'tier'
    type: Enum
    description: |
      The tier of the service.
    default_from_api: true
    conflicts:
      - scalingConfig
    enum_values:
      - 'DEVELOPER'
      - 'ENTERPRISE'
  - name: 'scalingConfig'
    type: NestedObject
    description: |
      Represents the scaling configuration of a metastore service.
    properties:
      - name: 'instanceSize'
        type: Enum
        description: |
          Metastore instance sizes.
        required: false
        conflicts:
          - tier
        exactly_one_of:
          - 'scaling_config.0.instance_size'
          - 'scaling_config.0.scaling_factor'
          - 'scaling_config.0.autoscaling_config'
        enum_values:
          - 'EXTRA_SMALL'
          - 'SMALL'
          - 'MEDIUM'
          - 'LARGE'
          - 'EXTRA_LARGE'
      - name: 'scalingFactor'
        type: Double
        description: |
          Scaling factor, in increments of 0.1 for values less than 1.0, and increments of 1.0 for values greater than 1.0.
        required: false
      - name: 'autoscalingConfig'
        type: NestedObject
        description: |
          Represents the autoscaling configuration of a metastore service.
        required: false
        properties:
          - name: 'autoscalingEnabled'
            type: Boolean
            description: |
              Defines whether autoscaling is enabled. The default value is false.
          - name: 'autoscalingFactor'
            type: Double
            description: |
              Output only. The scaling factor of a service with autoscaling enabled.
            output: true
          - name: 'limitConfig'
            type: NestedObject
            description: |
              Represents the limit configuration of a metastore service.
            default_from_api: true
            properties:
              - name: 'minScalingFactor'
                type: Double
                description: |
                  The minimum scaling factor that the service will autoscale to. The default value is 0.1.
                default_from_api: true
              - name: 'maxScalingFactor'
                type: Double
                description: |
                  The maximum scaling factor that the service will autoscale to. The default value is 6.0.
                default_from_api: true
  - name: 'scheduledBackup'
    type: NestedObject
    description: |
      The configuration of scheduled backup for the metastore service.
    properties:
      - name: 'enabled'
        type: Boolean
        description: |
          Defines whether the scheduled backup is enabled. The default value is false.
        default_from_api: true
      - name: 'cronSchedule'
        type: String
        description: |
          The scheduled interval in Cron format, see https://en.wikipedia.org/wiki/Cron The default is empty: scheduled backup is not enabled. Must be specified to enable scheduled backups.
      - name: 'timeZone'
        type: String
        description: |
          Specifies the time zone to be used when interpreting cronSchedule. Must be a time zone name from the time zone database (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), e.g. America/Los_Angeles or Africa/Abidjan. If left unspecified, the default is UTC.
        default_from_api: true
      - name: 'backupLocation'
        type: String
        description: |
          A Cloud Storage URI of a folder, in the format gs://<bucket_name>/<path_inside_bucket>. A sub-folder <backup_folder> containing backup files will be stored below it.
        required: true
  - name: 'deletionProtection'
    type: Boolean
    description: |
      Indicates if the dataproc metastore should be protected against accidental deletions.
  - name: 'maintenanceWindow'
    type: NestedObject
    description: |
      The one hour maintenance window of the metastore service.
      This specifies when the service can be restarted for maintenance purposes in UTC time.
      Maintenance window is not needed for services with the `SPANNER` database type.
    properties:
      - name: 'hourOfDay'
        type: Integer
        description: |
          The hour of day (0-23) when the window starts.
        required: true
      - name: 'dayOfWeek'
        type: Enum
        description: |
          The day of week, when the window starts.
        required: true
        enum_values:
          - 'MONDAY'
          - 'TUESDAY'
          - 'WEDNESDAY'
          - 'THURSDAY'
          - 'FRIDAY'
          - 'SATURDAY'
          - 'SUNDAY'
  - name: 'encryptionConfig'
    type: NestedObject
    description: |
      Information used to configure the Dataproc Metastore service to encrypt
      customer data at rest.
    properties:
      - name: 'kmsKey'
        type: String
        description: |
          The fully qualified customer provided Cloud KMS key name to use for customer data encryption.
          Use the following format: `projects/([^/]+)/locations/([^/]+)/keyRings/([^/]+)/cryptoKeys/([^/]+)`
        required: true
        immutable: true
  - name: 'hiveMetastoreConfig'
    type: NestedObject
    description: |
      Configuration information specific to running Hive metastore software as the metastore service.
    properties:
      - name: 'endpointProtocol'
        type: Enum
        description: |
          The protocol to use for the metastore service endpoint. If unspecified, defaults to `THRIFT`.
        immutable: true
        default_value: "THRIFT"
        enum_values:
          - 'THRIFT'
          - 'GRPC'
      - name: 'version'
        type: String
        description: |
          The Hive metastore schema version.
        required: true
        immutable: true
      - name: 'configOverrides'
        type: KeyValuePairs
        description: |
          A mapping of Hive metastore configuration key-value pairs to apply to the Hive metastore (configured in hive-site.xml).
          The mappings override system defaults (some keys cannot be overridden)
        default_from_api: true
        diff_suppress_func: 'dataprocMetastoreServiceOverrideSuppress'
      - name: 'kerberosConfig'
        type: NestedObject
        description: |
          Information used to configure the Hive metastore service as a service principal in a Kerberos realm.
        properties:
          - name: 'keytab'
            type: NestedObject
            description: |
              A Kerberos keytab file that can be used to authenticate a service principal with a Kerberos Key Distribution Center (KDC).
            required: true
            properties:
              - name: 'cloudSecret'
                type: String
                description: |
                  The relative resource name of a Secret Manager secret version, in the following form:

                  "projects/{projectNumber}/secrets/{secret_id}/versions/{version_id}".
                required: true
          - name: 'principal'
            type: String
            description: |
              A Kerberos principal that exists in the both the keytab the KDC to authenticate as. A typical principal is of the form "primary/instance@REALM", but there is no exact format.
            required: true
          - name: 'krb5ConfigGcsUri'
            type: String
            description: |
              A Cloud Storage URI that specifies the path to a krb5.conf file. It is of the form gs://{bucket_name}/path/to/krb5.conf, although the file does not need to be named krb5.conf explicitly.
            required: true
      - name: 'auxiliaryVersions'
        type: Map
        description: |
          A mapping of Hive metastore version to the auxiliary version configuration.
          When specified, a secondary Hive metastore service is created along with the primary service.
          All auxiliary versions must be less than the service's primary version.
          The key is the auxiliary service name and it must match the regular expression a-z?.
          This means that the first character must be a lowercase letter, and all the following characters must be hyphens, lowercase letters, or digits, except the last character, which cannot be a hyphen.
        key_name: 'key'
        key_description: |
          The auxiliary service name
        value_type:
          name: auxiliaryVersions
          type: NestedObject
          properties:
            - name: 'version'
              type: String
              description: |
                The Hive metastore version of the auxiliary service. It must be less than the primary Hive metastore service's version.
              required: true
            - name: 'configOverrides'
              type: KeyValuePairs
              description: |
                A mapping of Hive metastore configuration key-value pairs to apply to the auxiliary Hive metastore (configured in hive-site.xml) in addition to the primary version's overrides.
                If keys are present in both the auxiliary version's overrides and the primary version's overrides, the value from the auxiliary version's overrides takes precedence.
  - name: 'networkConfig'
    type: NestedObject
    description: |
      The configuration specifying the network settings for the Dataproc Metastore service.
    immutable: true
    properties:
      - name: 'consumers'
        type: Array
        description: |
          The consumer-side network configuration for the Dataproc Metastore instance.
        required: true
        immutable: true
        item_type:
          type: NestedObject
          properties:
            - name: 'endpointUri'
              type: String
              description: |
                The URI of the endpoint used to access the metastore service.
              output: true
            - name: 'subnetwork'
              type: String
              description: |
                The subnetwork of the customer project from which an IP address is reserved and used as the Dataproc Metastore service's endpoint.
                It is accessible to hosts in the subnet and to all hosts in a subnet in the same region and same network.
                There must be at least one IP address available in the subnet's primary range. The subnet is specified in the following form:
                `projects/{projectNumber}/regions/{region_id}/subnetworks/{subnetwork_id}
              required: true
      - name: 'customRoutesEnabled'
        type: Boolean
        description: |
          Enables custom routes to be imported and exported for the Dataproc Metastore service's peered VPC network.
        min_version: 'beta'
  - name: 'databaseType'
    type: Enum
    description: |
      The database type that the Metastore service stores its data.
    immutable: true
    default_value: "MYSQL"
    enum_values:
      - 'MYSQL'
      - 'SPANNER'
  - name: 'releaseChannel'
    type: Enum
    description: |
      The release channel of the service. If unspecified, defaults to `STABLE`.
    immutable: true
    default_value: "STABLE"
    enum_values:
      - 'CANARY'
      - 'STABLE'
  - name: 'uid'
    type: String
    description: |
      The globally unique resource identifier of the metastore service.
    output: true
  - name: 'metadataIntegration'
    type: NestedObject
    description: |
      The setting that defines how metastore metadata should be integrated with external services and systems.
    properties:
      - name: 'dataCatalogConfig'
        type: NestedObject
        description: |
          The integration config for the Data Catalog service.
        required: true
        properties:
          - name: 'enabled'
            type: Boolean
            description: |
              Defines whether the metastore metadata should be synced to Data Catalog. The default value is to disable syncing metastore metadata to Data Catalog.
            required: true
  - name: 'telemetryConfig'
    type: NestedObject
    description: |
      The configuration specifying telemetry settings for the Dataproc Metastore service. If unspecified defaults to JSON.
    default_from_api: true
    properties:
      - name: 'logFormat'
        type: Enum
        description: |
          The output format of the Dataproc Metastore service's logs.
        default_value: "JSON"
        enum_values:
          - 'LEGACY'
          - 'JSON'
  - name: 'tags'
    type: KeyValuePairs
    description: |
      A map of resource manager tags.
      Resource manager tag keys and values have the same definition as resource manager tags.
      Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_value_id}.
    immutable: true
    ignore_read: true
