gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.09k stars 981 forks source link

Empty list being passed to module as null #3369

Closed dmurvihill closed 2 months ago

dmurvihill commented 2 months ago

Describe the bug

In terragrunt 0.65.0 and later, an empty set or empty list in the terragrunt inputs block is passed to the module as a null.

Steps To Reproduce

Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.

# terragrunt.hcl

terraform {
  source = "./module"
}

inputs = {
  lists = []
  sets  = {}
}
# module/main.tf

variable "lists" {
  type    = list(string)
  default = []
}

variable "sets" {
  type    = map(string)
  default = {}
}

output "lists" {
  value = var.lists
}

output "sets" {
  value = var.sets
}
dolan@Dolans-MacBook-Pro repro-terragrunt-null-thing % terragrunt --version
terragrunt version v0.65.0
dolan@Dolans-MacBook-Pro repro-terragrunt-null-thing % terragrunt plan     

No changes. Your infrastructure matches the configuration.

OpenTofu has compared your real infrastructure against your configuration and
found no differences, so no changes are needed.

The module is getting null for both variables.

Expected behavior

It works correctly in 0.64:

dolan@Dolans-MacBook-Pro repro-terragrunt-null-thing % terragrunt --version
terragrunt version v0.64.0
dolan@Dolans-MacBook-Pro repro-terragrunt-null-thing % terragrunt plan

Changes to Outputs:
  + lists = []
  + sets  = {}

You can apply this plan to save these new output values to the OpenTofu
state, without changing any real infrastructure.

Nice to haves

Versions

Additional context

It also works correctly in OpenTofu and Terraform:

# example.tfvars

lists = []
sets  = {}
dolan@Dolans-MacBook-Pro module % tofu init && tofu plan -var-file ../example.tfvars 

Initializing the backend...

Initializing provider plugins...

OpenTofu has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.

OpenTofu has been successfully initialized!

You may now begin working with OpenTofu. Try running "tofu plan" to see
any changes that are required for your infrastructure. All OpenTofu commands
should now work.

If you ever set or change modules or backend configuration for OpenTofu,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Changes to Outputs:
  + lists = []
  + sets  = {}

You can apply this plan to save these new output values to the OpenTofu state, without changing any real infrastructure.

And similar on Terraform.

dmurvihill commented 2 months ago

Apologies; I believed that I had verified this behavior on the latest (0.67.0) but I must be mistaken as it's working now. Since this is a dup of #3312 and fixed in 0.66.1 I'll close it now.