Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Align for_each collection validation with its documented key semantics

Open
#85 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #88 by @lonegunmanb — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
go
Domain
tooling

Research direction

Start with BaseConfig.expandBlock in base_config.go at the linked lines and trace how for_each values are validated and converted to instance keys. The issue leaves open whether to enforce Terraform-compatible types or document broader iterable support, so settle that contract before changing validation. Add table-driven tests for the listed collection types; done means validation, diagnostics, addresses, and tests agree with the chosen semantics.

Written by the indexing model from the issue text.

Description

Summary

BaseConfig.expandBlock reports that for_each accepts a set or map, but its validation accepts every cty value for which CanIterateElements() is true. Lists, tuples, objects, and sets with non-string elements are therefore accepted with semantics that are broader than the diagnostic and Terraform-style for_each behavior.

Observed on main at commit 1d1c394b55ea36a8dc98495850430e4da643b1eb.

Reproduction

All of these currently reach expansion:

example "item" {
  for_each = ["a", "b"]
}

example "number" {
  for_each = toset([1, 2])
}

example "empty" {
  for_each = []
}

The validation is only:

if !forEachValue.CanIterateElements() {
    return nil, fmt.Errorf("invalid `for_each`, except set or map: %s", attr.Range().String())
}

https://github.com/Azure/golden/blob/1d1c394b55ea36a8dc98495850430e4da643b1eb/base_config.go#L294-L309

Actual behavior

Values outside the stated set/map contract are expanded. Sequence indices and arbitrary cty keys become instance keys through CtyValueToString, making address stability depend on undocumented behavior.

Expected behavior

The accepted type family and key semantics should be explicit and consistent across validation, diagnostics, addresses, and tests.

For Terraform-compatible behavior, accept maps/objects and sets of strings, and reject lists, tuples, and non-string sets. If Golden intentionally supports all iterable values, update the error and document stable key/address semantics for each supported family.

Suggested direction

Centralize for_each type validation before iteration and add table-driven tests for map, object, set(string), list, tuple, empty collections, and non-string sets.

Dominant language
Go
Stars
3
Forks
13
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/golden

All issues in Azure/golden

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.