Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema: Enable interpolated map keys and object attribute names #316

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hc-install v0.6.2
github.com/hashicorp/hcl-lang v0.0.0-20231103134808-2ce7ad140f7c
github.com/hashicorp/hcl-lang v0.0.0-20240122101040-f43c27231c10
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/terraform-exec v0.20.0
github.com/hashicorp/terraform-json v0.21.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hc-install v0.6.2 h1:V1k+Vraqz4olgZ9UzKiAcbman9i9scg9GgSt/U3mw/M=
github.com/hashicorp/hc-install v0.6.2/go.mod h1:2JBpd+NCFKiHiu/yYCGaPyPHhZLxXTpz8oreHa/a3Ps=
github.com/hashicorp/hcl-lang v0.0.0-20231103134808-2ce7ad140f7c h1:ppZ7NorEmcV4B7+M9DWd6nQNRSWs55RUebJzYOuAdc0=
github.com/hashicorp/hcl-lang v0.0.0-20231103134808-2ce7ad140f7c/go.mod h1:f8Trmd1qEAs00+y4etS5uTDqYhU3Z/pxJgzsTwWXWM8=
github.com/hashicorp/hcl-lang v0.0.0-20240122101040-f43c27231c10 h1:tXisNKDNqOGkcRf8NeM4b0Br4Q5SFrpbDj36qSQimjA=
github.com/hashicorp/hcl-lang v0.0.0-20240122101040-f43c27231c10/go.mod h1:HWlBK8JoI8P4yp2reyTc267YoDpypd5fK3OYAPLyUXM=
github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI=
github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE=
github.com/hashicorp/terraform-exec v0.20.0 h1:DIZnPsqzPGuUnq6cH8jWcPunBfY+C+M8JyYF3vpnuEo=
Expand Down Expand Up @@ -135,8 +135,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
16 changes: 10 additions & 6 deletions schema/convert_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ func exprConstraintFromSchemaAttribute(attr *tfjson.SchemaAttribute) schema.Cons
}
case tfjson.SchemaNestingModeMap:
return schema.Map{
Elem: convertJsonAttributesToObjectConstraint(attr.AttributeNestedType.Attributes),
MinItems: attr.AttributeNestedType.MinItems,
MaxItems: attr.AttributeNestedType.MaxItems,
Elem: convertJsonAttributesToObjectConstraint(attr.AttributeNestedType.Attributes),
MinItems: attr.AttributeNestedType.MinItems,
MaxItems: attr.AttributeNestedType.MaxItems,
AllowInterpolatedKeys: true,
}
}
}
Expand Down Expand Up @@ -270,7 +271,8 @@ func convertAttributeTypeToConstraint(attrType cty.Type) schema.Constraint {
}
if attrType.IsMapType() {
cons = append(cons, schema.Map{
Elem: convertAttributeTypeToConstraint(attrType.ElementType()),
Elem: convertAttributeTypeToConstraint(attrType.ElementType()),
AllowInterpolatedKeys: true,
})
}
if attrType.IsObjectType() {
Expand All @@ -297,7 +299,8 @@ func convertCtyObjectToObjectCons(obj cty.Type) schema.Object {
attributes[name] = aSchema
}
return schema.Object{
Attributes: attributes,
Attributes: attributes,
AllowInterpolatedKeys: true,
}
}

Expand All @@ -314,7 +317,8 @@ func convertJsonAttributesToObjectConstraint(attrs map[string]*tfjson.SchemaAttr
}
}
return schema.Object{
Attributes: attributes,
Attributes: attributes,
AllowInterpolatedKeys: true,
}
}

Expand Down
5 changes: 5 additions & 0 deletions schema/convert_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func TestProviderSchemaFromJson_basic(t *testing.T) {
Constraint: schema.AnyExpression{OfType: cty.Bool},
},
},
AllowInterpolatedKeys: true,
},
},
},
Expand Down Expand Up @@ -208,6 +209,7 @@ func TestProviderSchemaFromJson_basic(t *testing.T) {
Constraint: schema.AnyExpression{OfType: cty.Bool},
},
},
AllowInterpolatedKeys: true,
},
},
},
Expand Down Expand Up @@ -412,12 +414,14 @@ func TestProviderSchemaFromJson_nested_set_list(t *testing.T) {
Constraint: schema.AnyExpression{OfType: cty.String},
},
},
AllowInterpolatedKeys: true,
},
},
},
},
},
},
AllowInterpolatedKeys: true,
},
},
},
Expand Down Expand Up @@ -480,6 +484,7 @@ func TestProviderSchemaFromJson_nested_set_list(t *testing.T) {
Constraint: schema.AnyExpression{OfType: cty.String},
},
},
AllowInterpolatedKeys: true,
},
},
},
Expand Down
69 changes: 46 additions & 23 deletions schema/schema_merge_v012_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand All @@ -112,7 +113,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand All @@ -134,7 +136,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -197,7 +200,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
},
Expand Down Expand Up @@ -226,7 +230,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -280,7 +285,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -391,7 +397,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -450,7 +457,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -501,7 +509,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -611,7 +620,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -682,7 +692,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
},
Expand Down Expand Up @@ -711,7 +722,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -765,7 +777,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -876,7 +889,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -935,7 +949,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -986,7 +1001,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -1096,7 +1112,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand Down Expand Up @@ -1158,7 +1175,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand All @@ -1172,7 +1190,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
},
Expand Down Expand Up @@ -1210,7 +1229,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand All @@ -1224,7 +1244,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
},
Expand Down Expand Up @@ -1262,7 +1283,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
IsOptional: true,
Expand All @@ -1276,7 +1298,8 @@ var expectedMergedSchema_v012 = &schema.BodySchema{
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.String), SkipLiteralComplexTypes: true},
schema.Map{
Elem: schema.AnyExpression{OfType: cty.String},
Elem: schema.AnyExpression{OfType: cty.String},
AllowInterpolatedKeys: true,
},
},
},
Expand Down
Loading