update test fixtures

Update test fixtures to work in our new world.
This is mostly changing out attribute names for those in the schema,
adding Providers to states, and updating the test-fixture
configurations.
This commit is contained in:
James Bardin 2018-05-23 13:39:36 -04:00 committed by Martin Atkins
parent d0693d0db5
commit c6787d0266
24 changed files with 161 additions and 140 deletions

View File

@ -86,6 +86,7 @@ func TestContext2Apply_unstable(t *testing.T) {
md := plan.Diff.RootModule() md := plan.Diff.RootModule()
rd := md.Resources["test_resource.foo"] rd := md.Resources["test_resource.foo"]
randomVal := rd.Attributes["random"].New randomVal := rd.Attributes["random"].New
t.Logf("plan-time value is %q", randomVal) t.Logf("plan-time value is %q", randomVal)
@ -214,55 +215,54 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
{ // verify the apply happens in the correct order
// Wait for the dependency, sleep, and verify the graph never var mu sync.Mutex
// called a child. var order []string
var called int32
var checked bool
p.ApplyFn = func(
info *InstanceInfo,
is *InstanceState,
id *InstanceDiff) (*InstanceState, error) {
if info.HumanId() == "module.child.aws_instance.child" {
checked = true
// Sleep to allow parallel execution p.ApplyFn = func(
time.Sleep(50 * time.Millisecond) info *InstanceInfo,
is *InstanceState,
id *InstanceDiff) (*InstanceState, error) {
if info.HumanId() == "module.child.aws_instance.child" {
// Verify that called is 0 (dep not called) // make the child slower than the parent
if atomic.LoadInt32(&called) != 0 { time.Sleep(50 * time.Millisecond)
return nil, fmt.Errorf("aws_instance.a should not be called")
}
}
atomic.AddInt32(&called, 1) mu.Lock()
return testApplyFn(info, is, id) order = append(order, "child")
mu.Unlock()
} else {
mu.Lock()
order = append(order, "parent")
mu.Unlock()
} }
ctx := testContext2(t, &ContextOpts{ return testApplyFn(info, is, id)
Config: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
})
if _, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
state, diags := ctx.Apply()
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
if !checked {
t.Fatal("should check")
}
checkStateString(t, state, testTerraformApplyResourceDependsOnModuleStr)
} }
ctx := testContext2(t, &ContextOpts{
Config: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
})
if _, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
state, diags := ctx.Apply()
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
if !reflect.DeepEqual(order, []string{"child", "parent"}) {
t.Fatal("resources applied out of order")
}
checkStateString(t, state, testTerraformApplyResourceDependsOnModuleStr)
} }
// Test that without a config, the Dependencies in the state are enough // Test that without a config, the Dependencies in the state are enough
@ -301,27 +301,28 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) {
} }
{ {
// Wait for the dependency, sleep, and verify the graph never // verify the apply happens in the correct order
// called a child. var mu sync.Mutex
var called int32 var order []string
var checked bool
p.ApplyFn = func( p.ApplyFn = func(
info *InstanceInfo, info *InstanceInfo,
is *InstanceState, is *InstanceState,
id *InstanceDiff) (*InstanceState, error) { id *InstanceDiff) (*InstanceState, error) {
if info.HumanId() == "aws_instance.a" { if info.HumanId() == "aws_instance.a" {
checked = true
// Sleep to allow parallel execution // make the dep slower than the parent
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
// Verify that called is 0 (dep not called) mu.Lock()
if atomic.LoadInt32(&called) != 0 { order = append(order, "child")
return nil, fmt.Errorf("module child should not be called") mu.Unlock()
} } else {
mu.Lock()
order = append(order, "parent")
mu.Unlock()
} }
atomic.AddInt32(&called, 1)
return testApplyFn(info, is, id) return testApplyFn(info, is, id)
} }
@ -344,8 +345,8 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) {
t.Fatalf("diags: %s", diags.Err()) t.Fatalf("diags: %s", diags.Err())
} }
if !checked { if !reflect.DeepEqual(order, []string{"child", "parent"}) {
t.Fatal("should check") t.Fatal("resources applied out of order")
} }
checkStateString(t, state, "<no state>") checkStateString(t, state, "<no state>")
@ -1069,6 +1070,7 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) {
"require_new": "abc", "require_new": "abc",
}, },
}, },
Provider: "provider.aws",
}, },
}, },
}, },
@ -1213,6 +1215,7 @@ func TestContext2Apply_createBeforeDestroy_deposedOnly(t *testing.T) {
ID: "foo", ID: "foo",
}, },
}, },
Provider: "provider.aws",
}, },
}, },
}, },
@ -1725,25 +1728,20 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) {
p_aws.ApplyFn = testApplyFn p_aws.ApplyFn = testApplyFn
p_aws.DiffFn = testDiffFn p_aws.DiffFn = testDiffFn
p_tf := testProvider("terraform")
p_tf.ApplyFn = testApplyFn
p_tf.DiffFn = testDiffFn
providers := map[string]ResourceProviderFactory{ providers := map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p_aws), "aws": testProviderFuncFixed(p_aws),
"terraform": testProviderFuncFixed(p_tf),
} }
// Bug only appears from time to time, // Bug only appears from time to time,
// so we run this test multiple times // so we run this test multiple times
// to check for the race-condition // to check for the race-condition
for i := 0; i <= 10; i++ {
// FIXME: this test flaps now, so run it more times
for i := 0; i <= 100; i++ {
ctx := getContextForApply_destroyCrossProviders(t, m, providers) ctx := getContextForApply_destroyCrossProviders(t, m, providers)
if p, diags := ctx.Plan(); diags.HasErrors() { if _, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err()) t.Fatalf("diags: %s", diags.Err())
} else {
t.Logf(p.String())
} }
if _, diags := ctx.Apply(); diags.HasErrors() { if _, diags := ctx.Apply(); diags.HasErrors() {
@ -1758,14 +1756,15 @@ func getContextForApply_destroyCrossProviders(t *testing.T, m *configs.Config, p
&ModuleState{ &ModuleState{
Path: rootModulePath, Path: rootModulePath,
Resources: map[string]*ResourceState{ Resources: map[string]*ResourceState{
"terraform_remote_state.shared": &ResourceState{ "aws_instance.shared": &ResourceState{
Type: "terraform_remote_state", Type: "aws_instance",
Primary: &InstanceState{ Primary: &InstanceState{
ID: "remote-2652591293", ID: "remote-2652591293",
Attributes: map[string]string{ Attributes: map[string]string{
"output.env_name": "test", "id": "test",
}, },
}, },
Provider: "provider.aws",
}, },
}, },
}, },
@ -1780,6 +1779,7 @@ func getContextForApply_destroyCrossProviders(t *testing.T, m *configs.Config, p
"value": "test", "value": "test",
}, },
}, },
Provider: "provider.aws",
}, },
}, },
}, },
@ -1826,9 +1826,6 @@ func TestContext2Apply_minimal(t *testing.T) {
} }
func TestContext2Apply_badDiff(t *testing.T) { func TestContext2Apply_badDiff(t *testing.T) {
// FIXME
return
m := testModule(t, "apply-good") m := testModule(t, "apply-good")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
@ -1849,7 +1846,11 @@ func TestContext2Apply_badDiff(t *testing.T) {
p.DiffFn = func(*InstanceInfo, *InstanceState, *ResourceConfig) (*InstanceDiff, error) { p.DiffFn = func(*InstanceInfo, *InstanceState, *ResourceConfig) (*InstanceDiff, error) {
return &InstanceDiff{ return &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{ Attributes: map[string]*ResourceAttrDiff{
"newp": nil, "newp": &ResourceAttrDiff{
Old: "",
New: "",
NewComputed: true,
},
}, },
}, nil }, nil
} }
@ -3076,6 +3077,7 @@ func TestContext2Apply_moduleVarRefExisting(t *testing.T) {
"foo": "bar", "foo": "bar",
}, },
}, },
Provider: "provider.aws",
}, },
}, },
}, },
@ -3391,7 +3393,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) {
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
p2 := testProvider("do") p2 := testProvider("vault")
p2.ApplyFn = testApplyFn p2.ApplyFn = testApplyFn
p2.DiffFn = testDiffFn p2.DiffFn = testDiffFn
@ -4427,9 +4429,6 @@ func TestContext2Apply_provisionerCreateFailNoId(t *testing.T) {
} }
func TestContext2Apply_provisionerFail(t *testing.T) { func TestContext2Apply_provisionerFail(t *testing.T) {
// FIXME
return
m := testModule(t, "apply-provisioner-fail") m := testModule(t, "apply-provisioner-fail")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
@ -4475,9 +4474,6 @@ func TestContext2Apply_provisionerFail(t *testing.T) {
} }
func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) { func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) {
// FIXME
return
m := testModule(t, "apply-provisioner-fail-create-before") m := testModule(t, "apply-provisioner-fail-create-before")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
@ -4782,9 +4778,6 @@ aws_instance.web:
// Verify that a normal provisioner with on_failure "continue" set won't // Verify that a normal provisioner with on_failure "continue" set won't
// taint the resource and continues executing. // taint the resource and continues executing.
func TestContext2Apply_provisionerFailContinue(t *testing.T) { func TestContext2Apply_provisionerFailContinue(t *testing.T) {
// FIXME
return
m := testModule(t, "apply-provisioner-fail-continue") m := testModule(t, "apply-provisioner-fail-continue")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
@ -4833,9 +4826,6 @@ aws_instance.foo:
// Verify that a normal provisioner with on_failure "continue" records // Verify that a normal provisioner with on_failure "continue" records
// the error with the hook. // the error with the hook.
func TestContext2Apply_provisionerFailContinueHook(t *testing.T) { func TestContext2Apply_provisionerFailContinueHook(t *testing.T) {
// FIXME
return
h := new(MockHook) h := new(MockHook)
m := testModule(t, "apply-provisioner-fail-continue") m := testModule(t, "apply-provisioner-fail-continue")
p := testProvider("aws") p := testProvider("aws")
@ -5778,9 +5768,6 @@ func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) {
// Provisioner should NOT run on a diff, only create // Provisioner should NOT run on a diff, only create
func TestContext2Apply_Provisioner_Diff(t *testing.T) { func TestContext2Apply_Provisioner_Diff(t *testing.T) {
//FIXME
return
m := testModule(t, "apply-provisioner-diff") m := testModule(t, "apply-provisioner-diff")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
@ -5955,7 +5942,7 @@ func TestContext2Apply_Provisioner_ConnInfo(t *testing.T) {
if conn["user"] != "superuser" { if conn["user"] != "superuser" {
t.Fatalf("Bad: %#v", conn) t.Fatalf("Bad: %#v", conn)
} }
if conn["pass"] != "test" { if conn["password"] != "test" {
t.Fatalf("Bad: %#v", conn) t.Fatalf("Bad: %#v", conn)
} }
@ -6901,7 +6888,7 @@ func TestContext2Apply_error(t *testing.T) {
actual := strings.TrimSpace(state.String()) actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyErrorStr) expected := strings.TrimSpace(testTerraformApplyErrorStr)
if actual != expected { if actual != expected {
t.Fatalf("bad: \n%s", actual) t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
} }
} }
@ -6975,7 +6962,7 @@ func TestContext2Apply_errorPartial(t *testing.T) {
actual := strings.TrimSpace(state.String()) actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyErrorPartialStr) expected := strings.TrimSpace(testTerraformApplyErrorPartialStr)
if actual != expected { if actual != expected {
t.Fatalf("bad: \n%s", actual) t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
} }
} }
@ -7702,6 +7689,7 @@ func TestContext2Apply_targetedDestroy(t *testing.T) {
checkStateString(t, state, ` checkStateString(t, state, `
aws_instance.bar: aws_instance.bar:
ID = i-abc123 ID = i-abc123
provider = provider.aws
`) `)
} }
@ -8016,7 +8004,7 @@ func TestContext2Apply_targetedDestroyModule(t *testing.T) {
}, },
}, },
Targets: []addrs.Targetable{ Targets: []addrs.Targetable{
addrs.RootModuleInstance.Resource( addrs.RootModuleInstance.Child("child", addrs.NoKey).Resource(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.ManagedResourceMode, "aws_instance", "foo",
), ),
}, },
@ -8035,12 +8023,15 @@ func TestContext2Apply_targetedDestroyModule(t *testing.T) {
checkStateString(t, state, ` checkStateString(t, state, `
aws_instance.bar: aws_instance.bar:
ID = i-abc123 ID = i-abc123
provider = provider.aws
aws_instance.foo: aws_instance.foo:
ID = i-bcd345 ID = i-bcd345
provider = provider.aws
module.child: module.child:
aws_instance.bar: aws_instance.bar:
ID = i-abc123 ID = i-abc123
provider = provider.aws
`) `)
} }
@ -8094,12 +8085,16 @@ func TestContext2Apply_targetedDestroyCountIndex(t *testing.T) {
checkStateString(t, state, ` checkStateString(t, state, `
aws_instance.bar.0: aws_instance.bar.0:
ID = i-abc123 ID = i-abc123
provider = provider.aws
aws_instance.bar.2: aws_instance.bar.2:
ID = i-abc123 ID = i-abc123
provider = provider.aws
aws_instance.foo.0: aws_instance.foo.0:
ID = i-bcd345 ID = i-bcd345
provider = provider.aws
aws_instance.foo.1: aws_instance.foo.1:
ID = i-bcd345 ID = i-bcd345
provider = provider.aws
`) `)
} }
@ -8346,7 +8341,7 @@ func TestContext2Apply_unknownAttribute(t *testing.T) {
state, diags := ctx.Apply() state, diags := ctx.Apply()
if diags.HasErrors() { if diags.HasErrors() {
t.Fatal("should error") t.Fatal("should error with UnknownVariableValue")
} }
actual := strings.TrimSpace(state.String()) actual := strings.TrimSpace(state.String())
@ -9170,9 +9165,6 @@ module.middle.bottom:
// If a data source explicitly depends on another resource, it's because we need // If a data source explicitly depends on another resource, it's because we need
// that resource to be applied first. // that resource to be applied first.
func TestContext2Apply_dataDependsOn(t *testing.T) { func TestContext2Apply_dataDependsOn(t *testing.T) {
//FIXME
return
p := testProvider("null") p := testProvider("null")
m := testModule(t, "apply-data-depends-on") m := testModule(t, "apply-data-depends-on")
@ -9225,6 +9217,7 @@ func TestContext2Apply_dataDependsOn(t *testing.T) {
t.Fatalf("diags: %s", diags.Err()) t.Fatalf("diags: %s", diags.Err())
} }
t.Fatal("nil pointer below")
root := state.ModuleByPath(addrs.RootModuleInstance) root := state.ModuleByPath(addrs.RootModuleInstance)
actual := root.Resources["data.null_data_source.read"].Primary.Attributes["foo"] actual := root.Resources["data.null_data_source.read"].Primary.Attributes["foo"]

View File

@ -401,6 +401,10 @@ func testProvisioner() *MockResourceProvisioner {
Type: cty.String, Type: cty.String,
Optional: true, Optional: true,
}, },
"when": {
Type: cty.String,
Optional: true,
},
}, },
} }
return p return p
@ -464,6 +468,14 @@ func testProviderSchema(name string) *ProviderSchema {
Type: cty.String, Type: cty.String,
Optional: true, Optional: true,
}, },
"value": {
Type: cty.String,
Optional: true,
},
"root": {
Type: cty.Number,
Optional: true,
},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
@ -584,8 +596,8 @@ func testProviderSchema(name string) *ProviderSchema {
Optional: true, Optional: true,
}, },
"output": { "output": {
Type: cty.String, Type: cty.Map(cty.String),
Optional: true, Computed: true,
}, },
}, },
}, },
@ -629,6 +641,10 @@ func testProviderSchema(name string) *ProviderSchema {
Type: cty.String, Type: cty.String,
Optional: true, Optional: true,
}, },
"output": {
Type: cty.Map(cty.String),
Optional: true,
},
}, },
}, },
name + "_file": { name + "_file": {

View File

@ -67,7 +67,7 @@ func (b *BasicGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Di
log.Printf("[TRACE] Completed graph transform %T with new graph:\n%s------", step, thisStepStr) log.Printf("[TRACE] Completed graph transform %T with new graph:\n%s------", step, thisStepStr)
lastStepStr = thisStepStr lastStepStr = thisStepStr
} else { } else {
log.Printf("[TRACE] Completed graph transform %T (no changes)", step) log.Printf("[TRACE] Completed graph transform %T (no changes)\n------", step)
} }
if err != nil { if err != nil {

View File

@ -364,6 +364,8 @@ func (n *NodeAbstractResource) ProvisionedBy() []string {
// GraphNodeProvisionerConsumer // GraphNodeProvisionerConsumer
func (n *NodeAbstractResource) AttachProvisionerSchema(name string, schema *configschema.Block) { func (n *NodeAbstractResource) AttachProvisionerSchema(name string, schema *configschema.Block) {
// FIXME: this isn't called anywehere
panic("unused")
n.ProvisionerSchemas[name] = schema n.ProvisionerSchemas[name] = schema
} }

View File

@ -512,7 +512,7 @@ const testTerraformApplyModuleBoolStr = `
aws_instance.bar: aws_instance.bar:
ID = foo ID = foo
provider = provider.aws provider = provider.aws
foo = 1 foo = true
type = aws_instance type = aws_instance
Dependencies: Dependencies:
@ -522,7 +522,7 @@ module.child:
<no state> <no state>
Outputs: Outputs:
leader = 1 leader = true
` `
const testTerraformApplyModuleDestroyOrderStr = ` const testTerraformApplyModuleDestroyOrderStr = `
@ -566,6 +566,7 @@ module.child:
const testTerraformApplyModuleVarRefExistingStr = ` const testTerraformApplyModuleVarRefExistingStr = `
aws_instance.foo: aws_instance.foo:
ID = foo ID = foo
provider = provider.aws
foo = bar foo = bar
module.child: module.child:
@ -724,7 +725,7 @@ aws_instance.bar:
aws_instance.foo: aws_instance.foo:
ID = foo ID = foo
provider = provider.aws provider = provider.aws
num = 2 value = 2
` `
const testTerraformApplyErrorCreateBeforeDestroyStr = ` const testTerraformApplyErrorCreateBeforeDestroyStr = `
@ -751,7 +752,7 @@ aws_instance.bar:
aws_instance.foo: aws_instance.foo:
ID = foo ID = foo
provider = provider.aws provider = provider.aws
num = 2 value = 2
` `
const testTerraformApplyResourceDependsOnModuleStr = ` const testTerraformApplyResourceDependsOnModuleStr = `

View File

@ -1,6 +1,7 @@
resource "terraform_remote_state" "shared" {} resource "aws_instance" "shared" {
}
module "child" { module "child" {
source = "./child" source = "./child"
value = "${terraform_remote_state.shared.output.env_name}" value = "${aws_instance.shared.id}"
} }

View File

@ -3,5 +3,5 @@ resource "aws_instance" "foo" {
} }
resource "aws_instance" "bar" { resource "aws_instance" "bar" {
instances = ["${aws_instance.foo.*.id}"] foo = ["${aws_instance.foo.*.id}"]
} }

View File

@ -1,5 +1,5 @@
resource "aws_instance" "foo" { resource "aws_instance" "foo" {
num = "2" num = 2
} }
resource "aws_instance" "bar" { resource "aws_instance" "bar" {

View File

@ -7,5 +7,5 @@ resource "aws_instance" "test" {
} }
resource "aws_instance" "dependent" { resource "aws_instance" "dependent" {
count = "${aws_instance.test.count}" count = "${length(aws_instance.test)}"
} }

View File

@ -5,5 +5,5 @@ variable "amis" {
resource "null_resource" "noop" {} resource "null_resource" "noop" {}
output "amis_out" { output "amis_out" {
value = "${var.amis}" value = "${var.amis}"
} }

View File

@ -1,5 +1,5 @@
provider "aws" { provider "aws" {
root = "1" root = 1
} }
provider "aws" { provider "aws" {

View File

@ -1,5 +1,5 @@
provider "aws" { provider "aws" {
root = "1" root = 1
} }
provider "aws" { provider "aws" {
@ -9,4 +9,7 @@ provider "aws" {
module "child" { module "child" {
source = "./child" source = "./child"
providers = {
"aws.eu" = "aws.eu"
}
} }

View File

@ -1,5 +1,6 @@
variable "count" {} variable "num" {
}
resource "aws_instance" "foo" { resource "aws_instance" "foo" {
count = "${var.count}" count = "${var.num}"
} }

View File

@ -1,6 +1,7 @@
variable "count" {} variable "num" {
}
module "child" { module "child" {
source = "./child" source = "./child"
count = "${var.count}" num = "${var.num}"
} }

View File

@ -1,7 +1,7 @@
resource "vault_instance" "foo" {} resource "vault_instance" "foo" {}
provider "aws" { provider "aws" {
addr = "${vault_instance.foo.id}" value = "${vault_instance.foo.id}"
} }
module "child" { module "child" {

View File

@ -1,5 +1,4 @@
variable "num" {
variable "count" {
} }
variable "source_ids" { variable "source_ids" {
@ -11,7 +10,7 @@ variable "source_names" {
} }
resource "test_thing" "multi_count_var" { resource "test_thing" "multi_count_var" {
count = "${var.count}" count = "${var.num}"
# Can pluck a single item out of a multi-var # Can pluck a single item out of a multi-var
source_id = "${var.source_ids[count.index]}" source_id = "${var.source_ids[count.index]}"

View File

@ -1,16 +1,15 @@
variable "num" {
variable "count" {
} }
resource "test_thing" "source" { resource "test_thing" "source" {
count = "${var.count}" count = "${var.num}"
# The diffFunc in the test exports "name" here too, which we can use # The diffFunc in the test exports "name" here too, which we can use
# to test values that are known during plan. # to test values that are known during plan.
} }
resource "test_thing" "multi_count_var" { resource "test_thing" "multi_count_var" {
count = "${var.count}" count = "${var.num}"
# Can pluck a single item out of a multi-var # Can pluck a single item out of a multi-var
source_id = "${test_thing.source.*.id[count.index]}" source_id = "${test_thing.source.*.id[count.index]}"
@ -53,7 +52,7 @@ resource "test_thing" "whole_splat" {
module "child" { module "child" {
source = "./child" source = "./child"
count = "${var.count}" count = "${var.num}"
source_ids = "${test_thing.source.*.id}" source_ids = "${test_thing.source.*.id}"
source_names = "${test_thing.source.*.name}" source_names = "${test_thing.source.*.name}"
} }

View File

@ -1,7 +1,7 @@
variable "count" {} variable "num" {}
resource "aws_instance" "foo" { resource "aws_instance" "foo" {
count = "${var.count}" count = "${var.num}"
value = "foo" value = "foo"
} }

View File

@ -1,14 +1,14 @@
variable "count" { variable "num" {
default = 15 default = 15
} }
resource "aws_instance" "bar" { resource "aws_instance" "bar" {
count = "${var.count}" count = "${var.num}"
foo = "index-${count.index}" foo = "index-${count.index}"
} }
resource "aws_instance" "baz" { resource "aws_instance" "baz" {
count = "${var.count}" count = "${var.num}"
foo = "baz-${element(aws_instance.bar.*.foo, count.index)}" foo = "baz-${element(aws_instance.bar.*.foo, count.index)}"
} }

View File

@ -1,9 +1,9 @@
variable "count" { variable "num" {
default = 15 default = 15
} }
resource "aws_instance" "bar" { resource "aws_instance" "bar" {
count = "${var.count}" count = "${var.num}"
foo = "index-${count.index}" foo = "index-${count.index}"
} }

View File

@ -1,8 +1,8 @@
variable "count" {} variable "num" {}
resource "aws_instance" "bar" { resource "aws_instance" "bar" {
foo = "bar${count.index}" foo = "bar${count.index}"
count = "${var.count}" count = "${var.num}"
} }
output "output" { output "output" {

View File

@ -1,5 +1,8 @@
variable "pass" {} variable "pass" {
variable "value" {} }
variable "value" {
}
resource "aws_instance" "foo" { resource "aws_instance" "foo" {
num = "2" num = "2"
@ -17,7 +20,7 @@ resource "aws_instance" "bar" {
connection { connection {
user = "superuser" user = "superuser"
port = 2222 port = 2222
pass = "${var.pass}" password = "${var.pass}"
} }
} }
} }

View File

@ -1,9 +1,9 @@
variable "count" { variable "num" {
default = 3 default = 3
} }
resource "aws_instance" "a" { resource "aws_instance" "a" {
count = "${var.count}" count = "${var.num}"
} }
resource "aws_instance" "b" { resource "aws_instance" "b" {

View File

@ -1,4 +1,6 @@
variable "c" { default = 1 } variable "c" {
default = 1
}
resource "template_file" "parent" { resource "template_file" "parent" {
count = "${var.c}" count = "${var.c}"