mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
config: allow local value interpolations in count
There is some additional, early validation on the "count" meta-argument that verifies that only suitable variable types are used, and adding local values to this whitelist was missed in the initial implementation.
This commit is contained in:
parent
8cd0ee80e5
commit
0a342e8dc2
@ -557,6 +557,7 @@ func (c *Config) Validate() error {
|
||||
case *ResourceVariable:
|
||||
case *TerraformVariable:
|
||||
case *UserVariable:
|
||||
case *LocalVariable:
|
||||
|
||||
default:
|
||||
errs = append(errs, fmt.Errorf(
|
||||
|
@ -312,6 +312,13 @@ func TestConfigValidate_countUserVar(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigValidate_countLocalValue(t *testing.T) {
|
||||
c := testConfig(t, "validate-local-value-count")
|
||||
if err := c.Validate(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigValidate_countVar(t *testing.T) {
|
||||
c := testConfig(t, "validate-count-var")
|
||||
if err := c.Validate(); err != nil {
|
||||
|
8
config/test-fixtures/validate-local-value-count/main.tf
Normal file
8
config/test-fixtures/validate-local-value-count/main.tf
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
locals {
|
||||
count = 3
|
||||
}
|
||||
|
||||
resource "null_resource" "foo" {
|
||||
count = "${local.count}"
|
||||
}
|
@ -1294,6 +1294,39 @@ func TestContext2Plan_computedDataCountResource(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Plan_localValueCount(t *testing.T) {
|
||||
m := testModule(t, "plan-local-value-count")
|
||||
p := testProvider("test")
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"test": testProviderFuncFixed(p),
|
||||
},
|
||||
),
|
||||
})
|
||||
|
||||
plan, err := ctx.Plan()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if got := len(plan.Diff.Modules); got != 1 {
|
||||
t.Fatalf("got %d modules; want 1", got)
|
||||
}
|
||||
|
||||
moduleDiff := plan.Diff.Modules[0]
|
||||
|
||||
// make sure we created 3 "bar"s
|
||||
for i := 0; i < 3; i++ {
|
||||
resource := fmt.Sprintf("test_resource.foo.%d", i)
|
||||
if _, ok := moduleDiff.Resources[resource]; !ok {
|
||||
t.Fatalf("missing diff for %s", resource)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Higher level test at TestResource_dataSourceListPlanPanic
|
||||
func TestContext2Plan_dataSourceTypeMismatch(t *testing.T) {
|
||||
m := testModule(t, "plan-data-source-type-mismatch")
|
||||
|
8
terraform/test-fixtures/plan-local-value-count/main.tf
Normal file
8
terraform/test-fixtures/plan-local-value-count/main.tf
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
locals {
|
||||
count = 3
|
||||
}
|
||||
|
||||
resource "test_resource" "foo" {
|
||||
count = "${local.count}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user