TestTerraformLike parses both a native syntax and a JSON representation of the same HashiCorp Terraform-like configuration structure and then makes assertions against the result of each. Terraform exercises a lot of different HCL codepaths, so this is not exhaustive but tries to cover a variety of
(t *testing.T)
| 26 | // Terraform exercises a lot of different HCL codepaths, so this is not |
| 27 | // exhaustive but tries to cover a variety of different relevant scenarios. |
| 28 | func TestTerraformLike(t *testing.T) { |
| 29 | tests := map[string]func() (*hcl.File, hcl.Diagnostics){ |
| 30 | "native syntax": func() (*hcl.File, hcl.Diagnostics) { |
| 31 | return hclsyntax.ParseConfig( |
| 32 | []byte(terraformLikeNativeSyntax), |
| 33 | "config.tf", hcl.Pos{Line: 1, Column: 1}, |
| 34 | ) |
| 35 | }, |
| 36 | "JSON": func() (*hcl.File, hcl.Diagnostics) { |
| 37 | return json.Parse( |
| 38 | []byte(terraformLikeJSON), |
| 39 | "config.tf.json", |
| 40 | ) |
| 41 | }, |
| 42 | } |
| 43 | |
| 44 | type Variable struct { |
| 45 | Name string `hcl:"name,label"` |
| 46 | } |
| 47 | type Resource struct { |
| 48 | Type string `hcl:"type,label"` |
| 49 | Name string `hcl:"name,label"` |
| 50 | Config hcl.Body `hcl:",remain"` |
| 51 | DependsOn hcl.Expression `hcl:"depends_on,attr"` |
| 52 | } |
| 53 | type Module struct { |
| 54 | Name string `hcl:"name,label"` |
| 55 | Providers hcl.Expression `hcl:"providers"` |
| 56 | } |
| 57 | type Locals struct { |
| 58 | Config hcl.Body `hcl:",remain"` |
| 59 | } |
| 60 | type Root struct { |
| 61 | Variables []*Variable `hcl:"variable,block"` |
| 62 | Resources []*Resource `hcl:"resource,block"` |
| 63 | Modules []*Module `hcl:"module,block"` |
| 64 | Locals []*Locals `hcl:"locals,block"` |
| 65 | } |
| 66 | instanceDecode := &hcldec.ObjectSpec{ |
| 67 | "image_id": &hcldec.AttrSpec{ |
| 68 | Name: "image_id", |
| 69 | Required: true, |
| 70 | Type: cty.String, |
| 71 | }, |
| 72 | "instance_type": &hcldec.AttrSpec{ |
| 73 | Name: "instance_type", |
| 74 | Required: true, |
| 75 | Type: cty.String, |
| 76 | }, |
| 77 | "tags": &hcldec.AttrSpec{ |
| 78 | Name: "tags", |
| 79 | Required: false, |
| 80 | Type: cty.Map(cty.String), |
| 81 | }, |
| 82 | } |
| 83 | securityGroupDecode := &hcldec.ObjectSpec{ |
| 84 | "ingress": &hcldec.BlockListSpec{ |
| 85 | TypeName: "ingress", |
nothing calls this directly
no test coverage detected