@@ -22,37 +22,42 @@ import (
2222 "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/terraform/provider"
2323
2424 sdk "github.com/pipe-cd/piped-plugin-sdk-go"
25+ "go.uber.org/zap"
2526)
2627
2728// TODO: add test
2829func (p * Plugin ) executePlanStage (ctx context.Context , input * sdk.ExecuteStageInput [config.ApplicationConfigSpec ], dts []* sdk.DeployTarget [config.DeployTargetConfig ]) sdk.StageStatus {
29- lp := input .Client .LogPersister ()
30+ slp , err := input .Client .StageLogPersister ()
31+ if err != nil {
32+ input .Logger .Error ("No stage log persister available" , zap .Error (err ))
33+ return sdk .StageStatusFailure
34+ }
3035 cmd , err := provider .NewTerraformCommand (ctx , input .Client , input .Request .TargetDeploymentSource , dts [0 ])
3136 if err != nil {
32- lp .Errorf ("Failed to initialize Terraform command (%v)" , err )
37+ slp .Errorf ("Failed to initialize Terraform command (%v)" , err )
3338 return sdk .StageStatusFailure
3439 }
3540
3641 stageConfig := config.TerraformPlanStageOptions {}
3742 if err := json .Unmarshal (input .Request .StageConfig , & stageConfig ); err != nil {
38- lp .Errorf ("Failed to unmarshal stage config (%v)" , err )
43+ slp .Errorf ("Failed to unmarshal stage config (%v)" , err )
3944 return sdk .StageStatusFailure
4045 }
4146
42- planResult , err := cmd .Plan (ctx , lp )
47+ planResult , err := cmd .Plan (ctx , slp )
4348 if err != nil {
44- lp .Errorf ("Failed to plan (%v)" , err )
49+ slp .Errorf ("Failed to plan (%v)" , err )
4550 return sdk .StageStatusFailure
4651 }
4752
4853 if planResult .NoChanges () {
49- lp .Success ("No changes to apply" )
54+ slp .Success ("No changes to apply" )
5055 if stageConfig .ExitOnNoChanges {
5156 return sdk .StageStatusExited
5257 }
5358 return sdk .StageStatusSuccess
5459 }
5560
56- lp .Successf ("Detected %d import, %d add, %d change, %d destroy." , planResult .Imports , planResult .Adds , planResult .Changes , planResult .Destroys )
61+ slp .Successf ("Detected %d import, %d add, %d change, %d destroy." , planResult .Imports , planResult .Adds , planResult .Changes , planResult .Destroys )
5762 return sdk .StageStatusSuccess
5863}
0 commit comments