liveBook · Manning

Cloud block

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A Terraform cloud block is a configuration block for connecting Terraform to Terraform Cloud or Terraform Enterprise.

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

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains replacement of backend blocks, remote operation boundaries, service selection, and workspace selectors without detailing authentication or state internals.
Examples
Demonstrates tagged workspace selection and explicit named workspace selection with hosted and custom service hostnames.
What it assumes
Assumes familiarity with Terraform configuration and workspaces while distinguishing cloud blocks from standard backend blocks.
What you can do after
Operate/configure shared Terraform workflows with centralized state, tagged or named workspaces, and remote plan and apply execution.
How it connects
Links Terraform Cloud, Terraform Enterprise, backends, remote state, workspaces, and the terraform workspace command.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.