# 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: 'GlobalAddress'
api_resource_type_kind: Address
kind: 'compute#address'
description: |
  Represents a Global Address resource. Global addresses are used for
  HTTP(S) load balancing.
references:
  guides:
    'Reserving a Static External IP Address': 'https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address'
  api: 'https://cloud.google.com/compute/docs/reference/v1/globalAddresses'
docs:
base_url: 'projects/{{project}}/global/addresses'
has_self_link: true
immutable: true
timeouts:
  insert_minutes: 20
  update_minutes: 20
  delete_minutes: 20
async:
  actions: ['create', 'delete', 'update']
  type: 'OpAsync'
  operation:
    base_url: '{{op_id}}'
  result:
    resource_inside_response: false
collection_url_key: 'items'
custom_code:
  pre_create: 'templates/terraform/pre_create/compute_global_address.go.tmpl'
  post_create: 'templates/terraform/post_create/labels.tmpl'
examples:
  - name: 'global_address_basic'
    primary_resource_id: 'default'
    vars:
      global_address_name: 'global-appserver-ip'
  - name: 'global_address_private_services_connect'
    primary_resource_id: 'default'
    min_version: 'beta'
    vars:
      global_address_name: 'global-psconnect-ip'
      network_name: 'my-network-name'
parameters:
properties:
  - name: 'address'
    type: String
    description: |
      The IP address or beginning of the address range represented by this
      resource. This can be supplied as an input to reserve a specific
      address or omitted to allow GCP to choose a valid one for you.
    default_from_api: true
  - name: 'creationTimestamp'
    type: Time
    description: |
      Creation timestamp in RFC3339 text format.
    output: true
  - name: 'description'
    type: String
    description: |
      An optional description of this resource.
  - 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
  - name: 'labels'
    type: KeyValueLabels
    description: |
      Labels to apply to this address.  A list of key->value pairs.
    update_url: 'projects/{{project}}/global/addresses/{{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}}/global/addresses/{{name}}/setLabels'
    update_verb: 'POST'
    key_expander: ''
  - name: 'ipVersion'
    type: Enum
    description: |
      The IP Version that will be used by this address. The default value is `IPV4`.
    diff_suppress_func: 'tpgresource.EmptyOrDefaultStringSuppress("IPV4")'
    enum_values:
      - 'IPV4'
      - 'IPV6'
  - name: 'prefixLength'
    type: Integer
    description: |
      The prefix length of the IP range. If not present, it means the
      address field is a single IP address.

      This field is not applicable to addresses with addressType=INTERNAL
      when purpose=PRIVATE_SERVICE_CONNECT
    default_from_api: true
  - name: 'addressType'
    type: Enum
    description: |
      The type of the address to reserve.

      * EXTERNAL indicates public/external single IP address.
      * INTERNAL indicates internal IP ranges belonging to some network.
    diff_suppress_func: 'tpgresource.EmptyOrDefaultStringSuppress("EXTERNAL")'
    default_value: "EXTERNAL"
    enum_values:
      - 'EXTERNAL'
      - 'INTERNAL'
  - name: 'purpose'
    type: String
    description: |
      The purpose of the resource. Possible values include:

      * VPC_PEERING - for peer networks

      * PRIVATE_SERVICE_CONNECT - for ([Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html) only) Private Service Connect networks
  - name: 'network'
    type: ResourceRef
    description: |
      The URL of the network in which to reserve the IP range. The IP range
      must be in RFC1918 space. The network cannot be deleted if there are
      any reserved IP ranges referring to it.

      This should only be set when using an Internal address.
    custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
    resource: 'Network'
    imports: 'selfLink'
