How to use @aws-cdk/cloudformation-diff - 10 common examples

To help you get started, we’ve selected a few @aws-cdk/cloudformation-diff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / @aws-cdk / assert / lib / assertions / match-template.ts View on Github external
public assertUsing(inspector: StackInspector): boolean {
    const diff = cfnDiff.diffTemplate(this.template, inspector.value);
    const acceptable = this.isDiffAcceptable(diff);
    if (!acceptable) {
      // Print the diff
      cfnDiff.formatDifferences(process.stderr, diff);

      // Print the actual template
      process.stdout.write('--------------------------------------------------------------------------------------\n');
      process.stdout.write(JSON.stringify(inspector.value, undefined, 2) + '\n');
    }

    return acceptable;
  }
github aws / aws-cdk / packages / aws-cdk / lib / diff.ts View on Github external
stream?: cfnDiff.FormatStream): number {

  const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);

  // filter out 'AWS::CDK::Metadata' resources from the template
  if (diff.resources && !strict) {
    diff.resources = diff.resources.filter(change => {
      if (!change) { return true; }
      if (change.newResourceType === 'AWS::CDK::Metadata') { return false; }
      if (change.oldResourceType === 'AWS::CDK::Metadata') { return false; }
      return true;
    });
  }

  if (!diff.isEmpty) {
    cfnDiff.formatDifferences(stream || process.stderr, diff, buildLogicalToPathMap(newTemplate), context);
  } else {
    print(colors.green('There were no differences'));
  }

  return diff.differenceCount;
}
github seagull-js / seagull / packages / deploy-aws / src / seagull_app.ts View on Github external
async diffStack() {
    const sdk = new cdk.SDK({})
    const synthStack = this.synthesizeStack(this.projectName)
    const cfn = await sdk.cloudFormation(synthStack.environment, 0)
    const templateData = { StackName: synthStack.name }
    const template = await cfn.getTemplate(templateData).promise()
    const body = template.TemplateBody
    const curTemplate = (body && yaml.parse(body, { schema: 'yaml-1.1' })) || {}
    const logicalToPathMap = lib.createLogicalToPathMap(synthStack)
    const diff = cfnDiff.diffTemplate(curTemplate, synthStack.template)
    // tslint:disable-next-line:no-unused-expression
    diff.isEmpty && lib.noChangesInDiff()
    cfnDiff.formatDifferences(process.stdout, diff, logicalToPathMap)
  }
}
github aws / aws-cdk / tools / cdk-integ-tools / bin / cdk-integ-assert.ts View on Github external
const expected = await test.readExpected();

    const args = new Array();
    args.push('--no-path-metadata');
    args.push('--no-asset-metadata');
    args.push('--no-staging');

    const actual = await test.invoke(['--json', ...args, 'synth'], { json: true, context: STATIC_TEST_CONTEXT });

    const diff = diffTemplate(expected, actual);

    if (!diff.isEmpty) {
      failures.push(test.name);
      process.stdout.write('CHANGED.\n');
      formatDifferences(process.stdout, diff);
    } else {
      process.stdout.write('OK.\n');
    }
  }

  if (failures.length > 0) {
    // tslint:disable-next-line:max-line-length
    throw new Error(`The following integ stacks have changed: ${failures.join(', ')}. Run 'npm run integ' to verify that everything still deploys.`);
  }
}
github aws / aws-cdk / tools / cdk-integ-tools / bin / cdk-integ-assert.ts View on Github external
process.stdout.write(`Verifying ${test.name} against ${test.expectedFileName}... `);

    if (!test.hasExpected()) {
      throw new Error(`No such file: ${test.expectedFileName}. Run 'npm run integ'.`);
    }

    const expected = await test.readExpected();

    const args = new Array();
    args.push('--no-path-metadata');
    args.push('--no-asset-metadata');
    args.push('--no-staging');

    const actual = await test.invoke(['--json', ...args, 'synth'], { json: true, context: STATIC_TEST_CONTEXT });

    const diff = diffTemplate(expected, actual);

    if (!diff.isEmpty) {
      failures.push(test.name);
      process.stdout.write('CHANGED.\n');
      formatDifferences(process.stdout, diff);
    } else {
      process.stdout.write('OK.\n');
    }
  }

  if (failures.length > 0) {
    // tslint:disable-next-line:max-line-length
    throw new Error(`The following integ stacks have changed: ${failures.join(', ')}. Run 'npm run integ' to verify that everything still deploys.`);
  }
}
github aws / aws-cdk / packages / aws-cdk / lib / diff.ts View on Github external
export function printStackDiff(
      oldTemplate: any,
      newTemplate: cxapi.CloudFormationStackArtifact,
      strict: boolean,
      context: number,
      stream?: cfnDiff.FormatStream): number {

  const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);

  // filter out 'AWS::CDK::Metadata' resources from the template
  if (diff.resources && !strict) {
    diff.resources = diff.resources.filter(change => {
      if (!change) { return true; }
      if (change.newResourceType === 'AWS::CDK::Metadata') { return false; }
      if (change.oldResourceType === 'AWS::CDK::Metadata') { return false; }
      return true;
    });
  }

  if (!diff.isEmpty) {
    cfnDiff.formatDifferences(stream || process.stderr, diff, buildLogicalToPathMap(newTemplate), context);
  } else {
    print(colors.green('There were no differences'));
  }
