@ibm-cloud/cd-tools 1.15.1 → 1.15.3

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 { logger } from './logger.js';
18
+ import { LOG_STAGES, logger } from './logger.js';
19
19
 
20
20
  import { SECRET_KEYS_MAP, SUPPORTED_TOOLS_MAP } from '../../config.js';
21
21
 
@@ -236,6 +236,10 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
236
236
  const propValue = newTfFileObj['resource'][key][k]['value'];
237
237
  if (newTfFileObj['resource'][key][k]['type'] === 'integration' && propValue in toolIdMap) {
238
238
  newTfFileObj['resource'][key][k]['value'] = `\${${toolIdMap[propValue].type}.${toolIdMap[propValue].name}.tool_id}`;
239
+ } else if (propValue) {
240
+ // escape newlines, double quotes and backslashes
241
+ if (propValue.includes('\n')) logger.warn(`Warning! Multi-line values for pipeline and trigger properties are not yet supported in the provider, newlines will be replaced with '\\\\n': "${k}"`, LOG_STAGES.import, true);
242
+ newTfFileObj['resource'][key][k]['value'] = propValue.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/"/g, '\\"');
239
243
  }
240
244
  }
241
245
 
@@ -334,13 +334,15 @@ async function setupTerraformFiles(config) {
334
334
  if (isCompact || resourceName === 'ibm_cd_tekton_pipeline_property') {
335
335
  for (const [k, v] of Object.entries(newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'])) {
336
336
  try {
337
- if (v['type'] === 'integration') {
338
- const thisValue = v['value'];
339
-
340
- if (thisValue in toolIdToTfName) {
341
- const thisTfName = toolIdToTfName[thisValue];
342
- newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
343
- }
337
+ const thisValue = v['value'];
338
+
339
+ if (v['type'] === 'integration' && thisValue in toolIdToTfName) {
340
+ const thisTfName = toolIdToTfName[thisValue];
341
+ newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
342
+ } else if (thisValue) {
343
+ // escape newlines, double quotes and backslashes
344
+ // TODO: remove extra backslash in newline replacement once provider is updated
345
+ newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'][k]['value'] = thisValue.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\r/g, '\\\\r').replace(/"/g, '\\"');
344
346
  }
345
347
  }
346
348
  catch {
@@ -354,13 +356,15 @@ async function setupTerraformFiles(config) {
354
356
  if (isCompact || resourceName === 'ibm_cd_tekton_pipeline_trigger_property') {
355
357
  for (const [k, v] of Object.entries(newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'])) {
356
358
  try {
357
- if (v['type'] === 'integration') {
358
- const thisValue = v['value'];
359
-
360
- if (thisValue in toolIdToTfName) {
361
- const thisTfName = toolIdToTfName[thisValue];
362
- newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
363
- }
359
+ const thisValue = v['value'];
360
+
361
+ if (v['type'] === 'integration' && thisValue in toolIdToTfName) {
362
+ const thisTfName = toolIdToTfName[thisValue];
363
+ newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
364
+ } else if (thisValue) {
365
+ // escape newlines, double quotes and backslashes
366
+ // TODO: remove extra backslash in newline replacement once provider is updated
367
+ newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'][k]['value'] = thisValue.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\r/g, '\\\\r').replace(/"/g, '\\"');
364
368
  }
365
369
  }
366
370
  catch {
@@ -217,5 +217,10 @@ export function normalizeName(str) {
217
217
 
218
218
  newStr = newStr.replaceAll(whitelistRegex, '');
219
219
 
220
+ // terraform resource names must start with a letter
221
+ if (!newStr.slice(0,1).match(/[A-Za-z]/)) {
222
+ newStr = `x_${newStr}`;
223
+ }
224
+
220
225
  return newStr.toLowerCase();
221
226
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibm-cloud/cd-tools",
3
- "version": "1.15.1",
3
+ "version": "1.15.3",
4
4
  "description": "Tools and utilities for the IBM Cloud Continuous Delivery service and resources",
5
5
  "repository": {
6
6
  "type": "git",