@gradientedge/cdk-utils-azure 2.29.1 → 2.31.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.
@@ -42,7 +42,7 @@ export class AzureAppServiceManager {
42
42
  tier: 'FlexConsumption',
43
43
  },
44
44
  reserved: props.reserved ?? true,
45
- zoneRedundant: props.zoneRedundant ?? false,
45
+ zoneRedundant: props.zoneRedundant ?? true,
46
46
  tags: {
47
47
  environment: scope.props.stage,
48
48
  ...scope.props.defaultTags,
@@ -1,2 +1,3 @@
1
1
  export * from './main.js';
2
+ export * from './renderer.js';
2
3
  export * from './types.js';
@@ -1,2 +1,3 @@
1
1
  export * from './main.js';
2
+ export * from './renderer.js';
2
3
  export * from './types.js';
@@ -1,6 +1,7 @@
1
1
  import { ResourceOptions } from '@pulumi/pulumi';
2
2
  import { CommonAzureConstruct } from '../../common/index.js';
3
- import { ApplicationInsightsProps, ComponentCurrentBillingFeatureProps } from './types.js';
3
+ import { AzureWorkbookRenderer } from './renderer.js';
4
+ import { ApplicationInsightsProps, ComponentCurrentBillingFeatureProps, WorkbookProps } from './types.js';
4
5
  /**
5
6
  * Provides operations on Azure Application Insights using Pulumi
6
7
  * - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
@@ -38,4 +39,13 @@ export declare class AzureApplicationInsightsManager {
38
39
  * @see [Pulumi Azure Native Application Insights Billing Feature]{@link https://www.pulumi.com/registry/packages/azure-native/api-docs/insights/componentcurrentbillingfeature/}
39
40
  */
40
41
  createComponentCurrentBillingFeature(id: string, scope: CommonAzureConstruct, props: ComponentCurrentBillingFeatureProps, resourceOptions?: ResourceOptions): import("@pulumi/azure-native/applicationinsights/componentCurrentBillingFeature.js").ComponentCurrentBillingFeature;
42
+ /**
43
+ * @summary Method to create a new application insights workbook
44
+ * @param id scoped id of the resource
45
+ * @param scope scope in which this resource is defined
46
+ * @param props application insights workbook properties
47
+ * @param resourceOptions Optional settings to control resource behaviour
48
+ * @see [Pulumi Azure Native Application Insights Billing Feature]{@link https://www.pulumi.com/registry/packages/azure-native/api-docs/applicationinsights/workbook/}
49
+ */
50
+ createWorkbook(id: string, scope: CommonAzureConstruct, props: WorkbookProps, renderer?: AzureWorkbookRenderer, resourceOptions?: ResourceOptions): import("@pulumi/azure-native/applicationinsights/workbook.js").Workbook;
41
51
  }
@@ -1,4 +1,7 @@
1
- import { ApplicationType, Component, ComponentCurrentBillingFeature, } from '@pulumi/azure-native/applicationinsights/index.js';
1
+ import fs from 'fs';
2
+ import { ApplicationType, Component, ComponentCurrentBillingFeature, Workbook, WorkbookSharedTypeKind, } from '@pulumi/azure-native/applicationinsights/index.js';
3
+ import * as pulumi from '@pulumi/pulumi';
4
+ import { AzureWorkbookRenderer } from './renderer.js';
2
5
  /**
3
6
  * Provides operations on Azure Application Insights using Pulumi
4
7
  * - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
@@ -72,4 +75,37 @@ export class AzureApplicationInsightsManager {
72
75
  throw new Error(`Props undefined for ${id}`);
73
76
  return new ComponentCurrentBillingFeature(`${id}`, props, { parent: scope, ...resourceOptions });
74
77
  }
78
+ /**
79
+ * @summary Method to create a new application insights workbook
80
+ * @param id scoped id of the resource
81
+ * @param scope scope in which this resource is defined
82
+ * @param props application insights workbook properties
83
+ * @param resourceOptions Optional settings to control resource behaviour
84
+ * @see [Pulumi Azure Native Application Insights Billing Feature]{@link https://www.pulumi.com/registry/packages/azure-native/api-docs/applicationinsights/workbook/}
85
+ */
86
+ createWorkbook(id, scope, props, renderer, resourceOptions) {
87
+ if (!props)
88
+ throw new Error(`Props undefined for ${id}`);
89
+ const resourceGroup = scope.resourceGroup ??
90
+ scope.resourceGroupManager.resolveResourceGroup(scope, props.resourceGroupName.toString() ?? scope.props.resourceGroupName, resourceOptions);
91
+ const workbookRenderer = renderer ?? new AzureWorkbookRenderer();
92
+ const templateFile = workbookRenderer.renderToFile(props.slug, props.templateId, props.variables);
93
+ const template = fs.readFileSync(templateFile, 'utf-8');
94
+ const keys = Object.keys(props.variables);
95
+ const values = Object.values(props.variables);
96
+ const properties = pulumi.all(values).apply(resolved => {
97
+ const content = keys.reduce((result, key, i) => result.replaceAll(`\${${key}}`, JSON.stringify(String(resolved[i])).slice(1, -1)), template);
98
+ return JSON.parse(content);
99
+ });
100
+ return new Workbook(`${id}`, {
101
+ ...props,
102
+ displayName: `${props.location} - ${props.displayName}`,
103
+ resourceGroupName: resourceGroup.name,
104
+ location: props.location ?? resourceGroup.location,
105
+ kind: props.kind ?? WorkbookSharedTypeKind.Shared,
106
+ serializedData: properties.apply(p => JSON.stringify(p)),
107
+ sourceId: props.sourceId?.toString().toLowerCase(),
108
+ category: props.category ?? 'workbook',
109
+ }, { parent: scope, ...resourceOptions, ignoreChanges: ['location'] });
110
+ }
75
111
  }
