Spacelift custom workflow Error: Failed to load "spacelift.plan" as a plan file

23 views Asked by At

I am trying to customize spacelift workflow to run Terragrunt.Here is my workflow.yml file

init: terragrunt init 
workspaceSelect: terragrunt workspace select "{{ .WorkspaceName }}"
workspaceNew: terragrunt workspace new "{{ .WorkspaceName }}"
plan: terragrunt plan -input=false -lock={{ .Lock }} {{ if not .Refresh }}-refresh=false {{ end }}-out={{ .PlanFileName }} {{ range .Targets }}-target='{{ . }}' {{ end }}  
showState: terragrunt show -json   
showPlan: terragrunt show -json "{{ .PlanFileName }}"  
getOutputs: terragrunt output -json 
apply: terraform apply -auto-approve -input=false "{{ .PlanFileName }}"
destroy: terraform destroy -auto-approve -input=false

When I run my stack it generates proper plan

Plan: 3 to add, 1 to change, 1 to destroy.

In addition I can see the following spacelift log

[01HP03C0GY022KG636NYTHYCC6] Changes are GO
[01HP03C0GY022KG636NYTHYCC6] Uploading the list of managed resources...
[01HP03C0GY022KG636NYTHYCC6] Please be aware that the run changes calculation includes output changes.
[01HP03C0GY022KG636NYTHYCC6] Resource list upload is GO
[01HP03C0GY022KG636NYTHYCC6] Generating JSON representation of the plan...
[01HP03C0GY022KG636NYTHYCC6] JSON representation is GO
[01HP03C0GY022KG636NYTHYCC6] Loading custom plan policy inputs...
[01HP03C0GY022KG636NYTHYCC6] 0 custom plan policy inputs found
[01HP03C0GY022KG636NYTHYCC6] No plan policies to evaluate
[01HP03C0GY022KG636NYTHYCC6] Encrypting workspace...
[01HP03C0GY022KG636NYTHYCC6] Uploading workspace...
[01HP03C0GY022KG636NYTHYCC6] Workspace upload is GO

When I am trying to apply the plan, spacelift fails with the following

[01HP03C0GY022KG636NYTHYCC6] Merging .terraformrc files...
[01HP03C0GY022KG636NYTHYCC6] .terraformrc files merged successfully
[01HP03C0GY022KG636NYTHYCC6] Running 0 custom hooks...
[01HP03C0GY022KG636NYTHYCC6] Applying changes...
╷
│ Error: Failed to load "spacelift.plan" as a plan file
│ 
│ Error: stat spacelift.plan: no such file or directory
╵
[01HP03C0GY022KG636NYTHYCC6] Unexpected exit code when applying changes: 1
[01HP03C0GY022KG636NYTHYCC6] Uploading the list of managed resources...
time=2024-02-07T16:08:56Z level=info msg=Downloading Terraform configurations from file:///mnt/workspace/source/modules into /mnt/workspace/source/dev/eastus2/003/shared/.terragrunt-cache/7y28-uwVnav45dnHX4MKA9pePbU/2bbKStLKC7_dlyv56pDlSV3G8Ss
[01HP03C0GY022KG636NYTHYCC6] Resource list upload is GO

It looks like spacelift.plan is generated by plan command but it is not available for the apply.

1

There are 1 answers

0
Alexey Auslender On

The mistake was in workflow.yml implementation, my final version is

init: terragrunt init 
workspaceSelect: terragrunt workspace select "{{ .WorkspaceName }}"
workspaceNew: terragrunt workspace new "{{ .WorkspaceName }}"
plan: terragrunt plan -lock={{ .Lock }} {{ if not .Refresh }}-refresh=false {{ end }}-out={{ .PlanFileName }} {{ range .Targets }}-target='{{ . }}' {{ end }}  
showState: terragrunt show -json   
showPlan: terragrunt show -json "{{ .PlanFileName }}"  
getOutputs: terragrunt output -json 
apply: terragrunt apply -auto-approve
destroy: terragrunt destroy -auto-approve -input=false

I used terraform instead of terragrunt in apply command.