Skip to content

Conversation

pwillis-oi
Copy link
Contributor

@pwillis-oi pwillis-oi commented Jul 29, 2025

If the default value is null, the module fails with Error: Iteration over null value. This changes the default from null to an empty map to avoid this error.

Description

The default null value for default_capacity_provider_strategy always causes the module to fail.

│ Error: Iteration over null value
│
│   on /var/folders/7s/4m_zx_dj4616qf_rrf5wr1km0000gn/T/tfsh.aa9dd864fd/modules/ecs_cluster/modules/cluster/main.tf line 105, in resource "aws_ecs_cluster_capacity_providers" "this":
│  105:     [for k, v in var.default_capacity_provider_strategy : try(coalesce(v.name, k))],
│     ├────────────────
│     │ var.default_capacity_provider_strategy is null
│
│ A null value cannot be used as the collection in a 'for' expression.

Changing this to an empty map allows the module to continue without errors.

Motivation and Context

Breaking Changes

Should not be a breaking change since the module was breaking with the default as-is, but I have not done any regression testing...

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

I have tested this on a module I already have in use that I'm upgrading to the 6.x module version. I never specified that variable before, so the default is being used, and the module breaks. This fix avoids the error

If the default value is null, the module fails with `Error: Iteration over null value`. This changes the default from null to an empty map to avoid this error.
@pwillis-oi pwillis-oi changed the title Use a valid default default_capacity_provider_strategy fix: Use a valid default default_capacity_provider_strategy Jul 29, 2025
@pwillis-oi
Copy link
Contributor Author

Also, this is out of scope of the PR, but if the authors want, I can open a separate PR with a POC of running regression tests on PRs. This GitHub Action is what I use to run a matrix of jobs, each using a different Terraform release, to run a suite of simple tests. In this way I can see if any of my tests fail on a different version of Terraform. The same could be done with provider versions for example.

@bryantbiggs bryantbiggs changed the title fix: Use a valid default default_capacity_provider_strategy fix: Use an empty map as default value for default_capacity_provider_strategy Jul 29, 2025
@bryantbiggs
Copy link
Member

Also, this is out of scope of the PR, but if the authors want, I can open a separate PR with a POC of running regression tests on PRs. This GitHub Action is what I use to run a matrix of jobs, each using a different Terraform release, to run a suite of simple tests. In this way I can see if any of my tests fail on a different version of Terraform. The same could be done with provider versions for example.

we already do this in our CI - testing lower and upper bounds of Terraform versions

@bryantbiggs bryantbiggs merged commit ea0a160 into terraform-aws-modules:master Jul 29, 2025
12 checks passed
antonbabenko pushed a commit that referenced this pull request Jul 29, 2025
## [6.1.1](v6.1.0...v6.1.1) (2025-07-29)

### Bug Fixes

* Use an empty map as default value for `default_capacity_provider_strategy` ([#326](#326)) ([ea0a160](ea0a160))
@antonbabenko
Copy link
Member

This PR is included in version 6.1.1 🎉

@pwillis-oi pwillis-oi deleted the patch-1 branch August 1, 2025 16:59
Copy link

github-actions bot commented Sep 1, 2025

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default_capacity_provider_strategy can NOT be null (which is the default value)
3 participants