Skip to content

Commit

Permalink
feat: Added workaround for variable type any (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko authored Apr 9, 2021
1 parent a3ac47c commit e83b8b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit e83b8b0

Please # to comment.