@gradientedge/cdk-utils-azure 2.35.0 → 2.36.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.
@@ -46,12 +46,26 @@ export declare class CommonAzureStack extends ComponentResource {
46
46
  * - Primary use is to have layered config in separate files to enable easier maintenance and readability
47
47
  */
48
48
  protected determineExtraContexts(): Record<string, any>;
49
+ /**
50
+ * @summary Method to determine region contexts apart from the main context
51
+ * - Location is resolved from `location` Pulumi config
52
+ * - Loads `{regionContextPath}/{location}.json` if present
53
+ * - Primary use is to have layered config for each region in separate files
54
+ */
55
+ protected determineRegionContexts(): any;
49
56
  /**
50
57
  * @summary Method to determine extra stage contexts apart from the main context
51
58
  * - Sets the properties from the extra stage contexts
52
59
  * - Primary use is to have layered config for each environment which is injected into the context
53
60
  */
54
61
  protected determineStageContexts(): any;
62
+ /**
63
+ * @summary Method to determine stage-region contexts for environment and region-specific overrides
64
+ * - Loads `{stageRegionContextPath}/{stage}.{location}.json` if present
65
+ * - Has the highest priority in the configuration hierarchy
66
+ * - Primary use is to override config for a specific stage+region combination (e.g., prd.uksouth.json)
67
+ */
68
+ protected determineStageRegionContexts(): any;
55
69
  /**
56
70
  * @summary Create the construct instance for this stack
57
71
  * - Override in subclasses to provision infrastructure resources
@@ -58,10 +58,14 @@ export class CommonAzureStack extends ComponentResource {
58
58
  return {
59
59
  ...props,
60
60
  extraContexts: this.config.getObject('extraContexts'),
61
+ regionContextPath: this.config.get('regionContextPath'),
61
62
  stage: this.config.get('stage'),
62
63
  stageContextPath: this.config.get('stageContextPath'),
64
+ stageRegionContextPath: this.config.get('stageRegionContextPath'),
63
65
  ...this.determineExtraContexts(),
66
+ ...this.determineRegionContexts(),
64
67
  ...this.determineStageContexts(),
68
+ ...this.determineStageRegionContexts(),
65
69
  };
66
70
  }
67
71
  /**
@@ -95,6 +99,37 @@ export class CommonAzureStack extends ComponentResource {
95
99
  });
96
100
  return extraContextProps;
97
101
  }
102
+ /**
103
+ * @summary Method to determine region contexts apart from the main context
104
+ * - Location is resolved from `location` Pulumi config
105
+ * - Loads `{regionContextPath}/{location}.json` if present
106
+ * - Primary use is to have layered config for each region in separate files
107
+ */
108
+ determineRegionContexts() {
109
+ const debug = this.config.getBoolean('debug');
110
+ const location = this.config.get('location');
111
+ const regionContextPath = this.config.get('regionContextPath');
112
+ if (!location || !regionContextPath) {
113
+ if (debug)
114
+ console.debug(`No region context provided. Using default context properties`);
115
+ return {};
116
+ }
117
+ const regionContextFilePath = path.join(appRoot.path, regionContextPath, `${location}.json`);
118
+ /* alert default context usage when region config is missing */
119
+ if (!fs.existsSync(regionContextFilePath)) {
120
+ if (debug)
121
+ console.debug(`Region context properties unavailable in path:${regionContextFilePath}`);
122
+ if (debug)
123
+ console.debug(`Using default context properties for ${location} location`);
124
+ return {};
125
+ }
126
+ /* read the region properties */
127
+ const regionContextPropsBuffer = fs.readFileSync(regionContextFilePath);
128
+ if (debug)
129
+ console.debug(`Adding region contexts provided in ${regionContextFilePath}`);
130
+ /* parse as JSON properties */
131
+ return JSON.parse(regionContextPropsBuffer.toString('utf-8'));
132
+ }
98
133
  /**
99
134
  * @summary Method to determine extra stage contexts apart from the main context
100
135
  * - Sets the properties from the extra stage contexts
@@ -124,6 +159,36 @@ export class CommonAzureStack extends ComponentResource {
124
159
  /* parse as JSON properties */
125
160
  return JSON.parse(stageContextPropsBuffer.toString('utf-8'));
126
161
  }
162
+ /**
163
+ * @summary Method to determine stage-region contexts for environment and region-specific overrides
164
+ * - Loads `{stageRegionContextPath}/{stage}.{location}.json` if present
165
+ * - Has the highest priority in the configuration hierarchy
166
+ * - Primary use is to override config for a specific stage+region combination (e.g., prd.uksouth.json)
167
+ */
168
+ determineStageRegionContexts() {
169
+ const debug = this.config.getBoolean('debug');
170
+ const stage = this.config.get('stage');
171
+ const location = this.config.get('location');
172
+ const stageRegionContextPath = this.config.get('stageRegionContextPath');
173
+ if (!stage || !location || !stageRegionContextPath) {
174
+ if (debug)
175
+ console.debug(`No stage-region context provided. Using default context properties`);
176
+ return {};
177
+ }
178
+ const stageRegionContextFilePath = path.join(appRoot.path, stageRegionContextPath, `${stage}.${location}.json`);
179
+ /* gracefully skip when stage-region config is missing */
180
+ if (!fs.existsSync(stageRegionContextFilePath)) {
181
+ if (debug)
182
+ console.debug(`Stage-region context properties unavailable in path:${stageRegionContextFilePath}`);
183
+ return {};
184
+ }
185
+ /* read the stage-region properties */
186
+ const stageRegionContextPropsBuffer = fs.readFileSync(stageRegionContextFilePath);
187
+ if (debug)
188
+ console.debug(`Adding stage-region contexts provided in ${stageRegionContextFilePath}`);
189
+ /* parse as JSON properties */
190
+ return JSON.parse(stageRegionContextPropsBuffer.toString('utf-8'));
191
+ }
127
192
  /**
128
193
  * @summary Create the construct instance for this stack
129
194
  * - Override in subclasses to provision infrastructure resources
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils-azure",
3
- "version": "2.35.0",
3
+ "version": "2.36.0",
4
4
  "description": "Azure Pulumi utilities for @gradientedge/cdk-utils",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -23,7 +23,7 @@
23
23
  "lodash": "4.18.1",
24
24
  "uuid": "14.0.0",
25
25
  "yaml": "2.9.0",
26
- "@gradientedge/cdk-utils-common": "2.3.0"
26
+ "@gradientedge/cdk-utils-common": "2.4.0"
27
27
  },
28
28
  "keywords": [
29
29
  "gradientedge",