@gradientedge/cdk-utils-azure 2.35.0 → 2.37.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
@@ -55,14 +55,13 @@ export class CommonAzureStack extends ComponentResource {
55
55
  * @returns The stack properties
56
56
  */
57
57
  determineConstructProps(props) {
58
- return {
59
- ...props,
58
+ return _.merge({}, props, {
60
59
  extraContexts: this.config.getObject('extraContexts'),
60
+ regionContextPath: this.config.get('regionContextPath'),
61
61
  stage: this.config.get('stage'),
62
62
  stageContextPath: this.config.get('stageContextPath'),
63
- ...this.determineExtraContexts(),
64
- ...this.determineStageContexts(),
65
- };
63
+ stageRegionContextPath: this.config.get('stageRegionContextPath'),
64
+ }, this.determineExtraContexts(), this.determineRegionContexts(), this.determineStageContexts(), this.determineStageRegionContexts());
66
65
  }
67
66
  /**
68
67
  * @summary Method to determine extra contexts apart from the main context
@@ -88,13 +87,41 @@ export class CommonAzureStack extends ComponentResource {
88
87
  if (debug)
89
88
  console.debug(`Adding additional contexts provided in ${extraContextPath}`);
90
89
  /* parse as JSON properties */
91
- extraContextProps = {
92
- ...extraContextProps,
93
- ...JSON.parse(extraContextPropsBuffer.toString('utf-8')),
94
- };
90
+ extraContextProps = _.merge(extraContextProps, JSON.parse(extraContextPropsBuffer.toString('utf-8')));
95
91
  });
96
92
  return extraContextProps;
97
93
  }
94
+ /**
95
+ * @summary Method to determine region contexts apart from the main context
96
+ * - Location is resolved from `location` Pulumi config
97
+ * - Loads `{regionContextPath}/{location}.json` if present
98
+ * - Primary use is to have layered config for each region in separate files
99
+ */
100
+ determineRegionContexts() {
101
+ const debug = this.config.getBoolean('debug');
102
+ const location = this.config.get('location');
103
+ const regionContextPath = this.config.get('regionContextPath');
104
+ if (!location || !regionContextPath) {
105
+ if (debug)
106
+ console.debug(`No region context provided. Using default context properties`);
107
+ return {};
108
+ }
109
+ const regionContextFilePath = path.join(appRoot.path, regionContextPath, `${location}.json`);
110
+ /* alert default context usage when region config is missing */
111
+ if (!fs.existsSync(regionContextFilePath)) {
112
+ if (debug)
113
+ console.debug(`Region context properties unavailable in path:${regionContextFilePath}`);
114
+ if (debug)
115
+ console.debug(`Using default context properties for ${location} location`);
116
+ return {};
117
+ }
118
+ /* read the region properties */
119
+ const regionContextPropsBuffer = fs.readFileSync(regionContextFilePath);
120
+ if (debug)
121
+ console.debug(`Adding region contexts provided in ${regionContextFilePath}`);
122
+ /* parse as JSON properties */
123
+ return JSON.parse(regionContextPropsBuffer.toString('utf-8'));
124
+ }
98
125
  /**
99
126
  * @summary Method to determine extra stage contexts apart from the main context
100
127
  * - Sets the properties from the extra stage contexts
@@ -124,6 +151,36 @@ export class CommonAzureStack extends ComponentResource {
124
151
  /* parse as JSON properties */
125
152
  return JSON.parse(stageContextPropsBuffer.toString('utf-8'));
126
153
  }
154
+ /**
155
+ * @summary Method to determine stage-region contexts for environment and region-specific overrides
156
+ * - Loads `{stageRegionContextPath}/{stage}.{location}.json` if present
157
+ * - Has the highest priority in the configuration hierarchy
158
+ * - Primary use is to override config for a specific stage+region combination (e.g., prd.uksouth.json)
159
+ */
160
+ determineStageRegionContexts() {
161
+ const debug = this.config.getBoolean('debug');
162
+ const stage = this.config.get('stage');
163
+ const location = this.config.get('location');
164
+ const stageRegionContextPath = this.config.get('stageRegionContextPath');
165
+ if (!stage || !location || !stageRegionContextPath) {
166
+ if (debug)
167
+ console.debug(`No stage-region context provided. Using default context properties`);
168
+ return {};
169
+ }
170
+ const stageRegionContextFilePath = path.join(appRoot.path, stageRegionContextPath, `${stage}.${location}.json`);
171
+ /* gracefully skip when stage-region config is missing */
172
+ if (!fs.existsSync(stageRegionContextFilePath)) {
173
+ if (debug)
174
+ console.debug(`Stage-region context properties unavailable in path:${stageRegionContextFilePath}`);
175
+ return {};
176
+ }
177
+ /* read the stage-region properties */
178
+ const stageRegionContextPropsBuffer = fs.readFileSync(stageRegionContextFilePath);
179
+ if (debug)
180
+ console.debug(`Adding stage-region contexts provided in ${stageRegionContextFilePath}`);
181
+ /* parse as JSON properties */
182
+ return JSON.parse(stageRegionContextPropsBuffer.toString('utf-8'));
183
+ }
127
184
  /**
128
185
  * @summary Create the construct instance for this stack
129
186
  * - 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.37.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",