Creating an EKS cluster and Kubernetes resources in one stack: `Error: Get "http://localhost/api/v1/namespaces/app": dial tcp [::1]:80: connect: connection refused`.
AdvancedTroubleshootingDependencies, Cycles and Providers
Answer
Likely causes → The kubernetes provider was configured from values unknown at plan time (cluster not created yet, or being replaced), so it fell back to defaults (localhost). Also happens when the cluster is replaced in the same plan.
Diagnose → Is the cluster being created/replaced in this plan? Does the provider use module.eks.cluster_endpoint?
Fix → Apply in two stages (cluster stack first, workloads stack second), and configure the provider with exec auth:
provider "kubernetes" {
host = data.aws_eks_cluster.this.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.this.certificate_authority[0].data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
args = ["eks", "get-token", "--cluster-name", "prod"]
}
}
Prevent → Keep cluster infrastructure and in-cluster resources in separate states.
More on Dependencies, Cycles and Providers
`Error: Cycle: aws_security_group.app, aws_security_group.db`.Beginner`Error: Cycle: local.name_prefix, local.tags`.BeginnerA cycle appears only after adding `depends_on = [module.app]` to a module. The error lists dozens of nodes.IntermediateAdding `create_before_destroy = true` to a launch template causes `Error: Cycle: ... (destroy deposed ...)`.Advanced`terraform init` fails: `Could not retrieve the list of available versions for provider hashicorp/aws: no available releases match the given constraints ~> 4.0, >= 5.30.0`.Intermediate`Error: Inconsistent dependency lock file` with `locked version selection 5.31.0 doesn't match the updated version constraints ">= 5.40.0"`.Beginner