diff --git a/infrastructure/deploy.py b/infrastructure/deploy.py index 69189a7e..c913bdf7 100644 --- a/infrastructure/deploy.py +++ b/infrastructure/deploy.py @@ -8,6 +8,7 @@ import time from init_terraform import init_terraform +from replace_provider import replace_provider PRIVATE_KEY_FILE_PATH = "scpca-portal-key.pem" PUBLIC_KEY_FILE_PATH = "scpca-portal-key.pub" @@ -240,6 +241,11 @@ def restart_api_if_still_running(args, api_ip_address): if init_code != 0: exit(init_code) + replace_provider_code = replace_provider("hashicorp", "aws") + + if replace_provider_code != 0: + exit(replace_provider_code) + terraform_code, terraform_output = run_terraform(args) if terraform_code != 0: exit(terraform_code) diff --git a/infrastructure/replace_provider.py b/infrastructure/replace_provider.py new file mode 100644 index 00000000..e6914167 --- /dev/null +++ b/infrastructure/replace_provider.py @@ -0,0 +1,27 @@ +import signal +import subprocess + + +def replace_provider(org, provider): + """ + 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", + "state", + "replace-provider", + f"registry.terraform.io/-/{provider}", + f"registry.terraform.io/{org}/{provider}", + ] + terraform_process = subprocess.Popen(command) + terraform_process.wait() + except KeyboardInterrupt: + terraform_process.send_signal(signal.SIGINT) + terraform_process.wait() + + return terraform_process.returncode