Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform 1.0.8 updates #999

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions infrastructure/deploy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""This script deploys the cloud infrastructure for the ScPCA project."""

import argparse
import json
import os
import re
import signal
import subprocess
import time
Expand Down Expand Up @@ -158,13 +158,19 @@ def run_terraform(args):
terraform_process.wait()

terraform_process = subprocess.Popen(
["terraform", "apply", var_file_arg, "-auto-approve"], stdout=subprocess.PIPE
["terraform", "apply", var_file_arg, "-auto-approve"],
stdout=subprocess.PIPE,
)
output = ""
for line in iter(terraform_process.stdout.readline, b""):
decoded_line = line.decode("utf-8")
print(decoded_line, end="")
output += decoded_line

terraform_process.wait()

terraform_process = subprocess.Popen(
["terraform", "output", "-json"], stdout=subprocess.PIPE
)

terraform_process.wait()

output = json.loads(terraform_process.stdout)

terraform_process.wait()

Expand Down Expand Up @@ -244,14 +250,13 @@ def restart_api_if_still_running(args, api_ip_address):
if terraform_code != 0:
exit(terraform_code)

ip_address_match = re.match(
r".*\napi_server_1_ip = \"(\d+\.\d+\.\d+\.\d+)\"\n.*", terraform_output, re.DOTALL
)
api_ip_key = "api_server_1_ip"
api_ip_address = terraform_output.get(api_ip_key, None)

if ip_address_match:
api_ip_address = ip_address_match.group(1)
else:
if not api_ip_address:
print("Could not find the API's IP address. Something has gone wrong or changed.")
print(f"{api_ip_key} not defined in outputs:")
print(json.dumps(terraform_output, indent=2))
exit(1)

# Create a key file from env var
Expand Down
40 changes: 14 additions & 26 deletions infrastructure/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ resource "aws_s3_bucket" "scpca_portal_cert_bucket" {
bucket = "scpca-portal-cert-${var.user}-${var.stage}"
force_destroy = var.stage == "prod" ? false : true

# TODO: remove lifecycle rule when we upgrade aws_provider version
lifecycle_rule {
id = "auto-delete-after-30-days-${var.user}-${var.stage}"
prefix = ""
enabled = true
abort_incomplete_multipart_upload_days = 1

expiration {
days = 30
}
}

tags = merge(
var.default_tags,
{
Expand All @@ -70,20 +58,20 @@ resource "aws_s3_bucket_acl" "scpca_portal_cert_bucket" {
acl = "private"
}

# resource "aws_s3_bucket_lifecycle_configuration" "scpca_portal_cert_bucket" {
# bucket = aws_s3_bucket.scpca_portal_cert_bucket.id
# rule {
# id = "auto-delete-after-30-days-${var.user}-${var.stage}"
# status = "Enabled"
# abort_incomplete_multipart_upload {
# days_after_initiation = 1
# }
#
# expiration {
# days = 30
# }
# }
#}
resource "aws_s3_bucket_lifecycle_configuration" "scpca_portal_cert_bucket" {
bucket = aws_s3_bucket.scpca_portal_cert_bucket.id
rule {
id = "auto-delete-after-30-days-${var.user}-${var.stage}"
status = "Enabled"
abort_incomplete_multipart_upload {
days_after_initiation = 1
}

expiration {
days = 30
}
}
}

resource "aws_s3_bucket_public_access_block" "scpca_portal_cert_bucket" {
bucket = aws_s3_bucket.scpca_portal_cert_bucket.id
Expand Down
Loading