def deploy_gcp(args: argparse.Namespace) -> None: # Set local state path as our current working directory. This is a no-op # when the --local-state-path arg isn't used. We do this because Terraform # module directories are populated with relative paths, and we want to # support users running gcp up and down commands from different directories. # Also, because we change the working directory, we ensure that # local_state_path is an absolute path. args.local_state_path = os.path.abspath(args.local_state_path) if not os.path.exists(args.local_state_path): os.makedirs(args.local_state_path) os.chdir(args.local_state_path) # Set the TF_DATA_DIR where Terraform will store its supporting files env = os.environ.copy() env["TF_DATA_DIR"] = os.path.join(args.local_state_path, "terraform_data") # Create det_configs dictionary det_configs = {} # Add args to det_configs dict for arg in vars(args): if vars(args)[arg] is not None: det_configs[arg] = vars(args)[arg] # Not all args will be passed to Terraform, list the ones that won't be variables_to_exclude = [ "command", "dry_run", "environment", "local_state_path", ] # Delete if args.command == "down": gcp.delete(det_configs, env) print("Delete Successful") return if (args.cpu_env_image and not args.gpu_env_image) or (args.gpu_env_image and not args.cpu_env_image): print("If a CPU or GPU image is specified, both should be.") sys.exit(1) # Dry-run flag if args.dry_run: gcp.dry_run(det_configs, env, variables_to_exclude) print("Printed plan. To execute, run `det-deploy gcp`") return print("Starting Determined Deployment") gcp.deploy(det_configs, env, variables_to_exclude) print("\nDetermined Deployment Successful") print( "Please allow 1-5 minutes for the master instance to be accessible via the web-ui\n" )
def deploy_gcp(args: argparse.Namespace) -> None: # Set the TF_DATA_DIR where Terraform will store its supporting files env = os.environ.copy() env["TF_DATA_DIR"] = os.path.join(args.local_state_path, "terraform_data") # Create det_configs dictionary det_configs = {} # Add args to det_configs dict for arg in vars(args): if vars(args)[arg] is not None: det_configs[arg] = vars(args)[arg] # Not all args will be passed to Terraform, list the ones that won't be variables_to_exclude = [ "command", "dry_run", "environment", "local_state_path", ] # Delete if args.command == "down": # Set placeholders for required variables det_configs["cluster_id"] = "will-be-ignored" det_configs["project_id"] = "will-be-ignored" det_configs["network"] = "will-be-ignored" det_configs["region"] = "will-be-ignored" det_configs["det_version"] = "will-be-ignored" det_configs["environment_image"] = "will-be-ignored" gcp.delete(det_configs, env, variables_to_exclude) print("Delete Successful") return # Dry-run flag if args.dry_run: gcp.dry_run(det_configs, env, variables_to_exclude) print("Printed plan. To execute, run `det-deploy gcp`") return print("Starting Determined Deployment") gcp.deploy(det_configs, env, variables_to_exclude) print("\nDetermined Deployment Successful") print( "Please allow 1-5 minutes for the master instance to be accessible via the web-ui\n" )