I am trying to configure my tiny piece of Terraform code to use the cloud{}
backend.
Because this code is used in multiple TFE/TFC orgs, I am using the Environment Variables method to supply the config per https://developer.hashicorp.com/terraform/cli/v1.2.x/cloud/settings#environment-variables.
Code snippets:
terraform {
required_version = ">= 1.2"
# https://developer.hashicorp.com/terraform/cli/cloud/settings
cloud {
# cloud block is configured via env settings.
# TF_CLOUD_ORGANIZATION
# TF_CLOUD_HOSTNAME
# TF_CLOUD_WORKSPACE
}
required_providers {
# https://registry.terraform.io/providers/hashicorp/azurerm/latest
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
# https://registry.terraform.io/providers/hashicorp/vault/latest
vault = {
source = "hashicorp/vault"
version = "~>3.7"
}
}
}
The required environment variables exist in my shell:
~azure-basic-test !3: set | grep TF_
TF_CLOUD_HOSTNAME=terraform-qa.redacted.cloud
TF_CLOUD_ORGANIZATION=redactedqa-org
TF_CLOUD_WORKSPACE=terraformPrototypes
When I run the terraform init
in my shell, terraform says:
Initializing Terraform Cloud...
β·
β Error: Invalid or missing required argument
β
β on main.tf line 6, in terraform:
β 6: cloud {
β
β "organization" must be set in the cloud configuration or as an environment variable: TF_CLOUD_ORGANIZATION.
β Error: Invalid workspaces configuration
β
β on main.tf line 6, in terraform:
β 6: cloud {
β
β Missing workspace mapping strategy. Either workspace "tags" or "name" is required.
β
β The 'workspaces' block configures how Terraform CLI maps its workspaces for this single
β configuration to workspaces within a Terraform Cloud organization. Two strategies are available:
β
β tags - A set of tags used to select remote Terraform Cloud workspaces to be used for this single
β configuration. New workspaces will automatically be tagged with these tag values. Generally, this
β is the primary and recommended strategy to use. This option conflicts with "name".
β
β name - The name of a single Terraform Cloud workspace to be used with this configuration.
β When configured, only the specified workspace can be used. This option conflicts with "tags".
What am I missing here?