MCPcopy Index your code
hub / github.com/coder/coder / BuildEvalContext

Function BuildEvalContext

provisioner/terraform/tfparse/tfparse.go:451–484  ·  view source on GitHub ↗

BuildEvalContext builds an evaluation context for the given variable and parameter defaults.

(vars map[string]string, params map[string]string)

Source from the content-addressed store, hash-verified

449
450// BuildEvalContext builds an evaluation context for the given variable and parameter defaults.
451func BuildEvalContext(vars map[string]string, params map[string]string) *hcl.EvalContext {
452 varDefaultsM := map[string]cty.Value{}
453 for varName, varDefault := range vars {
454 varDefaultsM[varName] = cty.MapVal(map[string]cty.Value{
455 "value": cty.StringVal(varDefault),
456 })
457 }
458
459 paramDefaultsM := map[string]cty.Value{}
460 for paramName, paramDefault := range params {
461 paramDefaultsM[paramName] = cty.MapVal(map[string]cty.Value{
462 "value": cty.StringVal(paramDefault),
463 })
464 }
465
466 evalCtx := &hcl.EvalContext{
467 Variables: map[string]cty.Value{},
468 // NOTE: we do not currently support function execution here.
469 // The default function map for Terraform is not exposed, so we would essentially
470 // have to re-implement or copy the entire map or a subset thereof.
471 // ref: https://github.com/hashicorp/terraform/blob/e044e569c5bc81f82e9a4d7891f37c6fbb0a8a10/internal/lang/functions.go#L54
472 Functions: Functions(),
473 }
474 if len(varDefaultsM) != 0 {
475 evalCtx.Variables["var"] = cty.MapVal(varDefaultsM)
476 }
477 if len(paramDefaultsM) != 0 {
478 evalCtx.Variables["data"] = cty.MapVal(map[string]cty.Value{
479 "coder_parameter": cty.MapVal(paramDefaultsM),
480 })
481 }
482
483 return evalCtx
484}
485
486var rootTemplateSchema = &hcl.BodySchema{
487 Blocks: []hcl.BlockHeaderSchema{

Callers 3

evaluateWorkspaceTagsFunction · 0.85

Calls 1

FunctionsFunction · 0.85

Tested by

no test coverage detected