Ejemplo n.º 1
0
def reject(ctx, profile, config_file, environment, region, change_set_name,
           change_set_id):
    """
    Reject a CloudFormation ChangeSet, deleting the stack if in REVIEW_IN_PROGRESS status and has no other ChangeSets.
    If using --change-set-name then --config --environment and --region are required.
    If using --change-set-id no other values are required (although --profile and --region may be needed).
    """
    if not change_set_name and not change_set_id:
        raise click.UsageError(
            "Option '--change-set-name' or '--change-set-id' required.")

    try:
        if change_set_id:
            runner = create_changeset_runner(profile, region, change_set_id)
            runner.reject_change_set()
        else:
            if not config_file:
                raise click.UsageError(
                    "Missing option '-c' / '--config-file'.")
            if not environment:
                raise click.UsageError(
                    "Missing option '-e' / '--environment'.")

            cfg = load_config(config_file,
                              ctx.obj.config,
                              environment,
                              False,
                              ChangeSetName=change_set_name)
            runner = create_runner(profile, cfg)
            runner.reject_change_set()
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
        exit(1)
Ejemplo n.º 2
0
def apply(ctx, profile, config_file, environment, region, change_set_name,
          change_set_id):
    """
    Apply a CloudFormation ChangeSet to create or update a CloudFormation stack.
    If using --change-set-name then --config --environment and --region are required.
    If using --change-set-id no other values are required (although --profile and --region may be needed).
    """
    if not change_set_name and not change_set_id:
        raise click.UsageError(
            "Option '--change-set-name' or '--change-set-id' required.")

    try:
        if change_set_id:
            runner = create_changeset_runner(profile, region, change_set_id)
            runner.apply_change_set()
        else:
            if not config_file:
                raise click.UsageError(
                    "Missing option '-c' / '--config-file'.")
            if not environment:
                raise click.UsageError(
                    "Missing option '-e' / '--environment'.")

            cfg = load_config(config_file,
                              ctx.obj.config,
                              environment,
                              False,
                              ChangeSetName=change_set_name)
            runner = create_runner(profile, cfg)
            runner.apply_change_set()
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
        exit(1)
Ejemplo n.º 3
0
def delete(ctx, profile, config, environment, region, retain_resources):
    try:
        cfg = load_config(config, environment, region, None, None)
        runner = create_runner(profile, cfg, None, False)
        runner.delete(retain_resources)
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
Ejemplo n.º 4
0
def apply(ctx, profile, config, environment, region, change_set_name):
    try:
        cfg = load_config(config, environment, region, None, None)
        runner = create_runner(profile, cfg, change_set_name, False)
        runner.execute_change_set()
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
Ejemplo n.º 5
0
def deploy(ctx, profile, config, environment, region, template, parameter,
           change_set_name, auto_approve):
    try:
        cfg = load_config(config, environment, region, template, parameter)
        runner = create_runner(profile, cfg, change_set_name, auto_approve)
        runner.deploy()
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
Ejemplo n.º 6
0
def delete(ctx, profile, config_file, environment, region, retain_resources):
    """
    Delete a CloudFormation stack.
    """
    try:
        cfg = load_config(config_file, ctx.obj.config, environment, False)
        runner = create_runner(profile, cfg)
        runner.delete(retain_resources)
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
        exit(1)
Ejemplo n.º 7
0
def get_output(ctx, profile, config_file, environment, region, output_key):
    """
    Returns matching Output value if it exists.
    """
    try:
        cfg = load_config(config_file, ctx.obj.config, environment, False)
        runner = create_runner(profile, cfg)
        output_value = runner.get_output(output_key)
        echo(output_value)
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
        exit(1)
Ejemplo n.º 8
0
def status(ctx, profile, config_file, environment, region, event_days):
    """
    Print current status of Stack.
    Includes pending ChangeSets and recent events.
    """
    try:
        cfg = load_config(config_file, ctx.obj.config, environment, False)
        runner = create_runner(profile, cfg)
        runner.status(event_days)
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
        exit(1)
Ejemplo n.º 9
0
def deploy(ctx, profile, config_file, environment, region, template, parameter,
           parameter_use_previous, change_set_name, existing_changes,
           auto_apply):
    """
    Create or update a CloudFormation stack using ChangeSets.
    """
    try:
        cfg = load_config(config_file,
                          ctx.obj.config,
                          environment,
                          Template=template,
                          Parameters=parameter,
                          PreviousParameters=parameter_use_previous,
                          ChangeSetName=change_set_name,
                          ExistingChanges=existing_changes,
                          AutoApply=auto_apply)
        runner = create_runner(profile, cfg)
        runner.deploy()
    except (ValidationError, StackError) as e:
        error(f'\nError: {e}')
        exit(1)