Created
September 16, 2020 21:40
-
-
Save sjbodzo/c442abb1efdce3fa26ccfa42970c4fc9 to your computer and use it in GitHub Desktop.
Sample snippet to delete/re-add a module
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
import pyterprise | |
import argparse | |
import pathlib | |
parser = argparse.ArgumentParser(description='Parse Arguments') | |
parser.add_argument('-n', '--hostname', | |
required=True, | |
type=str, | |
action='store', | |
help="FQDN for the TFE cluster") | |
parser.add_argument('-t', '--token', | |
required=True, | |
type=str, | |
action='store', | |
help="Token to authenticate to the TFE cluster") | |
parser.add_argument('-o', '--organization', | |
required=True, | |
type=str, | |
action='store', | |
help="TFE organization name") | |
parser.add_argument('-m', '--module_name', | |
required=False, | |
default=None, | |
type=str, | |
action='store', | |
help="TFE module name") | |
parser.add_argument('-A', '--all_modules', | |
required=False, | |
action='store_true', | |
default=False, | |
help="specify all modules in TFE as the target") | |
parser.add_argument('-k', '--insecure', | |
action='store_true', | |
default=False, | |
required=False, | |
help="Toggle off certificate checking; Secure by default") | |
parser.add_argument('-c', '--certpath', | |
type=str, | |
action='store', | |
required=False, | |
default=f'{pathlib.Path(__file__).parent.absolute()}/certs/cert.pem', | |
help="TFE Certificate Bundle local filepath") | |
args = parser.parse_args() | |
client = pyterprise.Client() | |
client.init(token=args.token, url=args.hostname, cert=False if args.insecure else args.certpath) | |
org = client.set_organization(id=args.organization) | |
if args.module_name is None and not args.all_modules: | |
raise ValueError('Must specify a specific module by name [-m] or all modules [-A] as the target') | |
modules = org.list_modules() | |
m = modules if args.all_modules else [m for m in modules if m.name == args.module_name] | |
for module in m: | |
print(f'Deleting module {module.name}') | |
org.delete_module(module_name=module.name, provider=module.provider) | |
print(f'Re-adding module {module.name}') | |
org.create_module(module=module.name, provider=module.provider) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment