mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
terraform: test for referencing counts that are from vars
This commit is contained in:
parent
d2e15ab69a
commit
60f212b73e
@ -1156,6 +1156,34 @@ func TestContext2Apply_countVariable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_countVariableRef(t *testing.T) {
|
||||
m := testModule(t, "apply-count-variable-ref")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
expected := strings.TrimSpace(testTerraformApplyCountVariableRefStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_mapVariableOverride(t *testing.T) {
|
||||
m := testModule(t, "apply-map-var-override")
|
||||
p := testProvider("aws")
|
||||
|
@ -386,6 +386,20 @@ aws_instance.foo.1:
|
||||
type = aws_instance
|
||||
`
|
||||
|
||||
const testTerraformApplyCountVariableRefStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
foo = 2
|
||||
type = aws_instance
|
||||
|
||||
Dependencies:
|
||||
aws_instance.foo
|
||||
aws_instance.foo.0:
|
||||
ID = foo
|
||||
aws_instance.foo.1:
|
||||
ID = foo
|
||||
`
|
||||
|
||||
const testTerraformApplyMinimalStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
|
11
terraform/test-fixtures/apply-count-variable-ref/main.tf
Normal file
11
terraform/test-fixtures/apply-count-variable-ref/main.tf
Normal file
@ -0,0 +1,11 @@
|
||||
variable "foo" {
|
||||
default = "2"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
count = "${var.foo}"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${aws_instance.foo.count}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user