terraform-provider-kubernetes
terraform-provider-kubernetes copied to clipboard
Use kubernetes provider with EKS module with one apply
Terraform version, Kubernetes provider version and Kubernetes version
Terraform version: v1.3.2
Kubernetes provider version: 2.14.0
Kubernetes version: 1.21
Terraform configuration
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "18.7.1"
cluster_name = var.cluster_name
cluster_version = var.cluster_version
.
.
.
}
resource "kubernetes_namespace" "production" {
metadata {
name = var.environment
}
}
Question
Hi, Can I provision EKS and then use its credential in my Kubernetes provider? I mean, I want to provision EKS cluster and then apply some manifest on it with one time terraform apply command. I tried this but I got this error message.
│ Error: Provider configuration: cannot load Kubernetes client config
│
│ with provider["registry.terraform.io/hashicorp/kubernetes"],
│ on main.tf line 17, in provider "kubernetes":
│ 17: provider "kubernetes" {
│
│ invalid configuration: [context was not found for specified context: XXXXXXX, cluster has no server defined]
╵
Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!
@fazizsoltani Terraform doesn't support this mechanism of supplying provider attribute values from other resources being create in the same apply. The fact that it sometimes seem to work and other times not only adds to the confusion (depending on the resources involved and the complexity of the whole configuration).
A good explanation from one of the core engineers of Terraform is available here: https://discuss.hashicorp.com/t/provider-configuration-through-interpolation/22538/3
Our recommendation is to split the creation of the cluster and the operations on cluster resources into separate apply steps.
Without further feedback to proceed, we're closing this ticket to maintain clarity in our issue tracker. This closure is purely procedural; we're still interested in addressing your concerns.
Should this issue persist or if you have additional information to share, please feel free to open a new ticket. Your contributions are valuable to us, and we're keen to assist wherever possible.