constructor()

in packages/aws-cdk-lib/cloudformation-include/lib/cfn-include.ts [125:199]


  constructor(scope: Construct, id: string, props: CfnIncludeProps) {
    super(scope, id);

    this.allowCyclicalReferences = props.allowCyclicalReferences ?? false;

    this.logicalIdToPlaceholderMap = new Map<string, string>();

    this.parametersToReplace = props.parameters || {};

    // read the template into a JS object
    this.template = futils.readYamlSync(props.templateFile);

    this.preserveLogicalIds = props.preserveLogicalIds ?? true;

    this.dehydratedResources = props.dehydratedResources ?? [];

    for (const logicalId of this.dehydratedResources) {
      if (!Object.keys(this.template.Resources).includes(logicalId)) {
        throw new core.ValidationError(`Logical ID '${logicalId}' was specified in 'dehydratedResources', but does not belong to a resource in the template.`, this);
      }
    }

    // check if all user specified parameter values exist in the template
    for (const logicalId of Object.keys(this.parametersToReplace)) {
      if (!(logicalId in (this.template.Parameters || {}))) {
        throw new core.ValidationError(`Parameter with logical ID '${logicalId}' was not found in the template`, this);
      }
    }

    // instantiate the Mappings
    this.mappingsScope = new Construct(this, '$Mappings');
    for (const mappingName of Object.keys(this.template.Mappings || {})) {
      this.createMapping(mappingName);
    }

    // instantiate all parameters
    for (const logicalId of Object.keys(this.template.Parameters || {})) {
      this.createParameter(logicalId);
    }

    // instantiate the conditions
    this.conditionsScope = new Construct(this, '$Conditions');
    for (const conditionName of Object.keys(this.template.Conditions || {})) {
      this.getOrCreateCondition(conditionName);
    }

    // instantiate the rules
    this.rulesScope = new Construct(this, '$Rules');
    for (const ruleName of Object.keys(this.template.Rules || {})) {
      this.createRule(ruleName);
    }

    this.nestedStacksToInclude = props.loadNestedStacks || {};
    // instantiate all resources as CDK L1 objects
    for (const logicalId of Object.keys(this.template.Resources || {})) {
      this.getOrCreateResource(logicalId);
    }
    // verify that all nestedStacks have been instantiated
    for (const nestedStackId of Object.keys(props.loadNestedStacks || {})) {
      if (!(nestedStackId in this.resources)) {
        throw new core.ValidationError(`Nested Stack with logical ID '${nestedStackId}' was not found in the template`, this);
      }
    }

    // instantiate the Hooks
    this.hooksScope = new Construct(this, '$Hooks');
    for (const hookName of Object.keys(this.template.Hooks || {})) {
      this.createHook(hookName);
    }

    const outputScope = new Construct(this, '$Outputs');
    for (const logicalId of Object.keys(this.template.Outputs || {})) {
      this.createOutput(logicalId, outputScope);
    }
  }