Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Aug 1, 2022
1 parent 128e495 commit 7dec1c8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions access_keys.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ data "aws_arn" "current" {
}

data "aws_region" "current" {}

data "aws_iam_account_alias" "current" {}
1 change: 1 addition & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7dec1c8

Please sign in to comment.