@gradientedge/cdk-utils 9.43.3 → 9.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,3 +2,7 @@ export declare enum AzureRemoteBackend {
2
2
  local = "local",
3
3
  azurerm = "azurerm"
4
4
  }
5
+ /**
6
+ * List of Azure resources that excludes tags
7
+ */
8
+ export declare const RESOURCES_TO_EXCLUDE_TAGS: Set<string>;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AzureRemoteBackend = void 0;
3
+ exports.RESOURCES_TO_EXCLUDE_TAGS = exports.AzureRemoteBackend = void 0;
4
4
  var AzureRemoteBackend;
5
5
  (function (AzureRemoteBackend) {
6
6
  AzureRemoteBackend["local"] = "local";
7
7
  AzureRemoteBackend["azurerm"] = "azurerm";
8
8
  })(AzureRemoteBackend || (exports.AzureRemoteBackend = AzureRemoteBackend = {}));
9
+ /**
10
+ * List of Azure resources that excludes tags
11
+ */
12
+ exports.RESOURCES_TO_EXCLUDE_TAGS = new Set(['ApiManagementNamedValue']);
@@ -2,4 +2,5 @@ export * from './constants';
2
2
  export * from './construct';
3
3
  export * from './resource-name-formatter';
4
4
  export * from './stack';
5
+ export * from './tagging';
5
6
  export * from './types';
@@ -18,4 +18,5 @@ __exportStar(require("./constants"), exports);
18
18
  __exportStar(require("./construct"), exports);
19
19
  __exportStar(require("./resource-name-formatter"), exports);
20
20
  __exportStar(require("./stack"), exports);
21
+ __exportStar(require("./tagging"), exports);
21
22
  __exportStar(require("./types"), exports);
@@ -26,7 +26,9 @@ class AzureResourceNameFormatter extends constructs_1.Construct {
26
26
  azureResourceNameElements.push(options?.globalSuffix ? this.props.globalSuffix : undefined);
27
27
  }
28
28
  azureResourceNameElements.push(this.props.stage);
29
- return azureResourceNameElements.filter(Boolean).join('-');
29
+ return azureResourceNameElements
30
+ .filter(azureResourceNameElements => azureResourceNameElements != undefined)
31
+ .join('-');
30
32
  }
31
33
  }
32
34
  exports.AzureResourceNameFormatter = AzureResourceNameFormatter;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.CommonAzureStack = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
+ const tagging_1 = require("./tagging");
8
9
  const app_root_path_1 = __importDefault(require("app-root-path"));
9
10
  const cdktf_1 = require("cdktf");
10
11
  const lodash_1 = __importDefault(require("lodash"));
@@ -32,6 +33,7 @@ class CommonAzureStack extends cdktf_1.TerraformStack {
32
33
  /* determine extra cdk stage contexts */
33
34
  this.determineStageContexts();
34
35
  this.props = this.determineConstructProps(props);
36
+ cdktf_1.Aspects.of(this).add(new tagging_1.TagsAddingAspect(this.props.defaultTags || {}));
35
37
  }
36
38
  /**
37
39
  * @summary Method to determine the core CDK construct properties injected via context cdktf.json
@@ -0,0 +1,7 @@
1
+ import { IAspect } from 'cdktf';
2
+ import { IConstruct } from 'constructs';
3
+ export declare class TagsAddingAspect implements IAspect {
4
+ private tagsToAdd;
5
+ constructor(tagsToAdd: Record<string, string>);
6
+ visit(node: IConstruct): void;
7
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TagsAddingAspect = void 0;
4
+ const constants_1 = require("./constants");
5
+ function isTaggableConstruct(node) {
6
+ return 'tags' in node && 'tagsInput' in node;
7
+ }
8
+ class TagsAddingAspect {
9
+ tagsToAdd;
10
+ constructor(tagsToAdd) {
11
+ this.tagsToAdd = tagsToAdd;
12
+ }
13
+ // This method is called on every Construct within the specified scope (resources, data sources, etc.).
14
+ visit(node) {
15
+ // We need to take the input value to not create a circular reference
16
+ if (!isTaggableConstruct(node)) {
17
+ return;
18
+ }
19
+ // Determine if the resource excludes `tags`
20
+ if (constants_1.RESOURCES_TO_EXCLUDE_TAGS.has(node.constructor.name)) {
21
+ node.tags = undefined; // Completely remove tags for this resource
22
+ return;
23
+ }
24
+ const currentTags = node.tagsInput || {};
25
+ node.tags = { ...this.tagsToAdd, ...currentTags };
26
+ }
27
+ }
28
+ exports.TagsAddingAspect = TagsAddingAspect;
@@ -15,6 +15,9 @@ export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig
15
15
  [key: string]: AzureResourceNameFormatterProps;
16
16
  };
17
17
  location?: string;
18
+ defaultTags?: {
19
+ [key: string]: string;
20
+ };
18
21
  }
19
22
  export interface AzureRemoteBackendProps extends AzurermBackendConfig {
20
23
  type: AzureRemoteBackend;
@@ -49,6 +49,10 @@ class AzureCosmosDbManager {
49
49
  tags: props.tags ?? {
50
50
  environment: scope.props.stage,
51
51
  },
52
+ defaultIdentityType: props.defaultIdentityType || 'SystemAssignedIdentity',
53
+ identity: props.identity || {
54
+ type: 'SystemAssigned',
55
+ },
52
56
  });
53
57
  (0, utils_1.createAzureTfOutput)(`${id}-cosmosdbAccountName`, scope, cosmosdbAccount.name);
54
58
  (0, utils_1.createAzureTfOutput)(`${id}-cosmosdbAccountFriendlyUniqueId`, scope, cosmosdbAccount.friendlyUniqueId);
@@ -44,7 +44,9 @@ class AzureKeyVaultManager {
44
44
  name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.keyVault),
45
45
  location: resourceGroup.location,
46
46
  resourceGroupName: resourceGroup.name,
47
- skuName: props.skuName ?? 'standard',
47
+ skuName: props.skuName || 'standard',
48
+ enableRbacAuthorization: props.enableRbacAuthorization || true,
49
+ softDeleteRetentionDays: props.softDeleteRetentionDays || 90,
48
50
  tags: props.tags ?? {
49
51
  environment: scope.props.stage,
50
52
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "9.43.3",
3
+ "version": "9.44.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -2,3 +2,8 @@ export enum AzureRemoteBackend {
2
2
  local = 'local',
3
3
  azurerm = 'azurerm',
4
4
  }
5
+
6
+ /**
7
+ * List of Azure resources that excludes tags
8
+ */
9
+ export const RESOURCES_TO_EXCLUDE_TAGS = new Set(['ApiManagementNamedValue'])
@@ -2,4 +2,5 @@ export * from './constants'
2
2
  export * from './construct'
3
3
  export * from './resource-name-formatter'
4
4
  export * from './stack'
5
+ export * from './tagging'
5
6
  export * from './types'
@@ -33,6 +33,8 @@ export class AzureResourceNameFormatter extends Construct {
33
33
 
34
34
  azureResourceNameElements.push(this.props.stage)
35
35
 
36
- return azureResourceNameElements.filter(Boolean).join('-')
36
+ return azureResourceNameElements
37
+ .filter(azureResourceNameElements => azureResourceNameElements != undefined)
38
+ .join('-')
37
39
  }
38
40
  }
@@ -1,9 +1,9 @@
1
1
  import fs from 'fs'
2
2
  import { CommonAzureConstruct } from './construct'
3
3
  import { CommonAzureStackProps } from './types'
4
-
4
+ import { TagsAddingAspect } from './tagging'
5
5
  import appRoot from 'app-root-path'
6
- import { TerraformStack } from 'cdktf'
6
+ import { Aspects, TerraformStack } from 'cdktf'
7
7
  import { Construct } from 'constructs'
8
8
  import _ from 'lodash'
9
9
  import { isDevStage } from '../../common'
@@ -35,6 +35,8 @@ export class CommonAzureStack extends TerraformStack {
35
35
  this.determineStageContexts()
36
36
 
37
37
  this.props = this.determineConstructProps(props)
38
+
39
+ Aspects.of(this).add(new TagsAddingAspect(this.props.defaultTags || {}))
38
40
  }
39
41
 
40
42
  /**
@@ -0,0 +1,33 @@
1
+ import { IAspect } from 'cdktf'
2
+ import { IConstruct } from 'constructs'
3
+ import { RESOURCES_TO_EXCLUDE_TAGS } from './constants'
4
+
5
+ type TaggableConstruct = IConstruct & {
6
+ tags?: { [key: string]: string } | string[]
7
+ tagsInput?: { [key: string]: string } | string[]
8
+ }
9
+
10
+ function isTaggableConstruct(node: IConstruct): node is TaggableConstruct {
11
+ return 'tags' in node && 'tagsInput' in node
12
+ }
13
+
14
+ export class TagsAddingAspect implements IAspect {
15
+ constructor(private tagsToAdd: Record<string, string>) {}
16
+
17
+ // This method is called on every Construct within the specified scope (resources, data sources, etc.).
18
+ visit(node: IConstruct) {
19
+ // We need to take the input value to not create a circular reference
20
+ if (!isTaggableConstruct(node)) {
21
+ return
22
+ }
23
+
24
+ // Determine if the resource excludes `tags`
25
+ if (RESOURCES_TO_EXCLUDE_TAGS.has(node.constructor.name)) {
26
+ node.tags = undefined // Completely remove tags for this resource
27
+ return
28
+ }
29
+
30
+ const currentTags = node.tagsInput || {}
31
+ node.tags = { ...this.tagsToAdd, ...currentTags }
32
+ }
33
+ }
@@ -14,6 +14,7 @@ export interface CommonAzureStackProps extends BaseProps, AzurermProviderConfig
14
14
  resourceSuffix?: string
15
15
  resourceNameOptions?: { [key: string]: AzureResourceNameFormatterProps }
16
16
  location?: string
17
+ defaultTags?: { [key: string]: string }
17
18
  }
18
19
 
19
20
  export interface AzureRemoteBackendProps extends AzurermBackendConfig {
@@ -50,6 +50,10 @@ export class AzureCosmosDbManager {
50
50
  tags: props.tags ?? {
51
51
  environment: scope.props.stage,
52
52
  },
53
+ defaultIdentityType: props.defaultIdentityType || 'SystemAssignedIdentity',
54
+ identity: props.identity || {
55
+ type: 'SystemAssigned',
56
+ },
53
57
  })
54
58
 
55
59
  createAzureTfOutput(`${id}-cosmosdbAccountName`, scope, cosmosdbAccount.name)
@@ -45,7 +45,9 @@ export class AzureKeyVaultManager {
45
45
  name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.keyVault),
46
46
  location: resourceGroup.location,
47
47
  resourceGroupName: resourceGroup.name,
48
- skuName: props.skuName ?? 'standard',
48
+ skuName: props.skuName || 'standard',
49
+ enableRbacAuthorization: props.enableRbacAuthorization || true,
50
+ softDeleteRetentionDays: props.softDeleteRetentionDays || 90,
49
51
  tags: props.tags ?? {
50
52
  environment: scope.props.stage,
51
53
  },