@@ -90,11 +90,20 @@ func (r *Runner) init() error {
90
90
91
91
func (r * Runner ) plan () {
92
92
log .Print ("Launching terraform plan" )
93
- _ , err := r .terraform .Plan (context .Background (), tfexec .Out (PlanArtifact ))
93
+ diff , err := r .terraform .Plan (context .Background (), tfexec .Out (PlanArtifact ))
94
94
if err != nil {
95
95
log .Printf ("Terraform plan errored: %s" , err )
96
96
return
97
97
}
98
+ log .Printf ("Setting last plan date cache at key %s" , r .config .Runner .Layer .PlanDate )
99
+ err = r .cache .Set (r .config .Runner .Layer .PlanDate , []byte (strconv .FormatInt (time .Now ().Unix (), 10 )), 3600 )
100
+ if err != nil {
101
+ log .Fatalf ("Could not put plan date in cache: %s" , err )
102
+ }
103
+ if ! diff {
104
+ log .Printf ("Terraform plan diff empty, no subsequent apply should be launched" )
105
+ return
106
+ }
98
107
plan , err := os .ReadFile (fmt .Sprintf ("%s/%s" , r .terraform .WorkingDir (), PlanArtifact ))
99
108
if err != nil {
100
109
log .Fatalf ("Could not read plan output: %s" , err )
@@ -112,11 +121,6 @@ func (r *Runner) plan() {
112
121
if err != nil {
113
122
log .Fatalf ("Could not put plan checksum in cache: %s" , err )
114
123
}
115
- log .Printf ("Setting last plan date cache at key %s" , r .config .Runner .Layer .PlanDate )
116
- err = r .cache .Set (r .config .Runner .Layer .PlanDate , []byte (strconv .FormatInt (time .Now ().Unix (), 10 )), 3600 )
117
- if err != nil {
118
- log .Fatalf ("Could not put plan date in cache: %s" , err )
119
- }
120
124
}
121
125
122
126
func (r * Runner ) apply () {
0 commit comments