test a dynamic block with MinItems in the schema
A dynamic block is always going to be a single value during validation, but should not fail when min-items > 1 is specified.
This commit is contained in:
parent
6e5c6cbdea
commit
c658fe173a
|
@ -95,7 +95,19 @@ func testResourceList() *schema.Resource {
|
|||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
|
||||
"min_items": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
MinItems: 2,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"val": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"never_set": {
|
||||
Type: schema.TypeList,
|
||||
MaxItems: 1,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -481,3 +482,54 @@ resource "test_resource_list" "b" {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestResourceList_dynamicMinItems(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckResourceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
variable "a" {
|
||||
type = list(number)
|
||||
default = [1]
|
||||
}
|
||||
|
||||
resource "test_resource_list" "b" {
|
||||
dynamic "min_items" {
|
||||
for_each = var.a
|
||||
content {
|
||||
val = "foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
`),
|
||||
ExpectError: regexp.MustCompile(`attribute supports 2`),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
resource "test_resource_list" "a" {
|
||||
dependent_list {
|
||||
val = "a"
|
||||
}
|
||||
|
||||
dependent_list {
|
||||
val = "b"
|
||||
}
|
||||
}
|
||||
resource "test_resource_list" "b" {
|
||||
list_block {
|
||||
string = "constant"
|
||||
}
|
||||
dynamic "min_items" {
|
||||
for_each = test_resource_list.a.computed_list
|
||||
content {
|
||||
val = min_items.value
|
||||
}
|
||||
}
|
||||
}
|
||||
`),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue