From 7dec1c8ac2026c2cd552503402ebd9c21da4d980 Mon Sep 17 00:00:00 2001 From: badra001 Date: Mon, 1 Aug 2022 13:49:48 -0400 Subject: [PATCH] fix --- README.md | 1 + access_keys.tf | 8 ++++++-- data.tf | 2 ++ locals.tf | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73af96c..beea888 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ No requirements. | [time_sleep.wait_iam_access_key_v1](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource | | [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source | | [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | +| [aws_iam_account_alias.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_account_alias) | data source | | [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | ## Inputs diff --git a/access_keys.tf b/access_keys.tf index 6b71fbf..77a44bd 100644 --- a/access_keys.tf +++ b/access_keys.tf @@ -1,3 +1,7 @@ +locals { + profile = var.profile == null ? format("%v-%v", local.account_id, local.account_alias) : var.profile +} + resource "aws_iam_access_key" "iam_access_key_v1" { count = var.create_access_keys ? 1 : 0 user = aws_iam_user.user.name @@ -19,13 +23,13 @@ locals { { username = aws_iam_user.user.name region = local.account_environment == "ew" ? "us-east-1" : "us-gov-east-1" - profile = var.profile == null ? "default" : var.profile + profile = local.profile pgp_key_file = local.pgp_key_file_exists ? var.pgp_key_file : "" }) access_key_file = templatefile("${path.module}/templates/access_key.tpl", { username = aws_iam_user.user.name - profile = var.profile == null ? "default" : var.profile + profile = local.profile account_id = local.account_id create_date = join("", aws_iam_access_key.iam_access_key_v1.*.create_date) access_key_id = join("", aws_iam_access_key.iam_access_key_v1.*.id) diff --git a/data.tf b/data.tf index 16506e6..38c7ef4 100644 --- a/data.tf +++ b/data.tf @@ -5,3 +5,5 @@ data "aws_arn" "current" { } data "aws_region" "current" {} + +data "aws_iam_account_alias" "current" {} diff --git a/locals.tf b/locals.tf index 24d3131..3f70f25 100644 --- a/locals.tf +++ b/locals.tf @@ -1,6 +1,7 @@ locals { # account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id account_id = data.aws_caller_identity.current.account_id + account_alias = data.aws_iam_account_alias.current.account_alias account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew" region = data.aws_region.current.name }