Invalid token from aws_eks_cluster_auth

Viewed 280

I was following the Terraform docs for creating a EKS cluster. The resources in my terraform template are all created, but I have an issue with the aws_eks_cluster_auth token. Instead of a valid token, I am getting a token that after decoding contains this in the payload:

https://sts.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15 &X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIATBVLFFVRYLSI2QWE%2F20210715%2Fus-east-1%2Fsts%2Faws4_request&X-Amz-Date=20210715T100255Z &X-Amz-Expires=0&X-Amz-SignedHeaders=host%3Bx-k8s-aws-id

When I open the link I get a SignatureDoesNotMatch error displayed.

This is the code from my terraform template:

 data "aws_eks_cluster" "cluster" {
   name = module.my-cluster.cluster_id
 }
 
 data "aws_eks_cluster_auth" "cluster" {
    name = module.my-cluster.cluster_id
 }
 
 provider "kubernetes" {
   host   = data.aws_eks_cluster.cluster.endpoint
   cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
   token  = data.aws_eks_cluster_auth.cluster.token
   load_config_file   = false
   version= "~> 1.9"
 }
 
 provider "aws" {
     profile = "my-aws-profile"
     region = "eu-central-1"
 }
 
 module "my-cluster" {
   source  = "terraform-aws-modules/eks/aws"
   cluster_name = "cluster-name-123"
   cluster_version = "1.17"
   subnets = var.private_subnets
   vpc_id = var.vpc_id
}
 
 // output.tf
 output "certificateAuthorityData" {
   value = data.aws_eks_cluster.cluster.certificate_authority.0.data
 }
 output "endpoint" {
    value = data.aws_eks_cluster.cluster.endpoint
 }
 output "apiToken" {
   value = data.aws_eks_cluster_auth.cluster.token
   sensitive = true
 }

The output parameters certificateAuthorityData and endpoint are fine, but apiToken is an invalid token. I can't tell what I am doing wrong.

0 Answers
Related