From af5909e39b1fddafc48f1795c26aaf6426c280df Mon Sep 17 00:00:00 2001 From: xpk Date: Thu, 18 Aug 2022 08:23:50 +0800 Subject: [PATCH] UPD: removing unnecessary input variables --- modules/terraform-setup/examples/main.tf | 9 ++++++--- modules/terraform-setup/main.tf | 4 ++-- modules/terraform-setup/variables.tf | 3 +-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/terraform-setup/examples/main.tf b/modules/terraform-setup/examples/main.tf index 7c2e800..ec35058 100644 --- a/modules/terraform-setup/examples/main.tf +++ b/modules/terraform-setup/examples/main.tf @@ -1,5 +1,4 @@ variable "aws-region" {} -variable "aws-region-short" {} variable "customer-name" {} variable "project" {} variable "application" {} @@ -30,7 +29,12 @@ terraform { } locals { - resource-prefix = "${var.environment}-${var.aws-region-short}-${var.customer-name}-${var.project}" + aws-region-short = lookup(module.aws-region-short.region-map, var.aws-region) + resource-prefix = "${var.environment}-${local.aws-region-short}-${var.customer-name}-${var.project}" +} + +module aws-region-short { + source = "git::https://xpk.headdesk.me/git/xpk/terraform.aws-baseline-infra//modules/util/aws-region-short" } module "terraform-state-store" { @@ -38,7 +42,6 @@ module "terraform-state-store" { enable-bucket-versioning = true transition-ia-days = 30 bucket-acl = "private" - resource-prefix = local.resource-prefix ddb-table-name = "${local.resource-prefix}-tflock" bucket-name = "${local.resource-prefix}-tfstate" } \ No newline at end of file diff --git a/modules/terraform-setup/main.tf b/modules/terraform-setup/main.tf index fe55238..488342d 100644 --- a/modules/terraform-setup/main.tf +++ b/modules/terraform-setup/main.tf @@ -85,8 +85,8 @@ resource "aws_s3_bucket_policy" "bucket-policy" { "Action": "s3:*", "Effect": "Allow", "Resource": [ - "arn:aws:s3:::${var.resource-prefix}-tfstate/*", - "arn:aws:s3:::${var.resource-prefix}-tfstate" + "arn:aws:s3:::${var.bucket-name}/*", + "arn:aws:s3:::${var.bucket-name}-tfstate" ], "Principal": { "AWS": [ diff --git a/modules/terraform-setup/variables.tf b/modules/terraform-setup/variables.tf index eb2070e..77fd1ce 100644 --- a/modules/terraform-setup/variables.tf +++ b/modules/terraform-setup/variables.tf @@ -12,5 +12,4 @@ variable "bucket-acl" { variable "enable-bucket-versioning" { default = true } -variable "bucket-name" {} -variable "resource-prefix" {} \ No newline at end of file +variable "bucket-name" {} \ No newline at end of file