Skip to content

Commit 4eed21f

Browse files
committed
terraform: issue 5254 test case (not yet working)
1 parent 79281c2 commit 4eed21f

4 files changed

Lines changed: 100 additions & 0 deletions

File tree

‎terraform/context_apply_test.go‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3929,3 +3929,74 @@ func TestContext2Apply_singleDestroy(t *testing.T) {
39293929
t.Fatalf("bad: %d", invokeCount)
39303930
}
39313931
}
3932+
3933+
// GH-5254
3934+
func TestContext2Apply_issue5254(t *testing.T) {
3935+
// Create a provider. We use "template" here just to match the repro
3936+
// we got from the issue itself.
3937+
p := testProvider("template")
3938+
p.ResourcesReturn = append(p.ResourcesReturn, ResourceType{
3939+
Name: "template_file",
3940+
})
3941+
3942+
p.ApplyFn = testApplyFn
3943+
p.DiffFn = testDiffFn
3944+
3945+
// Apply cleanly step 0
3946+
t.Log("Applying Step 0")
3947+
ctx := testContext2(t, &ContextOpts{
3948+
Module: testModule(t, "issue-5254/step-0"),
3949+
Providers: map[string]ResourceProviderFactory{
3950+
"template": testProviderFuncFixed(p),
3951+
},
3952+
})
3953+
3954+
plan, err := ctx.Plan()
3955+
if err != nil {
3956+
t.Fatalf("err: %s", err)
3957+
}
3958+
t.Logf("Plan for Step 0: %s", plan)
3959+
3960+
state, err := ctx.Apply()
3961+
if err != nil {
3962+
t.Fatalf("err: %s", err)
3963+
}
3964+
3965+
// Application success. Now make the modification and store a plan
3966+
t.Log("Planning Step 1")
3967+
ctx = testContext2(t, &ContextOpts{
3968+
Module: testModule(t, "issue-5254/step-1"),
3969+
State: state,
3970+
Providers: map[string]ResourceProviderFactory{
3971+
"template": testProviderFuncFixed(p),
3972+
},
3973+
})
3974+
3975+
plan, err = ctx.Plan()
3976+
if err != nil {
3977+
t.Fatalf("err: %s", err)
3978+
}
3979+
3980+
t.Logf("Plan for Step 1: %s", plan)
3981+
3982+
// Apply the plan
3983+
t.Log("Applying Step 1 (from plan)")
3984+
ctx = plan.Context(&ContextOpts{
3985+
Providers: map[string]ResourceProviderFactory{
3986+
"template": testProviderFuncFixed(p),
3987+
},
3988+
})
3989+
3990+
state, err = ctx.Apply()
3991+
if err != nil {
3992+
t.Fatalf("err: %s", err)
3993+
}
3994+
3995+
/*
3996+
actual := strings.TrimSpace(state.String())
3997+
expected := strings.TrimSpace(testTerraformApplyProviderAliasStr)
3998+
if actual != expected {
3999+
t.Fatalf("bad: \n%s", actual)
4000+
}
4001+
*/
4002+
}

‎terraform/context_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func testDiffFn(
5252
continue
5353
}
5454

55+
// Ignore __-prefixed keys since they're used for magic
56+
if k[0] == '_' && k[1] == '_' {
57+
continue
58+
}
59+
5560
if k == "nil" {
5661
return nil, nil
5762
}
@@ -100,6 +105,9 @@ func testDiffFn(
100105
if k == "require_new" {
101106
attrDiff.RequiresNew = true
102107
}
108+
if _, ok := c.Raw["__"+k+"_requires_new"]; ok {
109+
attrDiff.RequiresNew = true
110+
}
103111
diff.Attributes[k] = attrDiff
104112
}
105113

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable "c" { default = 1 }
2+
3+
resource "template_file" "parent" {
4+
count = "${var.c}"
5+
template = "Hi"
6+
}
7+
8+
resource "template_file" "child" {
9+
template = "${join(",", template_file.parent.*.template)} ok"
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "c" { default = 1 }
2+
3+
resource "template_file" "parent" {
4+
count = "${var.c}"
5+
template = "Hi"
6+
}
7+
8+
resource "template_file" "child" {
9+
template = "${join(",", template_file.parent.*.template)}"
10+
__template_requires_new = 1
11+
}

0 commit comments

Comments
 (0)