Skip to content

Commit

Permalink
decoder: allow objects in for_each (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Oct 11, 2023
1 parent f75ab3a commit 6ec57d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
16 changes: 15 additions & 1 deletion decoder/body_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func TestCompletionAtPos_BodySchema_Extensions_ForEach(t *testing.T) {
Value: "A meta-argument that accepts a map or a set of strings, and creates an instance for each item in that map or set.\n\n**Note**: A given block cannot use both `count` and `for_each`.",
Kind: lang.MarkdownKind,
},
Detail: "optional, map of any single type or set of string",
Detail: "optional, map of any single type or set of string or object",
TextEdit: lang.TextEdit{
Range: hcl.Range{
Filename: "test.tf",
Expand Down Expand Up @@ -1102,6 +1102,20 @@ for_each =
},
Kind: lang.SetCandidateKind,
},
{
Label: "{ }",
Detail: "object",
TextEdit: lang.TextEdit{
Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{Line: 2, Column: 12, Byte: 43},
End: hcl.Pos{Line: 2, Column: 12, Byte: 43},
},
NewText: "{\n}",
Snippet: "{\n}",
},
Kind: lang.ObjectCandidateKind,
},
}),
},
}
Expand Down
2 changes: 1 addition & 1 deletion decoder/hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ func TestDecoder_HoverAtPos_extension_for_each(t *testing.T) {
hcl.Pos{Line: 2, Column: 5, Byte: 26},
&lang.HoverData{
Content: lang.MarkupContent{
Value: "**for_each** _optional, map of any single type or set of string_\n\n" +
Value: "**for_each** _optional, map of any single type or set of string or object_\n\n" +
"A meta-argument that accepts a map or a set of strings, and creates an instance for each item in that map or set.\n\n" +
"**Note**: A given block cannot use both `count` and `for_each`.",
Kind: lang.MarkdownKind,
Expand Down
6 changes: 6 additions & 0 deletions decoder/internal/schemahelper/attribute_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func ForEachAttributeSchema() *schema.AttributeSchema {
Constraint: schema.OneOf{
schema.AnyExpression{OfType: cty.Map(cty.DynamicPseudoType)},
schema.AnyExpression{OfType: cty.Set(cty.String)},
// Objects are still supported for backwards-compatible reasons
// but in general should be avoided here. We add it here because
// otherwise valid configuration would be flagged as invalid.
// We cannot suppress it in completion (yet) or otherwise inform
// the user of this anti-pattern though.
schema.AnyExpression{OfType: cty.EmptyObject},
},
Description: lang.Markdown("A meta-argument that accepts a map or a set of strings, and creates an instance for each item in that map or set.\n\n" +
"**Note**: A given block cannot use both `count` and `for_each`."),
Expand Down

0 comments on commit 6ec57d4

Please sign in to comment.