A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/terraform/language/v1.10.x/terraform below:

Terraform block configuration reference | Terraform

This topic provides reference information about the terraform block. The terraform block allows you to configure Terraform behavior, including the Terraform version, backend, integration with HCP Terraform, and required providers.

The following list outlines attribute hierarchy, data types, and requirements in the terraform block. Click on an attribute for details.

This section provides details about the fields you can configure in the terraform block. Specific providers and backends may support additional fields.

terraform

Parent block that contains configurations that define Terraform behavior. You can only use constant values in the terraform block. Arguments in the terraform block cannot refer to named objects, such as resources and input variables. Additionally, you cannot use built-in Terraform language functions in the block.

terraform{}.required_version

Specifies which version of the Terraform CLI is allowed to run the configuration. Refer to Version constraints for details about the supported syntax for specifying version constraints.

Use Terraform version constraints in a collaborative environment to ensure that everyone is using a specific Terraform version, or using at least a minimum Terraform version that has behavior expected by the configuration.

Terraform prints an error and exits without taking actions when you use a version of Terraform that does not meet the version constraints to run the configuration.

Modules associated with a configuration may also specify version constraints. You must use a Terraform version that satisfies all version constraints associated with the configuration, including constraints defined in modules, to perform operations. Refer to Modules for additional information about Terraform modules.

The required_version configuration applies only to the version of Terraform CLI and not versions of provider plugins. Refer to Provider Requirements for additional information.

terraform{}.required_providers

Specifies all provider plugins required to create and manage resources specified in the configuration. Each local provider name maps to a source address and a version constraint. Refer to each Terraform provider’s documentation in the public Terraform Registry, or your private registry, for instructions on how to configure attributes in the required_providers block.

terraform{}.provider_meta "<LABEL>"

Specifies metadata fields that a provider may expect. Individual modules can populate the metadata fields independently of any provider configuration. Refer to Provider Metadata for additional information.

terraform{}.backend "<BACKEND_TYPE>"

Specifies a mechanism for storing Terraform state files. The backend block takes a backend type as an argument. Refer to Backend Configuration for details about configuring the backend block.

You cannot configure a backend block when the configuration also contains a cloud configuration for storing state data.

terraform{}.cloud

Specifies a set of attributes that allow the Terraform configuration to connect to either HCP Terraform or a Terraform Enterprise installation. HCP Terraform and Terraform Enterprise provide state storage, remote execution, and other benefits. Refer to the HCP Terraform and Terraform Enterprise documentation for additional information.

You can only provide one cloud block per configuration.

You cannot configure a cloud block when the configuration also contains a backend configuration for storing state data.

The cloud block cannot refer to named values, such as input variables, locals, or data source attributes.

terraform{}.cloud{}.organization

Specifies the name of the organization you want to connect to. Instead of hardcoding the organization as a string, you can alternatively use the TF_CLOUD_ORGANIZATION environment variable.

terraform{}.cloud{}.workspaces

Specifies metadata for matching workspaces in HCP Terraform. Terraform associates the configuration with workspaces managed in HCP Terraform that match the specified tags, name, or project. You can specify the following metadata in the workspaces block:

Attribute Description Data type tags Specifies either a map of strings as key/value tags or a list of single-value, key-only tags. Terraform associates the configuration with workspaces that have all matching tags. New workspaces created from the working directory inherit the tags. You cannot set this attribute and the name attribute in the same configuration. Using a map type with both keys and values requires Terraform 1.10+. Array of strings or Map of strings name Specifies an HCP Terraform workspace name to associate the Terraform configuration with. You can only use the working directory with the workspace named in the configuration. You cannot manage the workspace from the Terraform CLI. You cannot set this attribute and the tags attribute in the same configuration.

Instead of hardcoding a single workspace as a string, you can alternatively use the TF_WORKSPACE environment variable.

String project Specifies the name of an HCP Terraform project. Terraform creates all workspaces that use this configuration in the project. Using the terraform workspace list command in the working directory returns only workspaces in the specified project.

Instead of hardcoding the project as a string, you can alternatively use the TF_CLOUD_PROJECT environment variable.

String terraform{}.cloud{}.hostname

Specifies the hostname for a Terraform Enterprise deployment. Instead of hardcoding the hostname of the Terraform Enterprise deployment, you can alternatively use the TF_CLOUD_HOSTNAME environment variable.

terraform{}.cloud{}.token

Specifies a token for authenticating with HCP Terraform. We recommend omitting the token from the configuration and either using the terraform login command or manually configuring credentials in the CLI configuration file instead.

terraform{}.experiments

Specifies a list of experimental feature names that you want to opt into. In releases where experimental features are available, you can enable them on a per-module basis.

Experiments are subject to arbitrary changes in later releases and, depending on the outcome of the experiment, may change significantly before final release or may not be released in stable form at all. Breaking changes may appear in minor and patch releases. We do not recommend using experimental features in Terraform modules intended for production.

Modules with experiments enabled generate a warning on every terraform plan or terraform apply operation. If you want to try experimental features in a shared module, we recommend enabling the experiment only in alpha or beta releases of the module.

Refer to the Terraform changelog for information about experiments and to monitor the release notes about experiment keywords that may be available.

You can use environment variables to configure one or more cloud block attributes. This is helpful when you want to use the same Terraform configuration in different HCP Terraform organizations and projects. Terraform only uses these variables if you do not define corresponding attributes in your configuration. If you choose to configure the cloud block entirely through environment variables, you must still add an empty cloud block in your configuration file.

Warning

You can use environment variables to automate Terraform operations, which has specific security considerations. Refer to Non-Interactive Workflows for details.

Use the following environment variables to configure the cloud block:

The following examples demonstrate common configuration patterns for specific use cases.

Add a provider

The following configuration requires the aws provider version 2.7.0 or later from the public Terraform registry:

terraform {
  required_providers {
    aws = {
      version = ">= 2.7.0"
      source = "hashicorp/aws"
    }
  }
}
Connect to HCP Terraform

In the following example, the configuration links the working directory to workspaces in the example_corp organization that contain the layer=app tag:

terraform {
  cloud {
    organization = "example_corp"
    workspaces {
      tags = {
        layer = "app"
      }
    }
  }
}
Connect to Terraform Enterprise

In the following example, the configuration links the working directory to workspaces in the example_corp organization that contain the app key-only tag. Key-only tags must be used with versions of Terraform Enterprise prior to v202411-1 or versions of Terraform prior to v1.10. The hostname field is required in the configuration unless you use the TF_CLOUD_HOSTNAME environment variable:

terraform {
  cloud {
    organization = "example_corp"
    hostname = "my.terraform-enterprise.host"
    workspaces {
      tags = ["app"]
    }
  }
}
Connect to Terraform Enterprise using environment variables

In the following example, Terraform checks the TF_CLOUD_ORGANIZATION and TF_CLOUD_HOSTNAME environment variables and automatically populates the organization and hostname arguments. During initialization, the local Terraform CLI connects the working directory to Terraform Enterprise using those values. As a result, Terraform links the configuration to either HCP Terraform or Terraform Enterprise and allows teams to reuse the configuration in different continuous integration pipelines:

terraform {
  cloud {
    workspaces {
      tags = ["app"]
    }
  }
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4