github aws / aws-cdk / packages / aws-cdk / lib / diff.ts View on Github external
export function printSecurityDiff(oldTemplate: any, newTemplate: cxapi.CloudFormationStackArtifact, requireApproval: RequireApproval): boolean {
  const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);

  if (difRequiresApproval(diff, requireApproval)) {
    // tslint:disable-next-line:max-line-length
    warning(`This deployment will make potentially sensitive changes according to your current security approval level (--require-approval ${requireApproval}).`);
    warning(`Please confirm you intend to make the following modifications:\n`);

    cfnDiff.formatSecurityChanges(process.stdout, diff, buildLogicalToPathMap(newTemplate));
    return true;
  }
  return false;
}
github aws / aws-cdk / packages / @aws-cdk / assert / lib / assertions / match-template.ts View on Github external
public assertUsing(inspector: StackInspector): boolean {
    const diff = cfnDiff.diffTemplate(this.template, inspector.value);
    const acceptable = this.isDiffAcceptable(diff);
    if (!acceptable) {
      // Print the diff
      cfnDiff.formatDifferences(process.stderr, diff);

      // Print the actual template
      process.stdout.write('--------------------------------------------------------------------------------------\n');
      process.stdout.write(JSON.stringify(inspector.value, undefined, 2) + '\n');
    }

    return acceptable;
  }
github seagull-js / seagull / packages / deploy-aws / src / seagull_app.ts View on Github external
async diffStack() {
    const sdk = new cdk.SDK({})
    const synthStack = this.synthesizeStack(this.projectName)
    const cfn = await sdk.cloudFormation(synthStack.environment, 0)
    const templateData = { StackName: synthStack.name }
    const template = await cfn.getTemplate(templateData).promise()
    const body = template.TemplateBody
    const curTemplate = (body && yaml.parse(body, { schema: 'yaml-1.1' })) || {}
    const logicalToPathMap = lib.createLogicalToPathMap(synthStack)
    const diff = cfnDiff.diffTemplate(curTemplate, synthStack.template)
    // tslint:disable-next-line:no-unused-expression
    diff.isEmpty && lib.noChangesInDiff()
    cfnDiff.formatDifferences(process.stdout, diff, logicalToPathMap)
  }
}
github aws / aws-cdk / packages / aws-cdk / lib / diff.ts View on Github external
export function printSecurityDiff(oldTemplate: any, newTemplate: cxapi.CloudFormationStackArtifact, requireApproval: RequireApproval): boolean {
  const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);

  if (difRequiresApproval(diff, requireApproval)) {
    // tslint:disable-next-line:max-line-length
    warning(`This deployment will make potentially sensitive changes according to your current security approval level (--require-approval ${requireApproval}).`);
    warning(`Please confirm you intend to make the following modifications:\n`);

    cfnDiff.formatSecurityChanges(process.stdout, diff, buildLogicalToPathMap(newTemplate));
    return true;
  }
  return false;
}

@aws-cdk/cloudformation-diff

Utilities to diff CDK stacks against CloudFormation templates

Apache-2.0
Latest version published 5 days ago

Package Health Score

98 / 100
Full package analysis