terragrunt
terragrunt copied to clipboard
`jsonencode` bad return
Describe the bug
Using jsonencode with variable value in inputs block generate bad json
To Reproduce
Example using this module : https://github.com/cloudposse/terraform-aws-cloudwatch-events
The jsonencode function is used in the module: https://github.com/cloudposse/terraform-aws-cloudwatch-events/blob/main/main.tf#L15
In native terraform
provider "aws" {
region = "eu-west-3"
}
module "cloudwatch_event" {
source = "cloudposse/cloudwatch-events/aws"
version = "0.6.1"
name = "test"
cloudwatch_event_rule_description = "This is event rule description."
cloudwatch_event_rule_pattern = {
"source" = ["aws.autoscaling"]
"detail-type" = ["EC2 Instance Launch Successful", "EC2 Instance Terminate Successful"]
"detail" = {
"AutoScalingGroupName" = ["test"]
}
}
cloudwatch_event_target_arn = "arn:aws:lambda:eu-west-3:000000000000:function:fake"
context = module.this.context
}
I get this for the cloudwatch rule event_pattern when I run terragrunt plan and it works with apply.
# module.cloudwatch_event.aws_cloudwatch_event_rule.this will be created
+ resource "aws_cloudwatch_event_rule" "this" {
+ arn = (known after apply)
+ description = "This is event rule description."
+ event_bus_name = "default"
+ event_pattern = jsonencode(
{
+ detail = {
+ AutoScalingGroupName = [
+ "test",
]
}
+ detail-type = [
+ "EC2 Instance Launch Successful",
+ "EC2 Instance Terminate Successful",
]
+ source = [
+ "aws.autoscaling",
]
}
)
+ id = (known after apply)
+ is_enabled = true
+ name = "test"
+ name_prefix = (known after apply)
+ tags_all = (known after apply)
}
With Terragrunt
terraform {
source = "github.com/cloudposse/terraform-aws-cloudwatch-events//.?ref=0.6.1"
}
### Inputs
inputs = {
name = "test"
cloudwatch_event_target_arn = "arn:aws:lambda:eu-west-3:000000000000:function:fake"
cloudwatch_event_rule_pattern = {
"source" = ["aws.autoscaling"]
"detail-type" = ["EC2 Instance Launch Successful", "EC2 Instance Terminate Successful"]
"detail" = {
"AutoScalingGroupName" = ["test"]
}
}
}
I get this for the cloudwatch rule event_pattern when I run terraform plan and it fails with apply.
# aws_cloudwatch_event_rule.this will be created
+ resource "aws_cloudwatch_event_rule" "this" {
+ arn = (known after apply)
+ description = "test"
+ event_bus_name = "default"
+ event_pattern = "\"{\\\"detail\\\":{\\\"AutoScalingGroupName\\\":[\\\"test\\\"]},\\\"detail-type\\\":[\\\"EC2 Instance Launch Successful\\\",\\\"EC2 Instance Terminate Successful\\\"],\\\"source\\\":[\\\"aws.autoscaling\\\"]}\""
+ id = (known after apply)
+ is_enabled = true
+ name = "test"
+ name_prefix = (known after apply)
+ tags_all = (known after apply)
}
Expected behavior
The value of event_pattern is badly formatted using Terragrunt
Nice to have
- [x] Terminal output
- [ ] Screenshots
Versions
- Terragrunt version: v1.6.3
- Terraform version: v0.53.2
- Environment details (Ubuntu 20.04, Windows 10, etc.): MacOS 14.1
Additional context
- provider registry.terraform.io/hashicorp/aws v5.24.0
- provider registry.terraform.io/hashicorp/local v2.4.0
After several more tests, it seems that this happens when jsonencode is used in a module, and not directly in terragrunt.hcl.
Any update? I am facing the same issue :(
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for raising this issue.