Skip to content

Fix multi-region provider aliases generating incorrect Terraform JSON format#2210

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-multi-region-provider-aliases
Open

Fix multi-region provider aliases generating incorrect Terraform JSON format#2210
Copilot wants to merge 2 commits intomainfrom
copilot/fix-multi-region-provider-aliases

Conversation

Copy link
Contributor

Copilot AI commented Mar 16, 2026

When configuring providers with dot-notation aliases (e.g., aws.use1), the generated providers_override.tf.json emitted invalid structure — separate top-level keys instead of the array-of-objects format Terraform's JSON syntax requires for multiple provider instances.

Changes

  • pkg/terraform/output/backend.go: Added exported ProcessProviderAliases that detects dot-notation provider keys, groups all configurations for the same provider type into an array (base config first, aliases sorted), and leaves non-aliased providers unchanged
  • internal/exec/utils.go: Updated generateComponentProviderOverrides to delegate to tfoutput.ProcessProviderAliases, eliminating duplicated logic

Example

Given stack config:

providers:
  aws:
    region: us-east-2
  aws.use1:
    region: us-east-1
    alias: use1

Before:

{ "provider": { "aws": { "region": "us-east-2" }, "aws.use1": { "alias": "use1", "region": "us-east-1" } } }

After:

{
  "provider": {
    "aws": [
      { "region": "us-east-2" },
      { "alias": "use1", "region": "us-east-1" }
    ]
  }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Multi-Region with Provider Aliases example is not working</issue_title>
<issue_description>### Describe the Bug

https://atmos.tools/stacks/providers#multi-region-with-provider-aliases, this example is not working, the actual generated file is different from the example.

Expected Behavior

The generated file is the same as the example.

Steps to Reproduce

With the following atmos component config:

components:
  terraform:
    eip:
      providers:
        aws:
          region: us-east-2
        aws.use1:
          region: us-east-1
          alias: use1
      metadata:
        component: eip

Run atmos command and check the output of providers_override.tf.json

Screenshots

The content of the generated providers_override.tf.json

{
  "provider": {
    "aws": {
      "region": "us-east-2"
    },
    "aws.use1": {
      "alias": "use1",
      "region": "us-east-1"
    }
  }
}

Would expect it to be :

{
  "provider": {
    "aws": [
      {
        "region": "us-east-2"
      },
      {
        "alias": "use1",
        "region": "us-east-1"
      }
    ]
  }
}

Environment

  • OS: OSX
  • Version: 1.209.0
  • Terraform version: v1.14.7

Additional Context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@mergify mergify bot added triage Needs triage wip Work in Progress: Not ready for final review or merge labels Mar 16, 2026
@osterman osterman added no-release Do not create a new release (wait for additional code changes) patch A minor, backward compatible change and removed no-release Do not create a new release (wait for additional code changes) labels Mar 16, 2026
When providers are configured with dot-notation aliases (e.g., `aws.use1`),
the generated `providers_override.tf.json` now correctly groups all instances
of the same provider type into an array, as required by Terraform's JSON format.

Before:
  {"provider": {"aws": {...}, "aws.use1": {...}}}

After:
  {"provider": {"aws": [{...}, {...}]}}

- Add `ProcessProviderAliases` helper to `pkg/terraform/output/backend.go`
- Update `generateProviderOverrides` to use the new helper
- Update `generateComponentProviderOverrides` in `internal/exec/utils.go`
  to use the shared `tfoutput.ProcessProviderAliases`
- Add test cases for multi-region with provider aliases in both packages

Co-authored-by: osterman <52489+osterman@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Multi-Region with Provider Aliases example Fix multi-region provider aliases generating incorrect Terraform JSON format Mar 16, 2026
Copilot AI requested a review from osterman March 16, 2026 15:10
@mergify mergify bot removed the wip Work in Progress: Not ready for final review or merge label Mar 16, 2026
@github-actions github-actions bot added the size/m Medium size PR label Mar 16, 2026
@osterman osterman marked this pull request as ready for review March 16, 2026 15:22
@osterman osterman requested a review from a team as a code owner March 16, 2026 15:22
@github-actions
Copy link

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.40%. Comparing base (1f4ac96) to head (b716bc3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2210   +/-   ##
=======================================
  Coverage   77.40%   77.40%           
=======================================
  Files         962      962           
  Lines       91284    91314   +30     
=======================================
+ Hits        70657    70686   +29     
+ Misses      16550    16548    -2     
- Partials     4077     4080    +3     
Flag Coverage Δ
unittests 77.40% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/exec/utils.go 82.31% <100.00%> (ø)
pkg/terraform/output/backend.go 82.47% <100.00%> (+7.84%) ⬆️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR triage Needs triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-Region with Provider Aliases example is not working

2 participants