@@ -0,0 +1,7 @@
1
+ import { WorkbookRenderer } from './types.js';
2
+ export declare class AzureWorkbookRenderer implements WorkbookRenderer {
3
+ readonly templatePath: string;
4
+ readonly outputDir: string;
5
+ constructor(basePath?: string, outputDir?: string);
6
+ renderToFile(filename: string, templateId: string, variables: Record<string, string>): string;
7
+ }
@@ -0,0 +1,25 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import appRoot from 'app-root-path';
4
+ import { parse } from 'yaml';
5
+ import _ from 'lodash';
6
+ export class AzureWorkbookRenderer {
7
+ templatePath;
8
+ outputDir;
9
+ constructor(basePath, outputDir) {
10
+ this.templatePath = basePath ?? path.join(appRoot.path, 'template', 'workbook');
11
+ this.outputDir = outputDir ?? path.join(appRoot.path, '.artifacts');
12
+ }
13
+ renderToFile(filename, templateId, variables) {
14
+ const templateFilePath = `${this.templatePath}/${templateId}.yaml`;
15
+ const templateContent = fs.readFileSync(templateFilePath, 'utf-8');
16
+ const parsed = parse(templateContent);
17
+ _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
18
+ const compiled = _.template(parsed.template);
19
+ const rendered = compiled(variables);
20
+ const outputPath = path.join(this.outputDir, `${filename}-workbook.json`);
21
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
22
+ fs.writeFileSync(outputPath, rendered, 'utf-8');
23
+ return outputPath;
24
+ }
25
+ }
@@ -1,8 +1,18 @@
1
- import { ComponentArgs, ComponentCurrentBillingFeatureArgs } from '@pulumi/azure-native/applicationinsights/index.js';
1
+ import { ComponentArgs, ComponentCurrentBillingFeatureArgs, WorkbookArgs } from '@pulumi/azure-native/applicationinsights/index.js';
2
2
  /** @category Interface */
3
3
  export interface ComponentCurrentBillingFeatureProps extends ComponentCurrentBillingFeatureArgs {
4
4
  }
5
5
  /** @category Interface */
6
+ export interface WorkbookProps extends WorkbookArgs {
7
+ slug: string;
8
+ templateId: string;
9
+ variables: Record<string, any>;
10
+ }
11
+ /** @category Interface */
6
12
  export interface ApplicationInsightsProps extends ComponentArgs {
7
13
  billingFeatures?: ComponentCurrentBillingFeatureProps;
8
14
  }
15
+ /** @category Interface */
16
+ export interface WorkbookRenderer {
17
+ renderToFile(filename: string, templateId: string, variables: Record<string, any>): string;
18
+ }
@@ -55,16 +55,13 @@ export class AzureStorageManager {
55
55
  new BlobServiceProperties(`${id}-blob-props`, {
56
56
  ...props.blobProperties,
57
57
  blobServicesName: 'default',
58
- accountName: scope.resourceNameFormatter
59
- .format(props.accountName?.toString(), scope.props.resourceNameOptions?.storageAccount)
60
- .replace(/\W/g, '')
61
- .toLowerCase(),
58
+ accountName: storageAccount.name,
62
59
  resourceGroupName,
63
60
  deleteRetentionPolicy: props.blobProperties?.deleteRetentionPolicy ?? {
64
61
  enabled: true,
65
62
  days: 7,
66
63
  },
67
- }, { parent: scope, ...resourceOptions });
64
+ }, { parent: scope, dependsOn: [storageAccount], ...resourceOptions });
68
65
  }
69
66
  return storageAccount;
70
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils-azure",
3
- "version": "2.29.1",
3
+ "version": "2.31.0",
4
4
  "description": "Azure Pulumi utilities for @gradientedge/cdk-utils",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -14,15 +14,15 @@
14
14
  "dist/src/"
15
15
  ],
16
16
  "dependencies": {
17
- "@pulumi/archive": "0.3.7",
17
+ "@pulumi/archive": "0.3.8",
18
18
  "@pulumi/azure-native": "3.17.0",
19
19
  "@pulumi/azuread": "6.9.0",
20
- "@pulumi/pulumi": "3.234.0",
20
+ "@pulumi/pulumi": "3.236.0",
21
21
  "@types/lodash": "4.17.24",
22
22
  "app-root-path": "3.1.0",
23
23
  "lodash": "4.18.1",
24
24
  "uuid": "14.0.0",
25
- "yaml": "2.8.3",
25
+ "yaml": "2.8.4",
26
26
  "@gradientedge/cdk-utils-common": "2.2.1"
27
27
  },
28
28
  "keywords": [