{"record":{"id":"6c284fe753399cd8","repo":"mikefarah/yq","slug":"hcl-encoder-does-not-support-aliases","errorCode":null,"errorMessage":"HCL encoder does not support aliases","messagePattern":"HCL encoder does not support aliases","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/encoder_hcl.go","lineNumber":686,"sourceCode":"\t\t\tv, err := nodeToCtyValue(valueNode)\n\t\t\tif err != nil {\n\t\t\t\treturn cty.NilVal, err\n\t\t\t}\n\t\t\tm[keyNode.Value] = v\n\t\t}\n\t\treturn cty.ObjectVal(m), nil\n\tcase SequenceNode:\n\t\tvals := make([]cty.Value, len(node.Content))\n\t\tfor i, item := range node.Content {\n\t\t\tv, err := nodeToCtyValue(item)\n\t\t\tif err != nil {\n\t\t\t\treturn cty.NilVal, err\n\t\t\t}\n\t\t\tvals[i] = v\n\t\t}\n\t\treturn cty.TupleVal(vals), nil\n\tcase AliasNode:\n\t\treturn cty.NilVal, fmt.Errorf(\"HCL encoder does not support aliases\")\n\tdefault:\n\t\treturn cty.NilVal, fmt.Errorf(\"unsupported node kind: %v\", node.Kind)\n\t}\n}\n","sourceCodeStart":668,"sourceCodeEnd":691,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/encoder_hcl.go#L668-L691","documentation":"nodeToCtyValue hit an AliasNode while converting the CandidateNode tree to a cty value for HCL emission. The HCL encoder cannot resolve YAML anchors/aliases (cty values are concrete), so any alias remaining in the tree — because the encoder's CanHandleAliases is false and the node was not exploded first — aborts conversion with this sentinel-style guard error.","triggerScenarios":"`yq -o hcl` on YAML input containing anchors/aliases, e.g. `base: &b {a: 1}` then `derived: *b` — encoding the derived field hits the AliasNode case.","commonSituations":"Terraform module configs written with YAML anchors to deduplicate blocks; users converting anchor-heavy YAML to HCL for Terraform.","solutions":["Resolve aliases before encoding, e.g. pipe through a tool/expression that dereferences anchors (yq evaluation typically resolves aliases on traversal; ensure the value is a real node)","Manually expand the anchor into a full mapping in the input","Use `-o json` intermediate step: `yq -o json | yq -o hcl` to materialize the data"],"exampleFix":"// before: derived: *b   (alias)\n// after:  derived: {a: 1}  (expanded mapping)","handlingStrategy":"validation","validationCode":"yq '[.. | tag] | any(\"!!alias\")' input.yaml   # must print false before -o hcl","typeGuard":"func containsAlias(node *CandidateNode) bool {\n  if node.Kind == AliasNode { return true }\n  for _, c := range node.Content {\n    if containsAlias(c) { return true }\n  }\n  return false\n}","tryCatchPattern":"v, err := nodeToCtyValue(node)\nif err != nil && strings.Contains(err.Error(), \"does not support aliases\") {\n    // dereference/expand the alias, then retry the encode\n}","preventionTips":["Avoid YAML anchors/aliases in data destined for HCL","Expand anchors before conversion (round-trip via JSON: `yq -o json | yq -p json -o hcl`)","Scan inputs with `[.. | tag] | any(\"!!alias\")` as a pre-flight check"],"tags":["hcl","encoding","aliases","yaml-anchors","yq"],"backgroundTag":"hcl-alias-unsupported","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}