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

decoder: allow objects in for_each #333

Merged
merged 1 commit into from
Oct 11, 2023
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
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