Skip to content

Commit

Permalink
add replace_provider command and call after init_terraform in deploy …
Browse files Browse the repository at this point in the history
…script
  • Loading branch information
avrohomgottlieb committed Nov 22, 2024
1 parent a66f456 commit 46b0868
Show file tree
Hide file tree
Showing 2 changed files with 33 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 @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions infrastructure/replace_provider.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 46b0868

Please sign in to comment.