Пример #1
0
def drift_detect(ctx: Context, path: str):
    """
    Detect stack drift and return stack drift status.

    In the event that the stack does not exist, we return
    a DetectionStatus and StackDriftStatus of STACK_DOES_NOT_EXIST.

    In the event that drift detection times out, we return
    a DetectionStatus and StackDriftStatus of TIMED_OUT.

    The timeout is set at 5 minutes, a value that cannot be configured.
    """
    context = SceptreContext(
        command_path=path,
        project_path=ctx.obj.get("project_path"),
        user_variables=ctx.obj.get("user_variables"),
        options=ctx.obj.get("options"),
        output_format=ctx.obj.get("output_format"),
        ignore_dependencies=ctx.obj.get("ignore_dependencies"))

    plan = SceptrePlan(context)
    responses = plan.drift_detect()

    output_format = "json" if context.output_format == "json" else "yaml"

    exit_status = 0
    for stack, response in responses.items():
        status = response["DetectionStatus"]
        if status in BAD_STATUSES:
            exit_status += 1
        for key in ["Timestamp", "ResponseMetadata"]:
            response.pop(key, None)
        write({stack.external_name: deserialize_json_properties(response)},
              output_format)

    exit(exit_status)
Пример #2
0
def step_impl(context, stack_group_name):
    sceptre_context = SceptreContext(command_path=stack_group_name,
                                     project_path=context.sceptre_dir)
    sceptre_plan = SceptrePlan(sceptre_context)
    values = sceptre_plan.drift_detect().values()
    context.output = list(values)