Skip to content

Commit

Permalink
schemahcl: allow set for_each on tuple any (#2466)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m authored Jan 22, 2024
1 parent 549a508 commit 2e16a5b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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

0 comments on commit 2e16a5b

Please sign in to comment.