def remove_host(ctx, env='Default'): '''Remove a single host from the selected Rancher environment''' current_total_hosts = terraform.count_resource(ctx, 'host') new_total_hosts = current_total_hosts - 1 hosts_in_env = terraform.get_hosts_by_environment(ctx, env) number_of_hosts_in_env = len(hosts_in_env) if number_of_hosts_in_env == 0: print() print('There are no hosts in environment: {0}'.format(env)) print() return 1 if new_total_hosts == 0: # This is a special case since terraform removes the host index when # there is only a single host instance target = ['aws_instance.host'] terraform.destroy(ctx, target) else: # Grab the name of the last host in the list target_host = hosts_in_env.pop() # The part after the . is the host index target_host_index = target_host.rsplit('.', 1)[-1] # Target only that host target = ['aws_instance.host[{0}]'.format(target_host_index)] terraform.destroy(ctx, target)
def destroy(ctx): '''Completely destroy all previously created cluster resources''' terraform.destroy(ctx)