A Terraform cloud block connects a configuration to Terraform Cloud or a self-hosted Terraform Enterprise instance. It replaces the backend block and centralizes state for team workflows. section 2.3.1
Unlike an ordinary backend, the cloud block can move plan and apply operations to remote systems. Import and state commands continue to run locally, making the block both a state configuration and a remote-run configuration. section 6.4.5
Configure the block by specifying:
- The organization and, when needed, the hostname of the cloud service. section 6.4.5
- A workspace selector using either tags or one workspace name. section 6.4.5
- Tags when the same Terraform project manages many workspaces and needs workspace-command switching. section 6.4.5
Listing 6.12 Terraform cloud block with tags
terraform {
cloud {
organization = "acme-org"
hostname = "app.terraform.io" #1
workspaces {
tags = ["acme_application", "development"] #2
}
}
}
hostname = "app.terraform.io" #3
workspaces {
tags = ["acme_application", "development"] #4
}
}
}
Use tags to associate the configuration with matching workspaces in an organization and hostname. section 6.4.5
Listing 6.13 Terraform cloud block with named project
terraform {
cloud {
organization = "acme-org"
hostname = "acme.scalr.io" #1
workspaces {
name = "acme_development_workspace" #2
}
}
}
Use a workspace name when the configuration should target one explicitly named workspace, including a service with a custom hostname. section 6.4.5
