Skip to content

Commit

Permalink
Merge pull request #992 from AlexsLemonade/davidsmejia/temp-ignore-lock
Browse files Browse the repository at this point in the history
add unlock_state and use it to unlock failed command
  • Loading branch information
davidsmejia authored Nov 22, 2024
2 parents d5ce4a7 + e1be89f commit 19828c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions infrastructure/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from init_terraform import init_terraform
from replace_provider import replace_provider
from unlock_state import unlock_state

PRIVATE_KEY_FILE_PATH = "scpca-portal-key.pem"
PUBLIC_KEY_FILE_PATH = "scpca-portal-key.pub"
Expand Down Expand Up @@ -241,6 +242,11 @@ def restart_api_if_still_running(args, api_ip_address):
if init_code != 0:
exit(init_code)

unlock_code = unlock_state("5eb1ff49-db2d-949a-a4f4-91692b16c525")

if unlock_code != 0:
exit(unlock_code)

replace_provider_code = replace_provider("hashicorp", "aws")

if replace_provider_code != 0:
Expand Down
22 changes: 22 additions & 0 deletions infrastructure/unlock_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import signal
import subprocess


def unlock_state(lock_id):
"""
Replaces the aws provider.
Takes an org name, and a provider,
and changes the terraform state to use the new qualified provider.
"""

# Make sure that Terraform is allowed to shut down gracefully.
try:
command = ["terraform", "force-unlock", "-force", lock_id]
terraform_process = subprocess.Popen(command)
terraform_process.wait()
except KeyboardInterrupt:
terraform_process.send_signal(signal.SIGINT)
terraform_process.wait()

# ignore error
return 1

0 comments on commit 19828c7

Please sign in to comment.