Skip to content

Commit

Permalink
Merge pull request #999 from AlexsLemonade/davidsmejia/terraform-1-0-…
Browse files Browse the repository at this point in the history
…8-updates

terraform 1.0.8 updates
  • Loading branch information
davidsmejia authored Nov 22, 2024
2 parents 51b5eeb + c2d2035 commit b1d2c0d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
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

0 comments on commit b1d2c0d

Please sign in to comment.