Terraform errors

Terraform and OpenTofu errors — state locks, providers, lock files, references and plans.

CodeErrorWhat it means
Error loading state: AccessDenied (S3 backend) Terraform: Error: Failed to load state: AccessDenied: Access Denied / Error refreshing state: AccessDenied status code: 403 Terraform can't read/write the S3 bucket (or DynamoDB table) that stores state — IAM permissions or wrong cre…
UnauthorizedOperation / AccessDenied during Terraform apply Terraform: Error: creating EC2 Instance: UnauthorizedOperation: You are not authorized to perform this operation. User: arn:aws:iam::123:user/ci is not authorized to perform: ec2:RunInstances The IAM identity used by Terraform lacks a permission needed for that resource.
Invalid AWS Region Terraform: Error: Invalid AWS Region: us-east-3 / Error: configuring Terraform AWS Provider: validating provider credentials: operation error STS: GetCallerIdentity The `region` is invalid/unavailable, or the provider can't reach AWS endpoints to validate credentials.
Google provider: could not find default credentials Terraform: Error: Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block. No credentials loaded The Google provider has no credentials (ADC, service account key, impersonation).
Failed to install provider (download failed) Terraform: Error: Failed to install provider — Error while installing hashicorp/aws v5.40.0: could not query provider registry / Get "https://releases.hashicorp.com/...": dial tcp: i/o timeout Terraform found the provider version but couldn't download/verify the package.
Failed to query available provider packages Terraform: Error: Failed to query available provider packages — Could not retrieve the list of available versions for provider hashicorp/aws: no available releases match the given constraints `terraform init` can't find a provider version matching your constraints (or can't reach the registry).
Your query returned no results (data source) Terraform: Error: Your query returned no results. Please change your search criteria and try again. A data source (e.g. `aws_ami`, `aws_vpc`) found nothing matching its filters.
Error 403: API has not been used in project (Terraform) Terraform: Error: Error creating Network: googleapi: Error 403: Compute Engine API has not been used in project 123 before or it is disabled Terraform called a Google API that isn't enabled in the project.
No valid credential sources found (AWS provider) Terraform: Error: No valid credential sources found — failed to refresh cached credentials, no EC2 IMDS role found / Error: configuring Terraform AWS Provider: no valid credential sources The AWS provider found no credentials (env vars, shared config, SSO, role, instance profile).
Backend configuration changed (migrate or reconfigure) Terraform: Error: Backend configuration changed — A change in the backend configuration has been detected, which may require migrating existing state The saved backend settings in `.terraform` differ from the current configuration.
Invalid for_each argument (keys cannot be determined until apply) Terraform: Error: Invalid for_each argument — The "for_each" map includes keys derived from resource attributes that cannot be determined until apply `for_each` keys depend on values only known after apply, so Terraform can't plan which instances exist.
No value for required variable Terraform: Error: No value for required variable — The root module input variable "region" is not set, and has no default value A variable without a default wasn't supplied.
BucketNotEmpty: bucket you tried to delete is not empty Terraform: Error: deleting S3 Bucket (my-bucket): BucketNotEmpty: The bucket you tried to delete is not empty Terraform can't delete an S3 bucket that still holds objects (or versions).
S3 backend: NoSuchBucket / bucket does not exist Terraform: Error: Failed to get existing workspaces: S3 bucket "my-tf-state" does not exist / NoSuchBucket: The specified bucket does not exist The S3 bucket configured as the state backend doesn't exist (or is in another region/account).
Invalid target address / No matching objects found (state commands) Terraform: Error: Invalid target address — No matching objects found. To view the available instances, use "terraform state list" A state/target command referenced an address that doesn't exist in state.
Output refers to sensitive values Terraform: Error: Output refers to sensitive values — a root module output containing sensitive data must be explicitly marked as sensitive An output (or module output) exposes a value derived from a sensitive variable/attribute without `sensitive =…
Inconsistent dependency lock file Terraform: Error: Inconsistent dependency lock file — provider x: required by this configuration but no version is selected The .terraform.lock.hcl file doesn’t match the providers/versions your configuration now requires, or init wa…
Provider produced invalid plan / inconsistent final plan Terraform: Error: Provider produced invalid plan — provider produced an invalid plan for aws_x.y, but we are tolerating it because it is using the legacy plugin SDK The provider changed planned values between plan and apply (a provider bug), so Terraform aborts.
Error acquiring the state lock Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked Another Terraform run holds the state lock, or a previous run crashed and left the lock behind.
Error building ARM Config: obtain subscription from Azure CLI Terraform: Error: building AzureRM Client: obtaining subscription ID / Please run 'az login' to setup account The AzureRM provider can't find Azure credentials or a subscription.
Reference to undeclared resource Terraform: Error: Reference to undeclared resource / Reference to undeclared input variable The configuration refers to a resource, data source, variable or module output that isn’t declared in this mo…
state snapshot was created by a newer Terraform version Terraform: Error: state snapshot was created by Terraform v1.9.0, which is newer than current v1.6.6; upgrade to Terraform v1.9.0 or greater to work with this state The remote/local state was last written by a newer Terraform CLI than the one you're running.
Unsupported argument: An argument named "x" is not expected here Terraform: Error: Unsupported argument — An argument named "enable_foo" is not expected here A resource/module block uses an argument the provider/module schema doesn't have.
timeout while waiting for state to become 'available' Terraform: Error: waiting for RDS DB Instance create: timeout while waiting for state to become 'available' (last state: 'creating', timeout: 40m0s) The resource didn't reach the target state before the provider's timeout.
Invalid count argument (value unknown until apply) Terraform: Error: Invalid count argument — The "count" value depends on resource attributes that cannot be determined until apply `count` depends on something unknown at plan time, so Terraform can't decide how many instances to create.
Module not installed Terraform: Error: Module not installed — This module is not yet installed. Run "terraform init" to install all modules required by this configuration A module block references a module that hasn't been downloaded to `.terraform/modules`.
Moved object still exists Terraform: Error: Moved object still exists — This statement declares a move from aws_x.old, but that resource instance is still declared at main.tf A `moved` block points at an address that is still present in the configuration.
Error reading resource: not found (deleted outside Terraform) Terraform: Error: reading EC2 Instance (i-0abc): couldn't find resource / 404 ResourceNotFound during refresh A resource tracked in state no longer exists in the cloud (deleted manually) or can't be read with current cr…
Unsupported attribute: This object does not have an attribute named Terraform: Error: Unsupported attribute — This object has no argument, nested block, or exported attribute named "foo" An expression references an attribute that the resource/data source/module output doesn't expose.
Invalid function argument Terraform: Error: Invalid function argument — Invalid value for "list" parameter: list of string required / Call to function "lookup" failed A built-in function got a wrong type/value (empty list, missing key, wrong type).
Invalid index: The given key does not identify an element Terraform: Error: Invalid index — The given key does not identify an element in this collection value You indexed a map/list/set with a key or position that doesn't exist.
Missing required argument Terraform: Error: Missing required argument — The argument "ami" is required, but no definition was found A resource/module block lacks an argument the schema requires.
Provider produced inconsistent result after apply Terraform: Error: Provider produced inconsistent result after apply — When applying changes to aws_x.y, provider produced an unexpected new value: Root resource was present, but now absent After creating/updating a resource, the provider returned values that don't match what Terraform planned — us…
Unsupported Terraform Core version Terraform: Error: Unsupported Terraform Core version — This configuration does not support Terraform version 1.5.7 The installed Terraform CLI doesn't satisfy `required_version` in the configuration (or a module).
Resource is tainted and must be replaced Terraform: # aws_instance.web is tainted, so must be replaced — -/+ destroy and then create replacement A previous apply failed during creation, so Terraform marked the resource tainted and will recreate it.
Workspace doesn't exist Terraform: Error: Failed to select workspace: workspace "staging" doesn't exist / Currently selected workspace "x" does not exist The workspace you selected (or that `.terraform/environment` points to) isn't present in the backend.
Inconsistent conditional result types Terraform: Error: Inconsistent conditional result types — The true and false result expressions must have consistent types A `cond ? a : b` expression returns values of different types/shapes.
Kubernetes cluster unreachable (provider/helm) Terraform: Error: Kubernetes cluster unreachable: Get "http://localhost/version": dial tcp 127.0.0.1:80: connect: connection refused The Kubernetes/Helm provider can't connect to the cluster (no config, cluster not ready at plan time, expired…
Error: Cycle (dependency cycle) Terraform: Error: Cycle: aws_security_group.a, aws_security_group.b Resources reference each other (directly or indirectly), so Terraform can't order them.
Duplicate resource configuration / variable declaration Terraform: Error: Duplicate resource "aws_s3_bucket" configuration — A aws_s3_bucket resource named "logs" was already declared at main.tf:1 The same resource, variable, output or provider is declared twice in the module.
DynamoDB lock table not found (ResourceNotFoundException) Terraform: Error: Error acquiring the state lock: ResourceNotFoundException: Requested resource not found / failed to retrieve lock info The S3 backend's `dynamodb_table` doesn't exist, so locking fails.
Invalid character / Argument or block definition required Terraform: Error: Invalid character — This character is not used within the language / Error: Argument or block definition required The `.tf` file has HCL syntax errors (stray characters, bad quotes, missing braces/commas).
Provider configuration not present (removed resource) Terraform: Error: Provider configuration not present — its original provider configuration is required, but it has been removed A resource in state needs a provider configuration (alias) that no longer exists in the code.
DependencyViolation: resource has dependent objects (destroy) Terraform: Error: deleting EC2 VPC (vpc-0abc): DependencyViolation: The vpc 'vpc-0abc' has dependencies and cannot be deleted Destroy failed because something else still uses the resource (ENIs, subnets, gateways, security group rules).
Failed to download module (git/registry/path) Terraform: Error: Failed to download module — Could not download module "vpc" (main.tf:1) source code from "git::https://github.com/org/repo.git": error downloading Terraform couldn't fetch a module's source (git auth, wrong ref/path, registry, network).
Backend initialization required Terraform: Error: Backend initialization required, please run "terraform init" — Reason: Initial configuration of the requested backend "s3" Terraform needs `terraform init` to set up the backend (new directory, changed backend config, missing `.terr…
Cannot import non-existent remote object Terraform: Error: Cannot import non-existent remote object — While attempting to import an existing object to "aws_s3_bucket.logs", the provider detected that no object exists with the given id `terraform import` (or an import block) used an ID that the provider can't find.
Error creating resource: already exists (needs import) Terraform: Error: creating S3 Bucket (my-bucket): BucketAlreadyOwnedByYou / EntityAlreadyExists: Role with name x already exists The resource exists outside Terraform's state (created manually or by another stack), so create fails.
Instance cannot be destroyed (lifecycle.prevent_destroy) Terraform: Error: Instance cannot be destroyed — Resource aws_db_instance.prod has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed The plan would destroy a resource protected with `lifecycle { prevent_destroy = true }`.
Invalid value for input variable Terraform: Error: Invalid value for variable — "instance_type" must be a t3 type / The given value is not suitable for var.x declared at variables.tf:1,1-17: string required A variable value failed its type or `validation` block.
Saved plan is stale Terraform: Error: Saved plan is stale — The given plan file can no longer be applied because the state was changed by another operation after the plan was created The state changed between `terraform plan -out` and `terraform apply planfile`.
Unsupported block type: Blocks of type "x" are not expected here Terraform: Error: Unsupported block type — Blocks of type "versioning" are not expected here A nested block doesn't exist in that resource's schema (renamed, removed or misplaced).
Error running command: exit status 1 (local-exec/remote-exec) Terraform: Error: local-exec provisioner error — Error running command './deploy.sh': exit status 1. Output: ... A `local-exec`/`remote-exec` provisioner command failed, so the resource is marked tainted.