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..5338ee89 --- /dev/null +++ b/infrastructure/unlock_state.py @@ -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