jenkins-x/terraform-aws-eks-jx

Deploy fails when using aws profile

mestuddtc opened this issue · 4 comments

Summary

I am following the EKS on AWS setup instructions to evaluate jenkinsx.
I have multiple aws profiles across multiple aws accounts. I set the correct profile to use in the infrastructure repo variables. Running terraform apply fails with an error.

Steps to reproduce the behavior

  1. Set up ~/.aws/credentials with "default" profile in one account and "second" profile in a different account.
  2. Create infrastructure repo https://github.com/jx3-gitops-repositories/jx3-terraform-eks/generate
  3. Set default = "second" for "profile" variable in variables.tf
  4. Run terraform init && terraform apply

Expected behavior

Terraform commands complete successfully.

Actual behavior

Terraform fails with error:

╷
│ Error: local-exec provisioner error
│
│   with module.eks-jx.module.cluster.null_resource.kubeconfig,
│   on .terraform/modules/eks-jx/modules/cluster/main.tf line 150, in resource "null_resource" "kubeconfig":
│  150:   provisioner "local-exec" {
│
│ Error running command 'aws eks update-kubeconfig --name tf-jx-capital-sunfish --region=us-east-1': exit status 254. Output:
│ An error occurred (ResourceNotFoundException) when calling the DescribeCluster operation: No cluster found for name: tf-jx-capital-sunfish.
│

Running aws eks update-kubeconfig --name tf-jx-capital-sunfish --region=us-east-1 --profile second succeeds.

Terraform version

The output of terraform version is:

Terraform v1.0.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.51.0
+ provider registry.terraform.io/hashicorp/cloudinit v2.2.0
+ provider registry.terraform.io/hashicorp/helm v2.2.0
+ provider registry.terraform.io/hashicorp/kubernetes v2.3.2
+ provider registry.terraform.io/hashicorp/local v2.1.0
+ provider registry.terraform.io/hashicorp/null v3.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/hashicorp/template v2.2.0

Module version

1.15.37

Operating system

MacOS

We should add the profile argument to that command. You can get around this issue by running:

AWS_PROFILE=second terraform init
AWS_PROFILE=second terraform apply

I experienced this same error too, I'm going to throw spaghetti at the wall with a proposed fix and see if it sticks.

This should be fixed now, closing.

It's working for me now. Thanks!