mirror of
https://github.com/khuedoan/homelab.git
synced 2024-12-23 01:04:32 +07:00
feat(configure): quick and dirty Terraform workspace replace
This commit is contained in:
parent
81f0a94574
commit
09a044443f
29
configure.py
29
configure.py
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user