Skip to content

Commit

Permalink
Merge branch '204-terraform-does-not-know-when-runs-are-approved-in-u…
Browse files Browse the repository at this point in the history
…i' into 'main'

Resolve "Terraform does not know when runs are approved in UI"

Closes #204

See merge request pub/terra/terrarun!105
  • Loading branch information
MatthewJohn committed Aug 12, 2024
2 parents a72eb2a + 399a0bd commit 1a517e6
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 85 deletions.
20 changes: 10 additions & 10 deletions terrarun/job_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

from terrarun.database import Database
import terrarun.models.organisation
import terrarun.models.run_queue
import terrarun.models.agent
import terrarun.models.apply
import terrarun.models.configuration
import terrarun.models.project
import terrarun.models.run
import terrarun.models.run_flow
import terrarun.models.run_queue
import terrarun.models.workspace
import terrarun.models.environment
Expand Down Expand Up @@ -191,29 +191,29 @@ def handle_plan_status_update(self, job_status):

# Update run status
## Do not update run status if is has been cancelled
if run.status == terrarun.models.run.RunStatus.CANCELED:
if run.status == terrarun.models.run_flow.RunStatus.CANCELED:
# Unlock workspace
run.unlock_workspace()
return

elif plan_status is terrarun.terraform_command.TerraformCommandState.RUNNING:
run.update_status(terrarun.models.run.RunStatus.PLANNING)
run.update_status(terrarun.models.run_flow.RunStatus.PLANNING)

elif plan_status is terrarun.terraform_command.TerraformCommandState.ERRORED:
run.update_status(terrarun.models.run.RunStatus.ERRORED)
run.update_status(terrarun.models.run_flow.RunStatus.ERRORED)
# Unlock workspace
run.unlock_workspace()
return

elif plan_status is terrarun.terraform_command.TerraformCommandState.FINISHED:
if run.plan_only or run.configuration_version.speculative or not run.plan.has_changes:
run.update_status(terrarun.models.run.RunStatus.PLANNED_AND_FINISHED)
run.update_status(terrarun.models.run_flow.RunStatus.PLANNED_AND_FINISHED)
# Unlock workspace
run.unlock_workspace()
return

else:
run.update_status(terrarun.models.run.RunStatus.PLANNED)
run.update_status(terrarun.models.run_flow.RunStatus.PLANNED)
terrarun.models.apply.Apply.create(plan=run.plan)

# Queue worker job for next stages
Expand Down Expand Up @@ -241,22 +241,22 @@ def handle_apply_status_update(cls, job_status):

# Update run status
## Do not update run status if is has been cancelled
if run.status == terrarun.models.run.RunStatus.CANCELED:
if run.status == terrarun.models.run_flow.RunStatus.CANCELED:
# Unlock workspace
run.unlock_workspace()
return

elif apply_status is terrarun.terraform_command.TerraformCommandState.RUNNING:
run.update_status(terrarun.models.run.RunStatus.APPLYING)
run.update_status(terrarun.models.run_flow.RunStatus.APPLYING)

elif apply_status is terrarun.terraform_command.TerraformCommandState.ERRORED:
run.update_status(terrarun.models.run.RunStatus.ERRORED)
run.update_status(terrarun.models.run_flow.RunStatus.ERRORED)
# Unlock workspace
run.unlock_workspace()
return

elif apply_status is terrarun.terraform_command.TerraformCommandState.FINISHED:
run.update_status(terrarun.models.run.RunStatus.APPLIED)
run.update_status(terrarun.models.run_flow.RunStatus.APPLIED)
# Unlock workspace
run.unlock_workspace()

Expand Down
11 changes: 6 additions & 5 deletions terrarun/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from terrarun.models.blob import Blob
from terrarun.models.ingress_attribute import IngressAttribute
import terrarun.models.run
import terrarun.models.run_flow
import terrarun.models.workspace
from terrarun.object_storage import ObjectStorage
import terrarun.presign
Expand Down Expand Up @@ -296,14 +297,14 @@ def can_create_run(self, speculative):
run_found = True
# Check for any statuses that indicate that plan has completed successfully
if run.status in [
terrarun.models.run.RunStatus.PLANNED_AND_FINISHED, terrarun.models.run.RunStatus.PLANNED,
terrarun.models.run.RunStatus.APPLY_QUEUED, terrarun.models.run.RunStatus.APPLYING,
terrarun.models.run.RunStatus.PRE_APPLY_RUNNING, terrarun.models.run.RunStatus.PRE_APPLY_COMPLETED,
terrarun.models.run.RunStatus.POST_PLAN_RUNNING, terrarun.models.run.RunStatus.POST_PLAN_COMPLETED]:
terrarun.models.run_flow.RunStatus.PLANNED_AND_FINISHED, terrarun.models.run_flow.RunStatus.PLANNED,
terrarun.models.run_flow.RunStatus.APPLY_QUEUED, terrarun.models.run_flow.RunStatus.APPLYING,
terrarun.models.run_flow.RunStatus.PRE_APPLY_RUNNING, terrarun.models.run_flow.RunStatus.PRE_APPLY_COMPLETED,
terrarun.models.run_flow.RunStatus.POST_PLAN_RUNNING, terrarun.models.run_flow.RunStatus.POST_PLAN_COMPLETED]:
successful_plan_found = True

# Check for states that indicate that apply has completed successfully
if run.status in [terrarun.models.run.RunStatus.APPLIED]:
if run.status in [terrarun.models.run_flow.RunStatus.APPLIED]:
successful_plan_found = True
successful_apply_found = True

Expand Down
Loading

0 comments on commit 1a517e6

Please sign in to comment.