get cfnResource()

in packages/cdk-graph/src/core/graph.ts [1967:2000]


  get cfnResource(): CfnResourceNode | undefined {
    if (this._cfnResource !== undefined) {
      if (this._cfnResource && this._cfnResource.isDestroyed) return undefined;
      return this._cfnResource || undefined;
    }

    const resourceNode = this.findChild(CdkConstructIds.RESOURCE) as
      | CfnResourceNode
      | undefined;
    if (resourceNode) {
      this._cfnResource = resourceNode;
      return resourceNode;
    }
    const defaultNode = this.findChild(CdkConstructIds.DEFAULT) as
      | CfnResourceNode
      | undefined;
    if (defaultNode) {
      this._cfnResource = defaultNode;
      return defaultNode;
    }

    if (this.isCdkOwned && this.children.length === 1) {
      const child = this.children[0];
      if (CfnResourceNode.isCfnResourceNode(child)) {
        this._cfnResource = child;
        return child;
      }
    }

    // prevent looking up again by setting to `null`
    this._cfnResource = null;

    return undefined;
  }