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

eks: add ephemeral aws_eks_cluster_auth resource #40660

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

bschaatsbergen
Copy link
Member

@bschaatsbergen bschaatsbergen commented Dec 20, 2024

Fixes #40343

Since it’s common to configure the Kubernetes provider by injecting a temporary IAM-compatible token for authenticating to the EKS control-plane (currently done using data.aws_eks_cluster_auth.example.token).

Terraform (1.10) supports referencing ephemeral resource attributes directly in providers. Having an ephemeral variant available of aws_eks_cluster_auth would greatly improve the security posture of Terraform users working with Amazon EKS and the Kubernetes or Helm provider as the temporary obtained IAM token is no longer persisted to the state.

ephemeral "aws_eks_cluster_auth" "example" {
  name = data.aws_eks_cluster.example.id
}

provider "kubernetes" {
  host                   = data.aws_eks_cluster.example.endpoint
  cluster_ca_certificate = base64decode(data.aws_eks_cluster.example.certificate_authority[0].data)
  token                  = ephemeral.aws_eks_cluster_auth.example.token
}

provider "helm" {
  kubernetes {
    host                   = data.aws_eks_cluster.example.endpoint
    cluster_ca_certificate = base64decode(data.aws_eks_cluster.example.certificate_authority[0].data)
    token                  = ephemeral.aws_eks_cluster_auth.example.token
  }
}

Test output:

 $ make testacc TESTARGS='-run=TestAccEKSClusterAuthEphemeral_basic' PKG=eks
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/eks/... -v -count 1 -parallel 20  -run=TestAccEKSClusterAuthEphemeral_basic -timeout 360m
2024/12/20 18:13:48 Initializing Terraform AWS Provider...
=== RUN   TestAccEKSClusterAuthEphemeral_basic
=== PAUSE TestAccEKSClusterAuthEphemeral_basic
=== CONT  TestAccEKSClusterAuthEphemeral_basic
--- PASS: TestAccEKSClusterAuthEphemeral_basic (11.50s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/eks        17.044s

Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added service/eks Issues and PRs that pertain to the eks service. needs-triage Waiting for first response or review from a maintainer. external-maintainer Contribution from a trusted external contributor. labels Dec 20, 2024
@github-actions github-actions bot added the generators Relates to code generators. label Dec 20, 2024
@github-actions github-actions bot added the tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. label Dec 20, 2024
Add return statements in error paths, and reference the EKS cluster name using ValueString to ensure it produces a literal value. This avoids generating the underlying framework’s string literal, which includes quotes and leads to incorrect token generation.
@johnsonaj johnsonaj added new-ephemeral-resource Introduces a new ephemeral resource. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 23, 2024
@bschaatsbergen bschaatsbergen removed the external-maintainer Contribution from a trusted external contributor. label Dec 23, 2024
@github-actions github-actions bot added the external-maintainer Contribution from a trusted external contributor. label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-maintainer Contribution from a trusted external contributor. generators Relates to code generators. new-ephemeral-resource Introduces a new ephemeral resource. service/eks Issues and PRs that pertain to the eks service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[New ephemeral]: aws_eks_cluster_auth should be turned into an ephemeral resource
2 participants