Skip to content

Commit e83b8b0

Browse files
authored
feat: Added workaround for variable type any (terraform-aws-modules#79)
1 parent a3ac47c commit e83b8b0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ module "s3_bucket" {
6969
}
7070
```
7171

72+
## Terragrunt and `variable "..." { type = any }`
73+
74+
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.
75+
76+
This module solves this issue by supporting `jsonencode()`-string in addition to the expected type (`list` or `map`).
77+
78+
In `terragrunt.hcl` you can write:
79+
80+
```terraform
81+
inputs = {
82+
bucket = "foobar" # `bucket` has type `string`, no need to jsonencode()
83+
cors_rule = jsonencode([...]) # `cors_rule` has type `any`, so `jsonencode()` is required
84+
}
85+
```
86+
87+
7288
## Examples:
7389

7490
* [Complete](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/tree/master/examples/complete) - Complete S3 bucket with most of supported features enabled

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "aws_s3_bucket" "this" {
2828
}
2929

3030
dynamic "cors_rule" {
31-
for_each = var.cors_rule
31+
for_each = try(jsondecode(var.cors_rule), var.cors_rule)
3232

3333
content {
3434
allowed_methods = cors_rule.value.allowed_methods
@@ -58,7 +58,7 @@ resource "aws_s3_bucket" "this" {
5858
}
5959

6060
dynamic "grant" {
61-
for_each = var.grant
61+
for_each = try(jsondecode(var.grant), var.grant)
6262

6363
content {
6464
id = lookup(grant.value, "id", null)
@@ -69,7 +69,7 @@ resource "aws_s3_bucket" "this" {
6969
}
7070

7171
dynamic "lifecycle_rule" {
72-
for_each = var.lifecycle_rule
72+
for_each = try(jsondecode(var.lifecycle_rule), var.lifecycle_rule)
7373

7474
content {
7575
id = lookup(lifecycle_rule.value, "id", null)

0 commit comments

Comments
 (0)