MMv1 resource reference

MMv1 resource reference#

This page documents commonly-used properties for resources. For a full list of available properties, see resource.go ↗.

Basic#

name#

API resource name.

description#

Resource description. Used in documentation.

Example:

description: |
  This is a multi-line description
  of a resource. All multi-line descriptions must follow
  this format of using a vertical bar followed by a line-break,
  with the remaining description being indented.

references#

Links to reference documentation for a resource. Contains two attributes:

Example:

references:
  guides:
    'Create and connect to a database': 'https://cloud.google.com/alloydb/docs/quickstart/create-and-connect'
  api: 'https://cloud.google.com/alloydb/docs/reference/rest/v1/projects.locations.backups'

min_version: beta#

Marks the field (and any subfields) as beta-only. Ensure a beta version block is present in provider.yaml.

docs#

Inserts styled markdown into the header of the resource’s page in the provider documentation. Can contain two attributes:

Example:

docs:
  warning: |
    This is a multi-line warning and will be
    displayed on a yellow background.
  note: |
    This is a multi-line note and will be
    displayed on a blue background.

API interactions#

base_url#

URL for the resource’s standard List method. Terraform field names enclosed in double curly braces are replaced with the field values from the resource at runtime.

base_url: 'projects/{{project}}/locations/{{location}}/resourcenames'

URL for the resource’s standard Get method. Terraform field names enclosed in double curly braces are replaced with the field values from the resource at runtime.

self_link: 'projects/{{project}}/locations/{{location}}/resourcenames/{{name}}'

immutable#

If true, the resource and all its fields are considered immutable - that is, only creatable, not updatable. Individual fields can override this for themselves and their subfields with update_url if they have a custom update method in the API.

See Best practices: Immutable fields for more information.

Default: false

Example:

immutable: true

timeouts#

Overrides one or more timeouts, in minutes. All timeouts default to 20.

Example:

timeouts:
  insert_minutes: 40
  update_minutes: 40
  delete_minutes: 40

create_url#

URL for the resource’s standard Create method, including query parameters. Terraform field names enclosed in double curly braces are replaced with the field values from the resource at runtime.

Example:

create_url: 'projects/{{project}}/locations/{{location}}/resourcenames?resourceId={{name}}'

create_verb#

Overrides the HTTP verb used to create a new resource. Allowed values: 'POST', 'PUT', 'PATCH'.

Default: 'POST'

create_verb: 'PATCH'

update_url#

Overrides the URL for the resource’s standard Update method. If unset, the self_link URL is used by default. Terraform field names enclosed in double curly braces are replaced with the field values from the resource at runtime.

update_url: 'projects/{{project}}/locations/{{location}}/resourcenames/{{name}}'

update_verb#

The HTTP verb used to update a resource. Allowed values: 'POST', 'PUT', 'PATCH'.

Default: 'PUT'.

Example:

update_verb: 'PATCH'

update_mask#

If true, the resource sets an updateMask query parameter listing modified fields when updating the resource. If false, it doesn’t.

Default: false

Example:

update_mask: true

delete_url#

Overrides the URL for the resource’s standard Delete method. If unset, the self_link URL is used by default. Terraform field names enclosed in double curly braces are replaced with the field values from the resource at runtime.

Example:

delete_url: 'projects/{{project}}/locations/{{location}}/resourcenames/{{name}}'

delete_verb#

Overrides the HTTP verb used to delete a resource. Allowed values: 'POST', 'PUT', 'PATCH', 'DELETE'.

Default: 'DELETE'

Example:

delete_verb: 'POST'

exclude_delete#

If true, deleting the resource will only remove it from the Terraform state and will not call an API. If false, deleting the resource will run the standard deletion behavior and/or any custom code related to deletion. This should be used if the resource can never be deleted in the API, and there is no other reasonable action to take on deletion. See Deletion behaviors for more information.

exclude_delete: true

autogen_async#

If true, code for handling long-running operations is generated along with the resource. If false, that code isn’t generated and must be handwritten.

Default: false

autogen_async: true

async#

Sets parameters for handling operations returned by the API. Can contain several attributes:

Example:

async:
  actions: ['create', 'update', 'delete']
  operation:
    base_url: '{{op_id}}'
  result:
    resource_inside_response: true

error_retry_predicates#

An array of function names that determine whether an error is retryable.

error_retry_predicates:
  - 'transport_tpg.IamMemberMissing'

error_abort_predicates#

An array of function names that determine whether an error is not retryable.

error_abort_predicates:
  - 'transport_tpg.Is429QuotaError'

IAM resources#

iam_policy#

Allows configuration of generated IAM resources. Supports the following common attributes – for a full reference, see iam_policy.rb ↗:

Example:

iam_policy:
  parent_resource_attribute: 'cloud_function'
  method_name_separator: ':'
  fetch_iam_policy_verb: :POST
  import_format:
    - 'projects/{{project}}/locations/{{location}}/resourcenames/{{cloud_function}}',
    - '{{cloud_function}}'
  allowed_iam_role: 'roles/viewer'
  iam_conditions_request_type: :REQUEST_BODY
  min_version: beta

Resource behavior#

custom_code#

Injects arbitrary logic into a generated resource. For more information, see Add custom resource code.

mutex#

All resources (of all kinds) that share a mutex value will block rather than executing concurrent API requests. Terraform field names enclosed in double curly braces are replaced with the field values from the resource at runtime.

Example:

mutex: 'alloydb/instance/{{name}}'

Sweeper#

Sweepers are a testing infrastructure mechanism that automatically clean up resources created during tests. They run before tests start and can be run manually to clean up dangling resources. Sweepers help prevent test failures due to resource quota limits and reduce cloud infrastructure costs by removing test resources that were not properly cleaned up.

Sweeper generation is enabled by default, except in the following conditions which require customization here:

Define the sweeper block in a resource to override these exclusions and enable sweeper generation for that resource.

exclude_sweeper#

If set to true, no sweeper will be generated for this resource. This is useful for resources that cannot or should not be automatically cleaned up.

Default: false

Example:

exclude_sweeper: true

sweeper#

Configures how test resources are swept (cleaned up) after tests. The sweeper system helps ensure resources created during tests are properly removed, even when tests fail unexpectedly. All fields within the sweeper block are optional, with reasonable defaults provided when not specified. See sweeper.go ↗ for the implementation.

Examples:

Basic sweeper configuration:

sweeper:
  prefixes:
    - "tf-test-"
    - "tmp-"

Sweeper with parent-child relationship (basic):

sweeper:
  dependencies: # sweep google_compute_instance before attempting to sweep this resource
    - "google_compute_instance"
  parent:
    resource_type: "google_container_cluster"
    parent_field: "name"
    child_field: "cluster"

Sweeper with parent_field_extract_name:

sweeper:
  parent:
    resource_type: "google_compute_network"
    parent_field: "selfLink"  # Contains: "projects/my-project/global/networks/my-network"
    parent_field_extract_name: true  # Extracts just "my-network"
    child_field: "network"

Sweeper with parent template and pre-deletion field update:

sweeper:
  parent:
    resource_type: "google_container_cluster"
    template: "projects/{{project}}/locations/{{location}}/clusters/{{value}}"
    parent_field: "displayName"  # Provides the value for {{value}}
    child_field: "cluster"
  ensure_value:
    field: "deletionProtection"
    value: "false"
    include_full_resource: false

Sweeper with URL substitutions for multiple regions:

sweeper:
  url_substitutions:
    - collection_id: default_collection
      region: global
    - collection_id: default_collection
      region: eu

Sweeper with URL substitutions specifying only regions:

sweeper:
  identifier_field: "displayName"
  url_substitutions:
    - region: "us-central1"
    - region: "us-east1"
    - region: "europe-west1"

Fields#

virtual_fields#

Contains a list of virtual_fields. By convention, these should be fields that do not get sent to the API, and are instead used to modify the behavior of a Terraform resource such as deletion_protection.

parameters#

Contains a list of fields. By convention, these should be the fields that are part URL parameters such as location and name.

properties#

Contains a list of fields. By convention, these should be fields that aren’t part of the URL parameters.

Example:

properties:
  - name: 'fieldOne'
    type: String

Examples#

examples#

A list of configurations that are used to generate documentation and tests. Each example supports the following common attributes – for a full reference, see examples.go ↗:

Example:

examples:
  - name: service_resource_basic
    primary_resource_id: example
    bootstrap_iam:
      - member: "serviceAccount:service-{project_number}@gcp-sa-healthcare.iam.gserviceaccount.com"
        role: "roles/bigquery.dataEditor"
      - member: "serviceAccount:service-org-{organization_id}@gcp-sa-osconfig.iam.gserviceaccount.com"
        role: "roles/osconfig.serviceAgent"
    vars:
      dataset_id: "my-dataset"
      network_name: "my-network"
    test_env_vars:
      org_id: "ORG_ID"
    test_vars_overrides:
      network_name: 'acctest.BootstrapSharedServiceNetworkingConnection(t, "service-resource-network-config")'
    min_version: "beta"
    ignore_read_extra: 
      - 'foo'
    exclude_test: true
    exclude_docs: true
    exclude_import_test: true
    skip_vcr: true
    skip_test: "https://github.com/hashicorp/terraform-provider-google/issues/20574"
    external_providers:
      - "time"