Skip to content

Commit

Permalink
fix: reserve var.name for togomak
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Nov 3, 2023
1 parent a6abb4f commit b483c3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/ci/module_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (m *Module) run(conductor *Conductor, source string, evalCtx *hcl.EvalConte
} else {
expr = hcl.StaticExpr(v, attr.Expr.Range())
}
logger.Tracef("setting variable %s to %s", attr.Name, expr)
variable := &Variable{
Id: attr.Name,
Value: expr,
Expand Down
10 changes: 10 additions & 0 deletions internal/ci/variable_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ func (v *Variable) Prepare(conductor *Conductor, skip bool, overridden bool) hcl

func (v *Variable) resolveVar(conductor *Conductor) (cty.Value, hcl.Diagnostics) {
var diags hcl.Diagnostics
if v.Id == "name" {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid variable name",
Detail: fmt.Sprintf("The variable name '%s' has been reserved by togomak", v.Id),
EvalContext: conductor.Eval().Context(),
})
return cty.NilVal, diags
}

osEnvValue := os.Getenv(fmt.Sprintf("TOGOMAK_VAR_%s", v.Id))
if osEnvValue != "" {
return cty.StringVal(osEnvValue), nil
Expand Down

0 comments on commit b483c3a

Please sign in to comment.