@ibm-cloud/cd-tools 1.15.2 → 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.
- package/cmd/utils/import-terraform.js +5 -1
- package/cmd/utils/terraform.js +18 -14
- package/package.json +1 -1
|
@@ -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
|
|
package/cmd/utils/terraform.js
CHANGED
|
@@ -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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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 {
|