Skip to content

Commit

Permalink
changing from terragrunt to s3 download
Browse files Browse the repository at this point in the history
  • Loading branch information
nolan committed Jul 22, 2024
1 parent b24d3f1 commit 36693be
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions gen-wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import re
import yaml
import json
import boto3
import shutil
import argparse
import subprocess
import shutil

TEMP_DIR = 'temp_wiki'

Expand Down Expand Up @@ -66,9 +67,31 @@ def run_terragrunt(directory):
print(f"Command output: {e.stdout}")
print(f"Command error output: {e.stderr}")
return None

def extract_after_live(s):
index = s.index('live/') + len('live/')
return s[index:]

def extract_repo_name(file_path):
with open(file_path, 'r') as file:
for line in file:
if "customer_name =" in line:
customer_name = line.split('=', 1)[1].strip().strip('"')
return customer_name

def download_bucket():
s3 = boto3.client('s3')
object_key = extract_after_live(os.getcwd())
bucket_name = "terraform-remote-state-" + extract_repo_name("terragrunt.hcl")
try:
s3.download_file(bucket_name, object_key, "tmp_file.json")
return "tmp_file.json"
except Exception as e:
print(f"Error: {e}")
return None

def process_directory(directory, config):
json_content = run_terragrunt(directory)
json_content = download_bucket(directory)
if not json_content:
return None

Expand Down

0 comments on commit 36693be

Please sign in to comment.