Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kubernetes provider with EKS module with one apply #1865

Closed
fazizsoltani opened this issue Oct 10, 2022 · 3 comments
Closed

Use kubernetes provider with EKS module with one apply #1865

fazizsoltani opened this issue Oct 10, 2022 · 3 comments
Labels

Comments

@fazizsoltani
Copy link

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]
╵
@github-actions
Copy link

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!

@github-actions github-actions bot added the stale label Oct 11, 2023
@alexsomesan
Copy link
Member

@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.

@iBrandyJackson
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants