@ibm-cloud/cd-tools 1.15.11 → 1.15.14

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.
@@ -15,7 +15,7 @@ import { jsonToTf } from 'json-to-tf';
15
15
  import { getPipelineData, getToolchainTools } from './requests.js';
16
16
  import { runTerraformPlanGenerate, setTerraformEnv } from './terraform.js';
17
17
  import { getRandChars, isSecretReference, normalizeName } from './utils.js';
18
- import { LOG_STAGES, logger } from './logger.js';
18
+ import { logger } from './logger.js';
19
19
 
20
20
  import { SECRET_KEYS_MAP, SUPPORTED_TOOLS_MAP } from '../../config.js';
21
21
 
@@ -220,6 +220,15 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
220
220
  // do nothing
221
221
  }
222
222
 
223
+ // if parameters is now empty after removing null values, remove parameters entirely
224
+ try {
225
+ if (Object.keys(v[0]['parameters'][0]).length === 0) {
226
+ delete newTfFileObj['resource'][key][k]['parameters'];
227
+ }
228
+ } catch {
229
+ // do nothing
230
+ }
231
+
223
232
  // ignore null values (if it exists) in source properties
224
233
  try {
225
234
  if (Object.keys(v[0]['source'][0]['properties'][0]).length > 0) {
@@ -331,13 +340,20 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
331
340
 
332
341
  if (!isCompact) {
333
342
  for (const [key, value] of Object.entries(newTfFileObj['resource'])) {
334
- if (!key.startsWith('ibm_')) continue;
335
- const newFileName = key.split('ibm_')[1];
336
-
337
- const newFileContents = { 'resource': { [key]: value } };
338
- const newFileContentsJson = jsonToTf(JSON.stringify(newFileContents));
339
-
340
- fs.writeFileSync(`${dir}/generated/${newFileName}.tf`, newFileContentsJson);
343
+ try {
344
+ if (!key.startsWith('ibm_')) continue;
345
+ const newFileName = key.split('ibm_')[1];
346
+
347
+ const newFileContentsJson = { 'resource': { [key]: value } };
348
+ const newFileContentsTf = jsonToTf(JSON.stringify(newFileContentsJson));
349
+
350
+ fs.writeFileSync(`${dir}/generated/${newFileName}.tf`, newFileContentsTf);
351
+ } catch (err) {
352
+ // some extra error logging
353
+ logger.dump(`\nCurrent resource: ${key}`);
354
+ logger.dump(`\n Current resource value: ${JSON.stringify(value, null, 2)}`);
355
+ throw err;
356
+ }
341
357
  }
342
358
  } else {
343
359
  const generatedFileNew = jsonToTf(JSON.stringify(newTfFileObj));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibm-cloud/cd-tools",
3
- "version": "1.15.11",
3
+ "version": "1.15.14",
4
4
  "description": "Tools and utilities for the IBM Cloud Continuous Delivery service and resources",
5
5
  "repository": {
6
6
  "type": "git",