Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Added workaround for variable type any #79

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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