From 4b8de15c1968c71ba3bf1c0191158a773632f204 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 22 Nov 2024 15:41:32 -0500 Subject: [PATCH 1/3] add unlock_state and use it to unlock failed command --- infrastructure/deploy.py | 6 ++++++ infrastructure/unlock_state.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 infrastructure/unlock_state.py diff --git a/infrastructure/deploy.py b/infrastructure/deploy.py index c913bdf7..b3ca1ec0 100644 --- a/infrastructure/deploy.py +++ b/infrastructure/deploy.py @@ -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" @@ -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: diff --git a/infrastructure/unlock_state.py b/infrastructure/unlock_state.py new file mode 100644 index 00000000..c80efef9 --- /dev/null +++ b/infrastructure/unlock_state.py @@ -0,0 +1,27 @@ +import signal +import subprocess + + +def replace_provider(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 From ff982013074d579cafa2d64d06ed732bd8f59290 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 22 Nov 2024 15:44:27 -0500 Subject: [PATCH 2/3] rename unlock_state --- infrastructure/unlock_state.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/unlock_state.py b/infrastructure/unlock_state.py index c80efef9..bb83852a 100644 --- a/infrastructure/unlock_state.py +++ b/infrastructure/unlock_state.py @@ -2,7 +2,7 @@ import subprocess -def replace_provider(lock_id): +def unlock_state(lock_id): """ Replaces the aws provider. Takes an org name, and a provider, From e1be89f10a41003d6f52127ee1fcbd787da3a3c9 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 22 Nov 2024 15:45:29 -0500 Subject: [PATCH 3/3] linting --- infrastructure/unlock_state.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/infrastructure/unlock_state.py b/infrastructure/unlock_state.py index bb83852a..5338ee89 100644 --- a/infrastructure/unlock_state.py +++ b/infrastructure/unlock_state.py @@ -11,12 +11,7 @@ def unlock_state(lock_id): # Make sure that Terraform is allowed to shut down gracefully. try: - command = [ - "terraform", - "force-unlock", - "-force", - lock_id - ] + command = ["terraform", "force-unlock", "-force", lock_id] terraform_process = subprocess.Popen(command) terraform_process.wait() except KeyboardInterrupt: