hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[New Data Source]: aws_profile #31311

Open interone-ms opened 1 year ago

interone-ms commented 1 year ago

Description

Similarly to aws_region, I'd like to be able to dynamically retrieve the AWS CLI profile being in use.

My use case is a module that creates an aws_eks_cluster, which has an additional block provisioning the local .kube/config file - it requires specifying the profile and currently uses a variable that needs to be passed through to the module:

resource "null_resource" "cluster-config" {
  triggers = {
    cluster      = aws_eks_cluster.cluster.endpoint
    cluster-cert = aws_eks_cluster.cluster.certificate_authority[0].data
  }
  provisioner "local-exec" {
    command = "aws eks update-kubeconfig --region ${data.aws_region.current.name} --name ${var.cluster-name} --profile ${var.aws-profile}"
  }
}

Requested Resource(s) and/or Data Source(s)

Potential Terraform Configuration

provider "aws" {
  region  = "eu-central-1"
  profile = "example"
}
data "aws_profile" "current" {}

resource "aws_eks_cluster" "cluster" {
# ...
}
resource "null_resource" "cluster-config" {
  triggers = {
    cluster      = aws_eks_cluster.cluster.endpoint
    cluster-cert = aws_eks_cluster.cluster.certificate_authority[0].data
  }
  provisioner "local-exec" {
    command = "aws eks update-kubeconfig --region ${data.aws_region.current.name} --name ${var.cluster-name} --profile ${data.aws_profile.current.name}"
  }
}

References

https://github.com/awsdocs/aws-cli-user-guide/blob/main/doc_source/cli-configure-profiles.md

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

LumaC0 commented 9 months ago

I'd like to implement this.

bryantbiggs commented 1 week ago

FYI - I don't think this is specific to the EKS service so the GitHub label is a bit misleading here