diff --git a/README.md b/README.md index f6266ecc..e2377cf9 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,22 @@ module "s3_bucket" { } ``` +## Terragrunt and `variable "..." { type = any }` + +There is a bug [#1211](https://github.com/gruntwork-io/terragrunt/issues/1211) in Terragrunt related to the way how the variables of type `any` are passed to Terraform. + +This module solves this issue by supporting `jsonencode()`-string in addition to the expected type (`list` or `map`). + +In `terragrunt.hcl` you can write: + +```terraform +inputs = { + bucket = "foobar" # `bucket` has type `string`, no need to jsonencode() + cors_rule = jsonencode([...]) # `cors_rule` has type `any`, so `jsonencode()` is required +} +``` + + ## Examples: * [Complete](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/tree/master/examples/complete) - Complete S3 bucket with most of supported features enabled diff --git a/main.tf b/main.tf index 650ff419..09097344 100644 --- a/main.tf +++ b/main.tf @@ -28,7 +28,7 @@ resource "aws_s3_bucket" "this" { } dynamic "cors_rule" { - for_each = var.cors_rule + for_each = try(jsondecode(var.cors_rule), var.cors_rule) content { allowed_methods = cors_rule.value.allowed_methods @@ -58,7 +58,7 @@ resource "aws_s3_bucket" "this" { } dynamic "grant" { - for_each = var.grant + for_each = try(jsondecode(var.grant), var.grant) content { id = lookup(grant.value, "id", null) @@ -69,7 +69,7 @@ resource "aws_s3_bucket" "this" { } dynamic "lifecycle_rule" { - for_each = var.lifecycle_rule + for_each = try(jsondecode(var.lifecycle_rule), var.lifecycle_rule) content { id = lookup(lifecycle_rule.value, "id", null)