constructor()

in src/declarative-stack.ts [18:66]


  constructor(scope: cdk.App, id: string, props: DeclarativeStackProps) {
    super(scope, id);

    const typeSystem = props.typeSystem;
    const template = props.template;

    const schema = renderFullSchema(typeSystem);

    const result = jsonschema.validate(template, schema);
    if (!result.valid) {
      throw new ValidationError('Schema validation errors:\n  ' + result.errors.map(e => `"${e.property}" ${e.message}`).join('\n  '));
    }

    // Replace every resource that starts with CDK::
    for (const [logicalId, resourceProps] of Object.entries(template.Resources || {})) {
      const rprops: any = resourceProps;
      if (!rprops.Type) {
        throw new Error('Resource is missing type: ' + JSON.stringify(resourceProps));
      }

      if (isCfnResourceType(rprops.Type)) {
        continue;
      }

      const typeInfo = typeSystem.findFqn(rprops.Type + 'Props');
      const typeRef = new reflect.TypeReference(typeSystem, typeInfo);
      const Ctor = resolveType(rprops.Type);

      // Changing working directory if needed, such that relative paths in the template are resolved relative to the
      // template's location, and not to the current process' CWD.
      _cwd(props.workingDirectory, () =>
        new Ctor(this, logicalId, deserializeValue(this, typeRef, true, 'Properties', rprops.Properties)));

      delete template.Resources[logicalId];
    }

    delete template.$schema;

    const workdir = mkdtempSync(join(tmpdir(), 'decdk-'));
    const templateFile = join(workdir, 'template.json');
    writeFileSync(templateFile, JSON.stringify(template));

    // Add an Include construct with what's left of the template
    new CfnInclude(this, 'Include', { templateFile });

    // replace all "Fn::GetAtt" with tokens that resolve correctly both for
    // constructs and raw resources.
    processReferences(this);
  }