Skip to content

Commit

Permalink
internal: Parse variable default values
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jun 17, 2021
1 parent d2dbc4a commit ba48327
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/hashicorp/terraform-exec v0.13.3
github.com/hashicorp/terraform-json v0.11.0
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896
github.com/hashicorp/terraform-schema v0.0.0-20210617115006-f08467a1ea82
github.com/hashicorp/terraform-schema v0.0.0-20210617130010-ab6887832578
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5
github.com/mitchellh/cli v1.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ github.com/hashicorp/terraform-json v0.11.0 h1:4zDqqW2F3kOysORIaYKFGgWDYIRA3hwqx
github.com/hashicorp/terraform-json v0.11.0/go.mod h1:pmbq9o4EuL43db5+0ogX10Yofv1nozM+wskr/bGFJpI=
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 h1:1FGtlkJw87UsTMg5s8jrekrHmUPUJaMcu6ELiVhQrNw=
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co=
github.com/hashicorp/terraform-schema v0.0.0-20210617115006-f08467a1ea82 h1:hqdAui7alEutzuAjhZRSrCYEBW+GC8LmEu55cAiaRQQ=
github.com/hashicorp/terraform-schema v0.0.0-20210617115006-f08467a1ea82/go.mod h1:I401Q0vqx1AvDdh+ND7sC12x+C2sqmY5vTkc7FBjSvM=
github.com/hashicorp/terraform-schema v0.0.0-20210617130010-ab6887832578 h1:r2zk8WVjkHqFCylDTukWwICfuZDh/5+p0S7A/MbHkeY=
github.com/hashicorp/terraform-schema v0.0.0-20210617130010-ab6887832578/go.mod h1:I401Q0vqx1AvDdh+ND7sC12x+C2sqmY5vTkc7FBjSvM=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
Expand Down
14 changes: 9 additions & 5 deletions internal/terraform/module/module_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,26 +437,30 @@ func TestSchemaForVariables(t *testing.T) {
}

mod.Meta.Variables = map[string]tfmodule.Variable{
"name": tfmodule.Variable{
"name": {
Description: "name of the module",
Type: cty.String,
},
}
expectedSchema := &schema.BodySchema{Attributes: map[string]*schema.AttributeSchema{
"name": &schema.AttributeSchema{
"name": {
Description: lang.MarkupContent{
Value: "name of the module",
Kind: lang.PlainTextKind,
},
Expr: schema.ExprConstraints{schema.LiteralTypeExpr{cty.String}},
IsRequired: true,
Expr: schema.LiteralTypeOnly(cty.String),
},
}}

actualSchema, _ := mm.SchemaForVariables(path)
actualSchema, err := mm.SchemaForVariables(path)
if err != nil {
t.Fatal(err)
}

diff := cmp.Diff(expectedSchema, actualSchema, ctydebug.CmpOptions)
if diff != "" {
t.Fatalf("unexpected schema %s", diff)
t.Fatalf("unexpected schema: %s", diff)
}
}

Expand Down

0 comments on commit ba48327

Please sign in to comment.