Skip to content

Commit 1143099

Browse files
committed
chore: pr comments
1 parent 009b8d1 commit 1143099

6 files changed

Lines changed: 39 additions & 13 deletions

File tree

internal/hclparse/autoinclude.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func (a *AutoIncludeHCL) Resolve(evalCtx *hcl.EvalContext) (*AutoIncludeResolved
7979

8080
body, ok := a.Remain.(*hclsyntax.Body)
8181
if !ok {
82-
// Non-syntax body — return result without EvalCtx since partial evaluation is not possible.
83-
return &AutoIncludeResolved{RawBody: a.Remain}, nil
82+
// Non-syntax body — return result with EvalCtx even though partial evaluation is not possible.
83+
return &AutoIncludeResolved{EvalCtx: evalCtx, RawBody: a.Remain}, nil
8484
}
8585

8686
var (
@@ -135,6 +135,15 @@ func resolveDependencyBlock(block *hclsyntax.Block, evalCtx *hcl.EvalContext) (A
135135
return AutoIncludeDependency{}, diags
136136
}
137137

138+
if val.Type() != cty.String {
139+
return AutoIncludeDependency{}, hcl.Diagnostics{{
140+
Severity: hcl.DiagError,
141+
Summary: "Invalid config_path type",
142+
Detail: "dependency config_path must evaluate to a string",
143+
Subject: configPathAttr.Expr.Range().Ptr(),
144+
}}
145+
}
146+
138147
return AutoIncludeDependency{
139148
Name: name,
140149
ConfigPath: val.AsString(),

internal/hclparse/generate.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/hcl/v2"
1010
"github.com/hashicorp/hcl/v2/hclsyntax"
1111
"github.com/hashicorp/hcl/v2/hclwrite"
12+
"github.com/zclconf/go-cty/cty"
1213
)
1314

1415
const (
@@ -179,11 +180,7 @@ func rangeBytes(src []byte, r hcl.Range) []byte {
179180

180181
// quotedStringTokens creates hclwrite tokens for a quoted string literal.
181182
func quotedStringTokens(value string) hclwrite.Tokens {
182-
return hclwrite.Tokens{
183-
{Type: hclsyntax.TokenOQuote, Bytes: []byte{'"'}},
184-
{Type: hclsyntax.TokenQuotedLit, Bytes: []byte(value)},
185-
{Type: hclsyntax.TokenCQuote, Bytes: []byte{'"'}},
186-
}
183+
return hclwrite.TokensForValue(cty.StringVal(value))
187184
}
188185

189186
// rawTokens wraps raw bytes as a single hclwrite token. hclwrite.Format

internal/hclparse/parse.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ func processStackIncludes(stackFile *StackFileHCL, stackDir string) error {
223223
return errors.Errorf("failed to decode include %q: %s", inc.Name, decodeDiags.Error())
224224
}
225225

226+
if included.Locals != nil {
227+
return errors.Errorf("included stack file %q must not define locals", inc.Name)
228+
}
229+
230+
if len(included.Includes) > 0 {
231+
return errors.Errorf("included stack file %q must not define nested includes", inc.Name)
232+
}
233+
226234
stackFile.Units = append(stackFile.Units, included.Units...)
227235
stackFile.Stacks = append(stackFile.Stacks, included.Stacks...)
228236
}
@@ -236,9 +244,15 @@ func buildRefsWithAbsPath(stackTargetDir string, units []*UnitBlockHCL) []Compon
236244
refs := make([]ComponentRef, 0, len(units))
237245

238246
for _, u := range units {
247+
unitPath := filepath.Join(stackTargetDir, u.Path)
248+
249+
if u.NoStack != nil && *u.NoStack {
250+
unitPath = filepath.Join(filepath.Dir(stackTargetDir), u.Path)
251+
}
252+
239253
refs = append(refs, ComponentRef{
240254
Name: u.Name,
241-
Path: filepath.Join(stackTargetDir, u.Path),
255+
Path: unitPath,
242256
})
243257
}
244258

internal/hclparse/stack.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ func UnitPathsFromStackDir(stackDir string) []string {
174174

175175
paths := make([]string, 0, len(result.Units))
176176
for _, unit := range result.Units {
177-
paths = append(paths, filepath.Join(stackDir, StackDir, unit.Path))
177+
unitPath := filepath.Join(stackDir, StackDir, unit.Path)
178+
179+
if unit.NoStack != nil && *unit.NoStack {
180+
unitPath = filepath.Join(stackDir, unit.Path)
181+
}
182+
183+
paths = append(paths, unitPath)
178184
}
179185

180186
return paths

pkg/config/dependency.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ func collectStackUnitOutputs(ctx context.Context, pctx *ParsingContext, l log.Lo
735735
if len(outputMap) > 0 {
736736
convertedOutput, err := gocty.ToCtyValue(outputMap, generateTypeFromValuesMap(outputMap))
737737
if err != nil {
738+
l.Debugf("Failed to convert output map for stack unit %s: %v", unit.Name, err)
739+
738740
continue
739741
}
740742

pkg/config/stack.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ func GenerateStackFile(ctx context.Context, l log.Logger, pctx *ParsingContext,
113113

114114
parseResult, parseErr := intHclparse.ParseStackFile(&intHclparse.ParseStackFileInput{Src: stackSrcBytes, Filename: stackFilePath, StackDir: stackSourceDir, Values: values})
115115
if parseErr != nil {
116-
l.Debugf("Autoinclude parse for %s: %v", stackFilePath, parseErr)
116+
return errors.Errorf("autoinclude parse failed for %s: %w", stackFilePath, parseErr)
117117
}
118118

119-
if parseErr == nil {
120-
autoIncludes = parseResult.AutoIncludes
121-
}
119+
autoIncludes = parseResult.AutoIncludes
122120
}
123121

124122
genOpts := generateOpts{

0 commit comments

Comments
 (0)