|
|
|
|
@ -68,28 +68,35 @@ func (p *SourceBundleParser) LoadConfigDir(source sourceaddrs.FinalSource) (*Mod
|
|
|
|
|
return nil, diags
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The result of sources.LocalPathForSource is an absolute path, but we
|
|
|
|
|
// The result of sources.LocalPathForSource can be an absolute path, but we
|
|
|
|
|
// don't actually want to pass an absolute path for a module's SourceDir;
|
|
|
|
|
// doing so will cause the value of `path.module` in Terraform configs to
|
|
|
|
|
// differ across plans and applies, since tfc-agent performs plans and
|
|
|
|
|
// applies in temporary directories. Instead, we try to resolve a relative
|
|
|
|
|
// path from Terraform's working directory, which should always be a
|
|
|
|
|
// reasonable SourceDir value.
|
|
|
|
|
workDir, err := os.Getwd()
|
|
|
|
|
if err != nil {
|
|
|
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
|
Summary: "Cannot resolve working directory",
|
|
|
|
|
Detail: fmt.Sprintf("Failed to resolve current working directory: %s. This is a bug in Terraform - please report it.", err),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
relativeSourceDir, err := filepath.Rel(workDir, sourceDir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
|
Summary: "Cannot resolve relative path",
|
|
|
|
|
Detail: fmt.Sprintf("Failed to resolve relative path to module directory: %s. This is a bug in Terraform - please report it.", err),
|
|
|
|
|
})
|
|
|
|
|
var relativeSourceDir string
|
|
|
|
|
if filepath.IsAbs(sourceDir) {
|
|
|
|
|
workDir, err := os.Getwd()
|
|
|
|
|
if err != nil {
|
|
|
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
|
Summary: "Cannot resolve working directory",
|
|
|
|
|
Detail: fmt.Sprintf("Failed to resolve current working directory: %s. This is a bug in Terraform - please report it.", err),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
relativeSourceDir, err = filepath.Rel(workDir, sourceDir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
|
Summary: "Cannot resolve relative path",
|
|
|
|
|
Detail: fmt.Sprintf("Failed to resolve relative path to module directory: %s. This is a bug in Terraform - please report it.", err),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// sourceDir is already relative, use it as-is
|
|
|
|
|
relativeSourceDir = sourceDir
|
|
|
|
|
}
|
|
|
|
|
mod.SourceDir = relativeSourceDir
|
|
|
|
|
|
|
|
|
|
|