Validating tags added to AWS resources with CDKTF before deployment

Hi, I’m exploring the use of CDK for Terraform in TypeScript to deploy resources to AWS.

I have followed this docs page on Aspect to:

  • Add tags to all taggable AWS resources
  • Validate the name of S3 buckets

I’m trying to use the visitor pattern used in these examples to validate that the required tags have been added to taggable resources before deploying the stack. Here is what I have:

import { IAspect } from 'cdktf';
import { IConstruct } from 'constructs';
import { isTaggableConstruct } from '../tag/util';
import { logger } from '../logger';

export class CostCenterTagValidationAspect implements IAspect {
  // This method is called on every Construct within the defined scope (resource, data sources,
  // etc.).
  visit(node: IConstruct) {
    if (isTaggableConstruct(node)) {
      // About node.tags and node.inputTags
      // github.com/hashicorp/terraform-cdk/issues/1892#issuecomment-1188770124
      // node.tagsInput is undefined here
      logger.info(`${node.tagsInput}`);
      // if (node.tagsInput) {
      //   console.log('CostCenter' in node.tagsInput);
      // }
      // if (!(node.tagsInput && 'CostCenter' in node.tagsInput)) {
      //   Annotations.of(node).addError(
      //     `Each taggable resources needs to specify the tag ${TagKey.COST_CENTER}`
      //   );
      // }
    }
  }
}

Source

The issue I encounter is that I can’t get access to the tags (key and value) that I have added to the resources when running cdktf synth because node.tags returns tokens (e.g. TfToken[TOKEN.0]) that are not available during synth time.

From this comment, I attempted to work around this issue with node.tagsInput, but the value returned is undefined (the source code says that the value is temporarily available).

Is there a way to access the key and value of the tags that I have added to AWS constructs during synthesis? Alternatively, how could I validate the tags with CDKTF before deploying the stack?

Thanks!