Terraform Cloud requires that an organization be specified in your cloud block configuration. This error occurs when you haven't configured which Terraform Cloud organization your infrastructure belongs to.
Terraform Cloud organizes all workspaces, state, and team management within organizations. An organization is a container for your Terraform infrastructure, teams, and permissions. When you use Terraform Cloud for state storage and remote operations, you must explicitly declare which organization your configuration belongs to. Terraform cannot proceed without knowing the target organization, as it needs to authenticate your access and manage state in the correct workspace.
Update your Terraform configuration (typically in main.tf or a separate backend configuration file) to include the organization attribute:
terraform {
cloud {
organization = "my-org"
workspaces {
name = "my-workspace"
}
}
}Replace "my-org" with your actual Terraform Cloud organization name. You can find your organization name in the Terraform Cloud web UI (app.terraform.io) in the top navigation or at https://app.terraform.io/app/{org-name}/workspaces.
If you want to use the same configuration across multiple organizations or keep sensitive values out of version control, use the TF_CLOUD_ORGANIZATION environment variable:
export TF_CLOUD_ORGANIZATION=my-org
terraform initIn your Terraform configuration, create an empty cloud block:
terraform {
cloud {
workspaces {
name = "my-workspace"
}
}
}Terraform will read the organization from the environment variable. This is useful in CI/CD pipelines where organization names may vary by environment.
Ensure you're authenticated to Terraform Cloud and the organization exists:
1. Run terraform login to authenticate:
terraform loginThis creates a credentials file at ~/.terraform.d/credentials.tfrc.json with your API token.
2. Visit https://app.terraform.io/app and verify your organization exists. If you don't have an organization, create one by signing up or asking an organization admin to invite you.
3. Verify the organization slug matches exactly (case-sensitive) in your configuration.
If you're using partial backend configuration (for example, in a CI/CD pipeline), ensure all required organization settings are provided:
# Using -cloud-config flags (if using legacy backend syntax)
terraform init -backend-config="organization=my-org"
# Or set via environment variable
export TF_CLOUD_ORGANIZATION=my-org
terraform initNote: The modern approach is to use the cloud block in your configuration with environment variables for dynamic values, rather than command-line flags.
If you're using the older remote backend syntax and need to switch to the cloud block:
Old syntax:
terraform {
backend "remote" {
organization = "my-org"
workspaces {
name = "my-workspace"
}
}
}New syntax:
terraform {
cloud {
organization = "my-org"
workspaces {
name = "my-workspace"
}
}
}After updating, run:
terraform init -migrate-stateThis migrates your state from the old backend to the cloud block while maintaining compatibility.
Organization vs Account: Terraform Cloud organizations are separate from Terraform Cloud user accounts. A single user account can belong to multiple organizations. Each organization has its own workspaces, state, and team permissions.
Workspace Configuration: The cloud block also requires workspace configuration. You can use either a fixed workspace name or a prefix pattern that matches multiple workspaces:
# Fixed workspace
workspaces {
name = "production"
}
# Prefix pattern
workspaces {
prefix = "env-"
}Terraform Enterprise: If using Terraform Enterprise (self-hosted), you also need to specify the hostname:
cloud {
hostname = "tfe.example.com"
organization = "my-org"
workspaces {
name = "my-workspace"
}
}MFA/Access Requirements: If your Terraform Cloud organization requires multi-factor authentication, ensure your API token user has MFA configured. Some organizations also restrict who can modify infrastructure—verify you have the appropriate permissions before attempting apply operations.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform