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 16, 2021
1 parent b88ef40 commit d576d8e
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-20210615134722-b66475e71618
github.com/hashicorp/terraform-schema v0.0.0-20210616110625-6bb1a1e93677
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-20210615134722-b66475e71618 h1:BqSvtjfGhxnPaOiTiIokg6eJcjhT1hg/nmXU6XoKYFI=
github.com/hashicorp/terraform-schema v0.0.0-20210615134722-b66475e71618/go.mod h1:ruV9Xx5LQYrZB0sNEx9dlkvS0Cp+juY/2jXQmup/67s=
github.com/hashicorp/terraform-schema v0.0.0-20210616110625-6bb1a1e93677 h1:vewur2+vil349IVlkHx3+KZVx2oS53FmwnRXuWX0aQ4=
github.com/hashicorp/terraform-schema v0.0.0-20210616110625-6bb1a1e93677/go.mod h1:ruV9Xx5LQYrZB0sNEx9dlkvS0Cp+juY/2jXQmup/67s=
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 d576d8e

Please sign in to comment.