From cbae6fafa83254162ad007ef703befc8d45c228c Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Tue, 25 Aug 2020 22:10:57 -0400 Subject: [PATCH 1/4] use coalesce for kms key lookup --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 197dbb4..8ddd7b3 100644 --- a/main.tf +++ b/main.tf @@ -11,7 +11,7 @@ locals { # Resolve resource names bucket = var.remote_bucket == "" ? aws_s3_bucket.this[0].id : var.remote_bucket - kms_key_id = var.kms_key_id == "" ? aws_kms_key.this[0].arn : var.kms_key_id + kms_key_id = coalesce(var.kms_key_id, aws_kms_key.this[0].arn) } resource "aws_s3_bucket" "this" { From 2734d7e8d198cf666aba3e8e5e49a0eea9bf5be5 Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Tue, 25 Aug 2020 22:17:27 -0400 Subject: [PATCH 2/4] use try --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 8ddd7b3..12de8b1 100644 --- a/main.tf +++ b/main.tf @@ -11,7 +11,7 @@ locals { # Resolve resource names bucket = var.remote_bucket == "" ? aws_s3_bucket.this[0].id : var.remote_bucket - kms_key_id = coalesce(var.kms_key_id, aws_kms_key.this[0].arn) + kms_key_id = coalesce(var.kms_key_id, try(aws_kms_key.this[0].arn, null)) } resource "aws_s3_bucket" "this" { From 85cd46bee0e00f94f6fe057461adc14282001426 Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Tue, 25 Aug 2020 22:30:02 -0400 Subject: [PATCH 3/4] add dumb carejourney hack --- main.tf | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 12de8b1..98b019b 100644 --- a/main.tf +++ b/main.tf @@ -10,8 +10,12 @@ locals { iam_account_principals = formatlist("arn:aws:iam::%s:root", local.account_ids) # Resolve resource names - bucket = var.remote_bucket == "" ? aws_s3_bucket.this[0].id : var.remote_bucket - kms_key_id = coalesce(var.kms_key_id, try(aws_kms_key.this[0].arn, null)) + bucket = var.remote_bucket == "" ? aws_s3_bucket.this[0].id : var.remote_bucket + kms_key_id = coalesce( + var.kms_key_id, + try(aws_kms_key.this[0].arn, null), + "arn:aws:kms:us-east-1:282211067113:key/51965291-49aa-4743-86c9-ab0acfe3c720" # dumb carejourney hack + ) } resource "aws_s3_bucket" "this" { From 3fc59a4338a70e01d3ef3b8c4a10f220fefb35f5 Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Tue, 25 Aug 2020 22:37:12 -0400 Subject: [PATCH 4/4] remove defaults for carejourney --- README.md | 8 ++++---- main.tf | 3 +-- variables.tf | 4 ---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c3f23d5..780cc06 100644 --- a/README.md +++ b/README.md @@ -71,14 +71,14 @@ region = "us-east-1" | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| kms\_key\_id | ARN for KMS key for all encryption operations. | `string` | n/a | yes | +| remote\_bucket | If specified, the remote bucket will be used for the backend. A new bucket will not be created | `string` | n/a | yes | +| table | Name of Dynamo Table to create | `string` | n/a | yes | +| tags | Mapping of any extra tags you want added to resources | `map(string)` | n/a | yes | | allowed\_account\_ids | Account IDs that are allowed to access the bucket/KMS key | `list(string)` | `[]` | no | | bucket | Name of bucket to create (do not provide if using `remote_bucket`) | `string` | `""` | no | -| kms\_key\_id | ARN for KMS key for all encryption operations. | `string` | `""` | no | | logging\_target\_bucket | The name of the bucket that will receive the log objects | `string` | `null` | no | | logging\_target\_prefix | A key prefix for log objects | `string` | `"TFStateLogs/"` | no | -| remote\_bucket | If specified, the remote bucket will be used for the backend. A new bucket will not be created | `string` | `""` | no | -| table | Name of Dynamo Table to create | `string` | `"tf-locktable"` | no | -| tags | Mapping of any extra tags you want added to resources | `map(string)` | `{}` | no | ## Outputs diff --git a/main.tf b/main.tf index 98b019b..ca00804 100644 --- a/main.tf +++ b/main.tf @@ -13,8 +13,7 @@ locals { bucket = var.remote_bucket == "" ? aws_s3_bucket.this[0].id : var.remote_bucket kms_key_id = coalesce( var.kms_key_id, - try(aws_kms_key.this[0].arn, null), - "arn:aws:kms:us-east-1:282211067113:key/51965291-49aa-4743-86c9-ab0acfe3c720" # dumb carejourney hack + try(aws_kms_key.this[0].arn, null) ) } diff --git a/variables.tf b/variables.tf index 304d857..128cddc 100644 --- a/variables.tf +++ b/variables.tf @@ -11,7 +11,6 @@ variable "bucket" { } variable "kms_key_id" { - default = "" description = "ARN for KMS key for all encryption operations." type = string } @@ -29,19 +28,16 @@ variable "logging_target_prefix" { } variable "remote_bucket" { - default = "" description = "If specified, the remote bucket will be used for the backend. A new bucket will not be created" type = string } variable "table" { - default = "tf-locktable" description = "Name of Dynamo Table to create" type = string } variable "tags" { - default = {} description = "Mapping of any extra tags you want added to resources" type = map(string) }