-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Hannafious
committed
Feb 16, 2018
1 parent
f8f02b6
commit 47d1e5d
Showing
18 changed files
with
833 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import click | ||
import subprocess | ||
import dss_terraform | ||
|
||
|
||
pkg_root = os.path.abspath(os.path.dirname(__file__)) # noqa | ||
|
||
|
||
def run(*args): | ||
out = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') | ||
try: | ||
out.check_returncode() | ||
except subprocess.CalledProcessError: | ||
print(f'\t{out.stderr}') | ||
return out.stdout.strip() | ||
|
||
|
||
def verify_gcp_account(): | ||
print("GCP Account:") | ||
print(run('gcloud', 'auth', 'list')) | ||
print(run('gcloud', 'config', 'configurations', 'list')) | ||
|
||
if not click.confirm('Continue?'): | ||
sys.exit(1) | ||
|
||
|
||
def verify_aws_account(): | ||
print("AWS Account:") | ||
print(run('aws', 'configure', 'list')) | ||
|
||
if not click.confirm('Continue?'): | ||
sys.exit(1) | ||
|
||
|
||
@click.command() | ||
@click.option('--stage', prompt=True) | ||
@click.option('--accept-defaults', is_flag=True, default=False) | ||
def main(stage, accept_defaults): | ||
if not accept_defaults: | ||
verify_aws_account() | ||
verify_gcp_account() | ||
print('Current stages:', ', '.join(dss_terraform.current_stages())) | ||
|
||
tf_tree = dss_terraform.TFTree(stage) | ||
|
||
if not tf_tree.vars.get('GCP_PROJECT', None): | ||
tf_tree.vars['GCP_PROJECT'] = run('gcloud', 'config', 'get-value', 'project') | ||
|
||
tf_tree.get_user_input(accept_defaults=accept_defaults) | ||
tf_tree.write() | ||
dss_terraform.set_active_stage(stage) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
STAGE=active | ||
COMPONENT= | ||
|
||
init: | ||
cd $(STAGE)/$(COMPONENT); terraform init | ||
|
||
plan: init | ||
cd $(STAGE)/$(COMPONENT); terraform plan | ||
|
||
apply: init | ||
cd $(STAGE)/$(COMPONENT); terraform apply | ||
|
||
destroy: init | ||
cd $(STAGE)/$(COMPONENT); terraform destroy | ||
|
||
clean: | ||
cd $(STAGE)/$(COMPONENT); -rm -rf .terraform | ||
|
||
.PHONY: init plan apply clean |
Oops, something went wrong.