0
0
Terraformcloud~5 mins

Terraform Cloud/Enterprise features - Commands & Configuration

Choose your learning style9 modes available
Introduction
Terraform Cloud and Enterprise help teams work together on infrastructure safely and efficiently. They provide features like remote state storage, version control integration, and policy enforcement to avoid mistakes and improve collaboration.
When multiple people manage the same infrastructure and need to avoid conflicts.
When you want to keep your infrastructure state files safe and backed up remotely.
When you want to run Terraform plans and applies automatically after code changes.
When you want to enforce rules on infrastructure changes to meet company policies.
When you want to see detailed logs and history of all infrastructure changes.
Config File - main.tf
main.tf
terraform {
  required_version = ">= 1.3.0"
  backend "remote" {
    organization = "example-org"
    workspaces {
      name = "example-workspace"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_s3_bucket" "example" {
  bucket = "example-terraform-cloud-bucket"
  acl    = "private"
}

This Terraform configuration uses the remote backend to connect to Terraform Cloud under the organization example-org and workspace example-workspace. This setup enables remote state storage and runs in Terraform Cloud.

The AWS provider is configured for the us-east-1 region, and a simple S3 bucket resource is defined.

Commands
This command authenticates your local Terraform CLI with Terraform Cloud so you can securely connect and run commands remotely.
Terminal
terraform login
Expected OutputExpected
Terraform has been successfully configured to authenticate with Terraform Cloud. You are now logged in.
Initializes the Terraform working directory and configures the remote backend to use Terraform Cloud for state management.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Successfully configured the backend "remote"! Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes.
Creates an execution plan showing what Terraform will do when applying the configuration. This runs locally but uses remote state from Terraform Cloud.
Terminal
terraform plan
Expected OutputExpected
Refreshing Terraform state in-memory prior to plan... An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_s3_bucket.example will be created + resource "aws_s3_bucket" "example" { + acl = "private" + bucket = "example-terraform-cloud-bucket" + id = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy.
Applies the planned changes to create the S3 bucket. The apply runs locally but updates state in Terraform Cloud.
Terminal
terraform apply -auto-approve
Expected OutputExpected
aws_s3_bucket.example: Creating... aws_s3_bucket.example: Creation complete after 2s [id=example-terraform-cloud-bucket] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-auto-approve - Skips interactive approval to apply changes immediately
Lists all resources tracked in the Terraform state stored remotely in Terraform Cloud, confirming the S3 bucket is managed.
Terminal
terraform state list
Expected OutputExpected
aws_s3_bucket.example
Key Concept

If you remember nothing else from this pattern, remember: Terraform Cloud stores your state remotely and runs plans and applies safely for teams.

Common Mistakes
Not running 'terraform login' before using Terraform Cloud backend
Terraform CLI cannot authenticate with Terraform Cloud, causing errors when initializing or applying.
Always run 'terraform login' once to authenticate your CLI with Terraform Cloud before other commands.
Using local backend instead of remote backend in team environments
State files are stored locally, risking conflicts and loss when multiple people work on the same infrastructure.
Configure the 'remote' backend in Terraform to store state in Terraform Cloud for safe team collaboration.
Running 'terraform apply' without reviewing the plan
You might apply unintended changes that could break infrastructure or cause downtime.
Always run 'terraform plan' first to review changes before applying.
Summary
Run 'terraform login' to authenticate your CLI with Terraform Cloud.
Configure the 'remote' backend in your Terraform file to store state in Terraform Cloud.
Use 'terraform init' to initialize the backend and working directory.
Run 'terraform plan' to preview changes and 'terraform apply' to make changes.
Use 'terraform state list' to verify resources tracked in remote state.