Skip to content

Commit 9be8bae

Browse files
authored
chore: Backporting #5722 (#5731)
* chore: Backporting #5722 * fix: Fixing codespell
1 parent 28eafc8 commit 9be8bae

7 files changed

Lines changed: 88 additions & 1 deletion

File tree

internal/cli/commands/catalog/tui/model_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestTUINavigationToModuleDetails(t *testing.T) {
192192
return bytes.Contains(bts, []byte("List of Modules"))
193193
}, teatest.WithCheckInterval(time.Millisecond*100), teatest.WithDuration(time.Second*2))
194194

195-
// Press Enter to select the first module (assuming it's pre-selected)
195+
// Press Enter to select the first module (assuming it's preselected)
196196
tm.Send(tea.KeyMsg{
197197
Type: tea.KeyEnter,
198198
})

internal/discovery/phase_parse.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/gruntwork-io/terragrunt/internal/component"
1010
"github.com/gruntwork-io/terragrunt/internal/errors"
1111
"github.com/gruntwork-io/terragrunt/internal/filter"
12+
"github.com/gruntwork-io/terragrunt/internal/runner/run/creds"
1213
"github.com/gruntwork-io/terragrunt/internal/util"
1314
"github.com/gruntwork-io/terragrunt/pkg/config"
1415
"github.com/gruntwork-io/terragrunt/pkg/config/hclparse"
@@ -233,6 +234,10 @@ func parseComponent(
233234
parseOpts.TerragruntConfigPath = filepath.Join(parseOpts.WorkingDir, configFilename)
234235
parseOpts.OriginalTerragruntConfigPath = parseOpts.TerragruntConfigPath
235236

237+
if _, err := creds.ObtainCredsForParsing(ctx, l, parseOpts); err != nil {
238+
return err
239+
}
240+
236241
ctx, parsingCtx := config.NewParsingContext(ctx, l, parseOpts)
237242
parsingCtx = parsingCtx.WithDecodeList(
238243
config.TerraformSource,

internal/filter/classifier_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,33 @@ func TestClassifier_Classify(t *testing.T) {
368368
expectedReason: filter.CandidacyReasonNone,
369369
expectedIdx: -1,
370370
},
371+
{
372+
name: "filesystem_match_requires_parse_when_parse_exprs_exist",
373+
filterStrs: []string{"./apps/*", "reading=config/*.hcl"},
374+
componentPath: "./apps/app1",
375+
parseDataAvailable: false,
376+
expectedStatus: filter.StatusCandidate,
377+
expectedReason: filter.CandidacyReasonRequiresParse,
378+
expectedIdx: -1,
379+
},
380+
{
381+
name: "no_filesystem_match_still_requires_parse",
382+
filterStrs: []string{"./apps/*", "reading=config/*.hcl"},
383+
componentPath: "./libs/db",
384+
parseDataAvailable: false,
385+
expectedStatus: filter.StatusCandidate,
386+
expectedReason: filter.CandidacyReasonRequiresParse,
387+
expectedIdx: -1,
388+
},
389+
{
390+
name: "negation_excluded_not_rescued_by_parse_exprs",
391+
filterStrs: []string{"!./apps/app1", "reading=config/*.hcl"},
392+
componentPath: "./apps/app1",
393+
parseDataAvailable: false,
394+
expectedStatus: filter.StatusExcluded,
395+
expectedReason: filter.CandidacyReasonNone,
396+
expectedIdx: -1,
397+
},
371398
}
372399

373400
for _, tt := range tests {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "secret" {
2+
type = string
3+
}
4+
5+
output "secret" {
6+
value = var.secret
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
printf '{"envs": {"AUTH_PROVIDER_SECRET": "from-auth-provider"}}\n'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
locals {
2+
secret = get_env("AUTH_PROVIDER_SECRET")
3+
}
4+
5+
inputs = {
6+
secret = local.secret
7+
}

test/integration_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,6 +3305,42 @@ func TestReadTerragruntAuthProviderCmd(t *testing.T) {
33053305
assert.Equal(t, "app3-bar", outputs["foo-app3"].Value)
33063306
}
33073307

3308+
// TestReadTerragruntAuthProviderCmdEnvInLocalsRunAll verifies that
3309+
// auth-provider-cmd credentials are available during discovery queue
3310+
// construction (run --all). Without the fix in phase_parse.go, get_env()
3311+
// in locals cannot see env vars injected by --auth-provider-cmd because
3312+
// ObtainCredsForParsing is never called during the discovery parse phase.
3313+
func TestReadTerragruntAuthProviderCmdEnvInLocalsRunAll(t *testing.T) {
3314+
t.Parallel()
3315+
3316+
helpers.CleanupTerraformFolder(t, testFixtureAuthProviderCmd)
3317+
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureAuthProviderCmd)
3318+
rootPath := filepath.Join(tmpEnvPath, testFixtureAuthProviderCmd, "env-in-locals")
3319+
mockAuthCmd := filepath.Join(rootPath, "mock-auth-cmd.sh")
3320+
3321+
helpers.RunTerragrunt(
3322+
t, fmt.Sprintf(
3323+
`terragrunt run --all --non-interactive --working-dir %s --auth-provider-cmd %s -- apply -auto-approve`,
3324+
rootPath,
3325+
mockAuthCmd,
3326+
),
3327+
)
3328+
3329+
stdout, _, err := helpers.RunTerragruntCommandWithOutput(
3330+
t, fmt.Sprintf(
3331+
"terragrunt run --non-interactive --working-dir %s --auth-provider-cmd %s -- output -json",
3332+
rootPath,
3333+
mockAuthCmd,
3334+
),
3335+
)
3336+
require.NoError(t, err)
3337+
3338+
outputs := map[string]helpers.TerraformOutput{}
3339+
require.NoError(t, json.Unmarshal([]byte(stdout), &outputs))
3340+
3341+
assert.Equal(t, "from-auth-provider", outputs["secret"].Value)
3342+
}
3343+
33083344
func TestIamRolesLoadingFromDifferentModules(t *testing.T) {
33093345
t.Parallel()
33103346

0 commit comments

Comments
 (0)