hashicorp / terraform-config-inspect

A helper library for shallow inspection of Terraform configurations
Mozilla Public License 2.0
381 stars 76 forks source link

display raw value from output #22

Open checkmypi opened 5 years ago

checkmypi commented 5 years ago

Hi there, I'm trying to add printout of the raw value from the output. So from this

output "val_a" {
  value = "${var.a}"
}

I'd like to get output like this

  "outputs": {
    "val_a": {
      "name": "val_a",
      "raw_value": "${var.a}",
      "pos": {
        "filename": "test.tf",
        "line": 5
      }
    }
  }

The trouble I have is that I don't know how to force attr.Expr to return raw value, it seems to try to evaluate the attribute when I access it. Any tips would be appreciated.

Thank you

DUMP


(*hcl.Block)(0xc00015e5b0)({
 Type: (string) (len=6) "output",
 Labels: ([]string) (len=1 cap=1) {
  (string) (len=5) "val_a"
 },
 Body: (*hclsyntax.Body)(0xc0001840b0)({
  Attributes: (hclsyntax.Attributes) (len=1) {
   (string) (len=5) "value": (*hclsyntax.Attribute)(0xc0001820e0)({
    Name: (string) (len=5) "value",
    Expr: (*hclsyntax.TemplateWrapExpr)(0xc00015a190)({
     Wrapped: (*hclsyntax.ScopeTraversalExpr)(0xc00014d800)({
      Traversal: (hcl.Traversal) (len=2 cap=2) {
       (hcl.TraverseRoot) {
        isTraverser: (hcl.isTraverser) {
        },
        Name: (string) (len=3) "var",
        SrcRange: (hcl.Range) test.tf:6,14-17
       },
       (hcl.TraverseAttr) {
        isTraverser: (hcl.isTraverser) {
        },
        Name: (string) (len=1) "a",
        SrcRange: (hcl.Range) test.tf:6,17-19
       }
      },
      SrcRange: (hcl.Range) test.tf:6,14-19
     }),
     SrcRange: (hcl.Range) test.tf:6,11-21
    }),
    SrcRange: (hcl.Range) test.tf:6,3-21,
    NameRange: (hcl.Range) test.tf:6,3-8,
    EqualsRange: (hcl.Range) test.tf:6,9-10
   })
  },