# 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: 'InstanceGroupManager'
kind: 'compute#instanceGroupManager'
description: |
  Creates a managed instance group using the information that you specify in
  the request. After the group is created, it schedules an action to create
  instances in the group using the specified instance template. This
  operation is marked as DONE when the group is created even if the
  instances in the group have not yet been created. You must separately
  verify the status of the individual instances.

  A managed instance group can have up to 1000 VM instances per group.
# Used as a resource reference
exclude: true
docs:
base_url: 'projects/{{project}}/zones/{{zone}}/instanceGroupManagers'
has_self_link: 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:
parameters:
  - name: 'zone'
    type: ResourceRef
    description: 'The zone the managed instance group resides.'
    required: true
    custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
    resource: 'Zone'
    imports: 'name'
properties:
  - name: 'baseInstanceName'
    type: String
    description: |
      The base instance name to use for instances in this group. The value
      must be 1-58 characters long. Instances are named by appending a
      hyphen and a random four-character string to the base instance name.
      The base instance name must comply with RFC1035.
    required: true
  - name: 'instanceGroupManagerId'
    type: Integer
    description: |
      The unique identifier number for the resource. This identifier is defined by the server.
    api_name: id
    output: true
  - name: 'creationTimestamp'
    type: Time
    description: |
      The creation timestamp for this managed instance group in RFC3339
      text format.
    output: true
  - name: 'currentActions'
    type: NestedObject
    description: |
      The list of instance actions and the number of instances in this
      managed instance group that are scheduled for each of those actions.
    output: true
    properties:
      - name: 'abandoning'
        type: Integer
        description: |
          The total number of instances in the managed instance group that
          are scheduled to be abandoned. Abandoning an instance removes it
          from the managed instance group without deleting it.
        output: true
      - name: 'creating'
        type: Integer
        description: |
          The number of instances in the managed instance group that are
          scheduled to be created or are currently being created. If the
          group fails to create any of these instances, it tries again until
          it creates the instance successfully.

          If you have disabled creation retries, this field will not be
          populated; instead, the creatingWithoutRetries field will be
          populated.
        output: true
      - name: 'creatingWithoutRetries'
        type: Integer
        description: |
          The number of instances that the managed instance group will
          attempt to create. The group attempts to create each instance only
          once. If the group fails to create any of these instances, it
          decreases the group's targetSize value accordingly.
        output: true
      - name: 'deleting'
        type: Integer
        description: |
          The number of instances in the managed instance group that are
          scheduled to be deleted or are currently being deleted.
        output: true
      - name: 'none'
        type: Integer
        description: |
          The number of instances in the managed instance group that are
          running and have no scheduled actions.
        output: true
      - name: 'recreating'
        type: Integer
        description: |
          The number of instances in the managed instance group that are
          scheduled to be recreated or are currently being being recreated.
          Recreating an instance deletes the existing root persistent disk
          and creates a new disk from the image that is defined in the
          instance template.
        output: true
      - name: 'refreshing'
        type: Integer
        description: |
          The number of instances in the managed instance group that are
          being reconfigured with properties that do not require a restart
          or a recreate action. For example, setting or removing target
          pools for the instance.
        output: true
      - name: 'restarting'
        type: Integer
        description: |
          The number of instances in the managed instance group that are
          scheduled to be restarted or are currently being restarted.
        output: true
  - name: 'description'
    type: String
    description: |
      An optional description of this resource. Provide this property when
      you create the resource.
    immutable: true
  # fingerprint ignored as it is an internal locking detail
  - name: 'id'
    type: Integer
    description: 'A unique identifier for this resource'
    output: true
  - name: 'instanceGroup'
    type: ResourceRef
    description: 'The instance group being managed'
    output: true
    custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
    resource: 'InstanceGroup'
    imports: 'selfLink'
  - name: 'instanceTemplate'
    type: ResourceRef
    description: |
      The instance template that is specified for this managed instance
      group. The group uses this template to create all new instances in the
      managed instance group.
    required: true
  # kind is internal transport detail
    custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
    resource: 'InstanceTemplate'
    imports: 'selfLink'
  - name: 'name'
    type: String
    description: |
      The name of the managed instance group. The name must be 1-63
      characters long, and comply with RFC1035.
    required: true
  # TODO(nelsonjr): Make namedPorts a NameValue(name[string], port[integer])
  - name: 'namedPorts'
    type: Array
    description:
      Named ports configured for the Instance Groups complementary to this
      Instance Group Manager.
    item_type:
      type: NestedObject
      properties:
        - name: 'name'
          type: String
          description: |
            The name for this named port. The name must be 1-63 characters
            long, and comply with RFC1035.
        - name: 'port'
          type: Integer
          description:
            The port number, which can be a value between 1 and 65535.
  - name: 'region'
    type: ResourceRef
    description: |
      The region this managed instance group resides
      (for regional resources).
    output: true
    custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
    resource: 'Region'
    imports: 'selfLink'
  - name: 'targetPools'
    type: Array
    description: |
      TargetPool resources to which instances in the instanceGroup field are
      added. The target pools automatically apply to all of the instances in
      the managed instance group.
    custom_expand: 'templates/terraform/custom_expand/array_resourceref_with_validation.go.tmpl'
    item_type:
      name: 'targetPool'
      type: ResourceRef
      description: 'The targetPool to receive managed instances.'
      resource: 'TargetPool'
      imports: 'selfLink'
  - name: 'targetSize'
    type: Integer
    description: |
      The target number of running instances for this managed instance
      group. Deleting or abandoning instances reduces this number. Resizing
      the group changes this number.
