Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb2aad91

Browse files
authored
stacks: Make path.module and path.root relative, to match documentation (#37982)
* stacks: Make path.module and path.root relative, to match documentationPreviously, we were just handing off the absolute path produced by thesourcebundle struct. But that's no good, because the value doesn't stayconsistent between plan and apply when running under tfc-agent. (It uses workingdirectories named after the unique job ID.) It also doesn't match thedocumentation, which describes these as relative paths. This was preventingpeople from uploading module-provided files to create aws lambda functions, forexample.This commit addresses that by converting the source-bundle provided module pathto a relative path (relative to Terraform's working directory). In tfc-agent forstacks runs, that ends up being the directory directly above the sourcebundledirectory, and all the paths below that are consistent between plan and apply.* I think this is how the changelog thing works?
1 parentf591872 commitb2aad91

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind:BUG FIXES
2+
body:'stacks: change absolute paths in path.module/path.root to be relative, as documented'
3+
time:2025-12-09T23:00:00.316597+00:00
4+
custom:
5+
Issue:"37982"

‎internal/configs/source_bundle_parser.go‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,31 @@ func (p *SourceBundleParser) LoadConfigDir(source sourceaddrs.FinalSource) (*Mod
6767
})
6868
returnnil,diags
6969
}
70-
mod.SourceDir=sourceDir
70+
71+
// The result of sources.LocalPathForSource is an absolute path, but we
72+
// don't actually want to pass an absolute path for a module's SourceDir;
73+
// doing so will cause the value of `path.module` in Terraform configs to
74+
// differ across plans and applies, since tfc-agent performs plans and
75+
// applies in temporary directories. Instead, we try to resolve a relative
76+
// path from Terraform's working directory, which should always be a
77+
// reasonable SourceDir value.
78+
workDir,err:=os.Getwd()
79+
iferr!=nil {
80+
diags=diags.Append(&hcl.Diagnostic{
81+
Severity:hcl.DiagError,
82+
Summary:"Cannot resolve working directory",
83+
Detail:fmt.Sprintf("Failed to resolve current working directory: %s. This is a bug in Terraform - please report it.",err),
84+
})
85+
}
86+
relativeSourceDir,err:=filepath.Rel(workDir,sourceDir)
87+
iferr!=nil {
88+
diags=diags.Append(&hcl.Diagnostic{
89+
Severity:hcl.DiagError,
90+
Summary:"Cannot resolve relative path",
91+
Detail:fmt.Sprintf("Failed to resolve relative path to module directory: %s. This is a bug in Terraform - please report it.",err),
92+
})
93+
}
94+
mod.SourceDir=relativeSourceDir
7195

7296
returnmod,diags
7397
}

‎internal/stacks/stackruntime/internal/stackeval/planning_test.go‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"fmt"
99
"os"
10-
"path/filepath"
1110
"strings"
1211
"testing"
1312
"time"
@@ -852,29 +851,21 @@ func TestPlanning_PathValues(t *testing.T) {
852851
t.Fatalf("failed to get current working directory: %s",err)
853852
}
854853

855-
normalizePath:=func(pathstring)string {
856-
rel,err:=filepath.Rel(cwd,path)
857-
iferr!=nil {
858-
t.Errorf("rel(%s,%s): %s",cwd,path,err)
859-
returnpath
860-
}
861-
returnrel
862-
}
863-
854+
// path.cwd should be absolute and all others should be relative, as per documentation.
864855
expected:=map[string]string{
865-
"cwd":".",
856+
"cwd":cwd,
866857
"root":"testdata/sourcebundle/planning/path_values/module",// this is the root module of the component
867858
"module":"testdata/sourcebundle/planning/path_values/module",// this is the root module
868859
"child_root":"testdata/sourcebundle/planning/path_values/module",// should be the same for all modules
869860
"child_module":"testdata/sourcebundle/planning/path_values/module/child",// this is the child module
870861
}
871862

872863
actual:=map[string]string{
873-
"cwd":normalizePath(component.PlannedOutputValues[addrs.OutputValue{Name:"cwd"}].AsString()),
874-
"root":normalizePath(component.PlannedOutputValues[addrs.OutputValue{Name:"root"}].AsString()),
875-
"module":normalizePath(component.PlannedOutputValues[addrs.OutputValue{Name:"module"}].AsString()),
876-
"child_root":normalizePath(component.PlannedOutputValues[addrs.OutputValue{Name:"child_root"}].AsString()),
877-
"child_module":normalizePath(component.PlannedOutputValues[addrs.OutputValue{Name:"child_module"}].AsString()),
864+
"cwd":component.PlannedOutputValues[addrs.OutputValue{Name:"cwd"}].AsString(),
865+
"root":component.PlannedOutputValues[addrs.OutputValue{Name:"root"}].AsString(),
866+
"module":component.PlannedOutputValues[addrs.OutputValue{Name:"module"}].AsString(),
867+
"child_root":component.PlannedOutputValues[addrs.OutputValue{Name:"child_root"}].AsString(),
868+
"child_module":component.PlannedOutputValues[addrs.OutputValue{Name:"child_module"}].AsString(),
878869
}
879870

880871
ifcmp.Diff(expected,actual)!="" {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp