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

schemahcl: allow set for_each on tuple any #2466

Merged
merged 1 commit 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 doc/md/atlas-schema/hcl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ or a `set` of references.

```hcl title="schema.pg.hcl" {2-3}
trigger "audit_log_trigger" {
for_each = toset([table.users, table.orders, table.payments])
for_each = [table.users, table.orders, table.payments]
on = each.value
after {
insert = true
Expand Down
2 changes: 1 addition & 1 deletion schemahcl/schemahcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ func forEachBlocks(ctx *hcl.EvalContext, b *hclsyntax.Block) ([]*hclsyntax.Block
if diags.HasErrors() {
return nil, diags
}
if t := forEach.Type(); !t.IsSetType() && !t.IsObjectType() {
if t := forEach.Type(); !t.IsSetType() && !t.IsObjectType() && !t.IsTupleType() {
return nil, fmt.Errorf("schemahcl: for_each does not support %s type", t.FriendlyName())
}
delete(b.Body.Attributes, forEachAttr)
Expand Down
31 changes: 31 additions & 0 deletions schemahcl/schemahcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,37 @@ table "t1" {
table "t2" {
schema = schema.s2
}
`, string(buf))

// Tuple of type any.
b1 = []byte(`
schema "s1" {
comment = "schema comment"
}
schema "s2" {
# object without comment.
}

table {
for_each = [schema.s1, schema.s2]
name = each.value.name
schema = each.value
}
`)
err = New().EvalBytes(b1, &doc1, nil)
require.NoError(t, err)
buf, err = Marshal.MarshalSpec(&doc1)
require.NoError(t, err)
require.Equal(t, `schema "s1" {
}
schema "s2" {
}
table "s1" {
schema = schema.s1
}
table "s2" {
schema = schema.s2
}
`, string(buf))
}

Expand Down
Loading