Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no apply on empty plan #21

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ func (r *Runner) init() error {

func (r *Runner) plan() {
log.Print("Launching terraform plan")
_, err := r.terraform.Plan(context.Background(), tfexec.Out(PlanArtifact))
diff, err := r.terraform.Plan(context.Background(), tfexec.Out(PlanArtifact))
if err != nil {
log.Printf("Terraform plan errored: %s", err)
return
}
log.Printf("Setting last plan date cache at key %s", r.config.Runner.Layer.PlanDate)
err = r.cache.Set(r.config.Runner.Layer.PlanDate, []byte(strconv.FormatInt(time.Now().Unix(), 10)), 3600)
if err != nil {
log.Fatalf("Could not put plan date in cache: %s", err)
}
if !diff {
log.Printf("Terraform plan diff empty, no subsequent apply should be launched")
return
}
plan, err := os.ReadFile(fmt.Sprintf("%s/%s", r.terraform.WorkingDir(), PlanArtifact))
if err != nil {
log.Fatalf("Could not read plan output: %s", err)
Expand All @@ -112,11 +121,6 @@ func (r *Runner) plan() {
if err != nil {
log.Fatalf("Could not put plan checksum in cache: %s", err)
}
log.Printf("Setting last plan date cache at key %s", r.config.Runner.Layer.PlanDate)
err = r.cache.Set(r.config.Runner.Layer.PlanDate, []byte(strconv.FormatInt(time.Now().Unix(), 10)), 3600)
if err != nil {
log.Fatalf("Could not put plan date in cache: %s", err)
}
}

func (r *Runner) apply() {
Expand Down