You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
1.1 KiB

#!/usr/bin/env python3
import argparse
from os import path, chdir
from subprocess import run, CalledProcessError
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("cmd")
parser.add_argument("--terraform-path", default="/usr/local/bin")
parser.add_argument("--plan-file", default="tf.plan")
args, terraform_args = parser.parse_known_args()
terraform = [
path.join(args.terraform_path, "terraform"),
args.cmd
]
if args.cmd == "init":
# terraform does not allow variables in the backend block
# but only wants to be told of it when doing 'init
tfargs = ["-backend-config=wasabi-backend.conf"]
elif args.cmd == "plan":
chdir("sudoisnet/")
run(["poetry", "run", "sudoisnet"], check=True)
chdir("..")
tfargs = ["-out", args.plan_file]
elif args.cmd == "apply":
tfargs = [args.plan_file]
else:
tfargs = []
# pass any other args to teraform
tfargs.extend(terraform_args)
try:
# can also build a convergence from this
run(terraform + tfargs)
except CalledProcessError:
raise