@@ -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+ }
0 commit comments