dynamic block MinItems MaxItems validation test
This commit is contained in:
parent
3e49c4b388
commit
d351d712c4
|
@ -2008,3 +2008,95 @@ func TestContext2Validate_sensitiveProvisionerConfig(t *testing.T) {
|
||||||
t.Fatal("ValidateProvisionerConfig not called")
|
t.Fatal("ValidateProvisionerConfig not called")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Plan_validateMinMaxDynamicBlock(t *testing.T) {
|
||||||
|
p := new(MockProvider)
|
||||||
|
p.GetProviderSchemaResponse = getProviderSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"test_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"things": {
|
||||||
|
Type: cty.List(cty.String),
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BlockTypes: map[string]*configschema.NestedBlock{
|
||||||
|
"foo": {
|
||||||
|
Block: configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"bar": {Type: cty.String, Optional: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Nesting: configschema.NestingList,
|
||||||
|
MinItems: 2,
|
||||||
|
MaxItems: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
m := testModuleInline(t, map[string]string{
|
||||||
|
"main.tf": `
|
||||||
|
resource "test_instance" "a" {
|
||||||
|
// MinItems 2
|
||||||
|
foo {
|
||||||
|
bar = "a"
|
||||||
|
}
|
||||||
|
foo {
|
||||||
|
bar = "b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "test_instance" "b" {
|
||||||
|
// one dymamic block can satisfy MinItems of 2
|
||||||
|
dynamic "foo" {
|
||||||
|
for_each = test_instance.a.things
|
||||||
|
content {
|
||||||
|
bar = foo.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "test_instance" "c" {
|
||||||
|
// we may have more than MaxItems dynamic blocks when they are unknown
|
||||||
|
foo {
|
||||||
|
bar = "b"
|
||||||
|
}
|
||||||
|
dynamic "foo" {
|
||||||
|
for_each = test_instance.a.things
|
||||||
|
content {
|
||||||
|
bar = foo.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dynamic "foo" {
|
||||||
|
for_each = test_instance.a.things
|
||||||
|
content {
|
||||||
|
bar = "${foo.value}-2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dynamic "foo" {
|
||||||
|
for_each = test_instance.b.things
|
||||||
|
content {
|
||||||
|
bar = foo.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`})
|
||||||
|
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Config: m,
|
||||||
|
Providers: map[addrs.Provider]providers.Factory{
|
||||||
|
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
diags := ctx.Validate()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatal(diags.ErrWithWarnings())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue