feat(configure): quick and dirty Terraform workspace replace

This commit is contained in:
Khue Doan 2022-02-01 00:57:23 +07:00
parent 81f0a94574
commit 09a044443f

View File

@ -1,7 +1,7 @@
#!/usr/bin/python
# WIP
# clean this up
# TODO clean this up
"""
Basic configure script for new users
@ -14,13 +14,11 @@ import sys
editor = os.getenv('EDITOR')
seed_repo = "github.com/khuedoan/homelab"
domain = "khuedoan.com"
terraform_workspace = "khuedoan"
if sys.version_info < (3, 10, 0):
raise Exception("Must be using Python >= 3.10.0")
if platform.system() != 'Linux':
raise Exception("Only Linux is supported, please us a Linux VM or switch operating system")
# confirm text editor
editor = str(input(f"Text editor ({editor}): ") or editor)
@ -32,10 +30,29 @@ os.system(f"./scripts/replace-gitops-repo {seed_repo}")
domain = str(input(f"Enter your domain ({domain}): ") or domain)
os.system(f"./scripts/replace-domain {domain}")
# change hardware info
# Change hardware info
os.system(f"{editor} 'metal/inventories/prod.yml'") # TODO use var for inventory
# TODO change Terraform workspace
def replace_terraform_workspace(current, new):
filename = 'external/versions.tf'
# Read in the file
with open(filename, 'r') as file:
filedata = file.read()
# Replace the target string
filedata = filedata.replace(current, new)
# Write the file out again
with open(filename, 'w') as file:
file.write(filedata)
new_terraform_workspace = str(
input(f"Enter your Terraform Workspace ({terraform_workspace}): ")
or terraform_workspace
)
replace_terraform_workspace(terraform_workspace, new_terraform_workspace)
# TODO switch to git lib
os.system("git diff")