Add repro test case for bug #2892
This commit is contained in:
parent
c4a6a8f09a
commit
2b60d0c6b6
|
@ -10,6 +10,8 @@ import (
|
|||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
)
|
||||
|
||||
func TestContext2Apply(t *testing.T) {
|
||||
|
@ -298,6 +300,88 @@ func TestContext2Apply_destroyComputed(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// https://github.com/hashicorp/terraform/issues/2892
|
||||
func TestContext2Apply_destroyCrossProviders(t *testing.T) {
|
||||
m := testModule(t, "apply-destroy-cross-providers")
|
||||
|
||||
p_aws := testProvider("aws")
|
||||
p_aws.ApplyFn = testApplyFn
|
||||
p_aws.DiffFn = testDiffFn
|
||||
|
||||
p_tf := testProvider("terraform")
|
||||
p_tf.ApplyFn = testApplyFn
|
||||
p_tf.DiffFn = testDiffFn
|
||||
|
||||
providers := map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p_aws),
|
||||
"terraform": testProviderFuncFixed(p_tf),
|
||||
}
|
||||
|
||||
// Bug only appears from time to time,
|
||||
// so we run this test multiple times
|
||||
// to check for the race-condition
|
||||
for i := 0; i <= 10; i++ {
|
||||
ctx := getContextForApply_destroyCrossProviders(
|
||||
t, m, providers)
|
||||
|
||||
if p, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
} else {
|
||||
t.Logf(p.String())
|
||||
}
|
||||
|
||||
if _, err := ctx.Apply(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getContextForApply_destroyCrossProviders(
|
||||
t *testing.T,
|
||||
m *module.Tree,
|
||||
providers map[string]ResourceProviderFactory) *Context {
|
||||
state := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"terraform_remote_state.shared": &ResourceState{
|
||||
Type: "terraform_remote_state",
|
||||
Primary: &InstanceState{
|
||||
ID: "remote-2652591293",
|
||||
Attributes: map[string]string{
|
||||
"output.env_name": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&ModuleState{
|
||||
Path: []string{"root", "example"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_vpc.bar": &ResourceState{
|
||||
Type: "aws_vpc",
|
||||
Primary: &InstanceState{
|
||||
ID: "vpc-aaabbb12",
|
||||
Attributes: map[string]string{
|
||||
"value": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: providers,
|
||||
State: state,
|
||||
Destroy: true,
|
||||
})
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
func TestContext2Apply_minimal(t *testing.T) {
|
||||
m := testModule(t, "apply-minimal")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
variable "value" {}
|
||||
|
||||
resource "aws_vpc" "bar" {
|
||||
value = "${var.value}"
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
resource "terraform_remote_state" "shared" {}
|
||||
|
||||
module "child" {
|
||||
source = "./child"
|
||||
value = "${terraform_remote_state.shared.output.env_name}"
|
||||
}
|
Loading…
Reference in New Issue