@ibm-cloud/cd-tools 1.3.3 → 1.3.4
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 +16 -9
- package/cmd/utils/terraform.js +43 -0
- package/package.json +1 -1
|
@@ -63,19 +63,17 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
|
|
|
63
63
|
// check and add secret refs
|
|
64
64
|
if (tool.tool_type_id in SECRET_KEYS_MAP) {
|
|
65
65
|
SECRET_KEYS_MAP[tool.tool_type_id].forEach(({ key, tfKey, prereq, required }) => {
|
|
66
|
-
if (prereq)
|
|
67
|
-
if (!prereq.values.includes(tool[prereq.key])) return;
|
|
68
|
-
}
|
|
66
|
+
if (prereq && !prereq.values.includes(tool.parameters[prereq.key])) return; // missing prereq
|
|
69
67
|
|
|
70
68
|
if (isSecretReference(tool.parameters[key])) {
|
|
71
69
|
additionalProps[block.name].push({ param: tfKey, value: tool.parameters[key] });
|
|
72
70
|
} else {
|
|
73
71
|
const newFileName = SUPPORTED_TOOLS_MAP[tool.tool_type_id].split('ibm_')[1];
|
|
74
|
-
if (required) {
|
|
72
|
+
if (required || prereq) {
|
|
75
73
|
nonSecretRefs.push({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
resource_name: block.name,
|
|
75
|
+
property_name: tfKey,
|
|
76
|
+
file_name: isCompact ? 'resources.tf' : `${newFileName}.tf`
|
|
79
77
|
});
|
|
80
78
|
additionalProps[block.name].push({ param: tfKey, value: `<${tfKey}>` });
|
|
81
79
|
}
|
|
@@ -180,6 +178,15 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
|
|
|
180
178
|
// do nothing
|
|
181
179
|
}
|
|
182
180
|
|
|
181
|
+
// handle missing worker, which breaks terraform
|
|
182
|
+
try {
|
|
183
|
+
if (newTfFileObj['resource'][key][k]['worker'][0]['id'] === null) {
|
|
184
|
+
delete newTfFileObj['resource'][key][k]['worker'];
|
|
185
|
+
}
|
|
186
|
+
} catch {
|
|
187
|
+
// do nothing
|
|
188
|
+
}
|
|
189
|
+
|
|
183
190
|
// ignore null values
|
|
184
191
|
for (const [k2, v2] of Object.entries(v[0])) {
|
|
185
192
|
if (v2 === null) delete newTfFileObj['resource'][key][k][k2];
|
|
@@ -218,7 +225,7 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
|
|
|
218
225
|
}
|
|
219
226
|
|
|
220
227
|
// add relevent references and depends_on
|
|
221
|
-
if (key === 'ibm_cd_tekton_pipeline') {
|
|
228
|
+
if (key === 'ibm_cd_tekton_pipeline' && newTfFileObj['resource'][key][k]['worker']) {
|
|
222
229
|
const workerId = newTfFileObj['resource'][key][k]['worker'][0]['id'];
|
|
223
230
|
if (workerId != null && workerId != 'public' && workerId in toolIdMap) {
|
|
224
231
|
newTfFileObj['resource'][key][k]['worker'][0]['id'] = `\${${toolIdMap[workerId].type}.${toolIdMap[workerId].name}.tool_id}`;
|
|
@@ -226,7 +233,7 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
|
|
|
226
233
|
} else if (key === 'ibm_cd_tekton_pipeline_property' || key === 'ibm_cd_tekton_pipeline_trigger_property') {
|
|
227
234
|
const propValue = newTfFileObj['resource'][key][k]['value'];
|
|
228
235
|
if (newTfFileObj['resource'][key][k]['type'] === 'integration' && propValue in toolIdMap) {
|
|
229
|
-
newTfFileObj['resource'][key][k]['
|
|
236
|
+
newTfFileObj['resource'][key][k]['value'] = `\${${toolIdMap[propValue].type}.${toolIdMap[propValue].name}.tool_id}`;
|
|
230
237
|
}
|
|
231
238
|
}
|
|
232
239
|
|
package/cmd/utils/terraform.js
CHANGED
|
@@ -92,6 +92,7 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
|
|
|
92
92
|
// for converting legacy GHE tool integrations
|
|
93
93
|
const hasGHE = moreTfResources['github_integrated'].length > 0;
|
|
94
94
|
const repoToTfName = {};
|
|
95
|
+
const toolIdToTfName = {};
|
|
95
96
|
const newConvertedTf = {};
|
|
96
97
|
|
|
97
98
|
if (hasGHE) {
|
|
@@ -100,8 +101,10 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
|
|
|
100
101
|
const tfName = `converted--githubconsolidated_${getRandChars(4)}`;
|
|
101
102
|
|
|
102
103
|
repoToTfName[gitUrl] = tfName;
|
|
104
|
+
toolIdToTfName[t['id']] = tfName;
|
|
103
105
|
newConvertedTf[tfName] = {
|
|
104
106
|
toolchain_id: `\${ibm_cd_toolchain.${newTcId}.id}`,
|
|
107
|
+
name: t['name'],
|
|
105
108
|
initialization: [{
|
|
106
109
|
auto_init: 'false',
|
|
107
110
|
blind_connection: 'false',
|
|
@@ -286,6 +289,46 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
|
|
|
286
289
|
}
|
|
287
290
|
}
|
|
288
291
|
|
|
292
|
+
// add references to converted GHE integrations
|
|
293
|
+
if (isCompact || resourceName === 'ibm_cd_tekton_pipeline_property') {
|
|
294
|
+
for (const [k, v] of Object.entries(newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'])) {
|
|
295
|
+
try {
|
|
296
|
+
if (v['type'] === 'integration') {
|
|
297
|
+
const thisValue = v['value'];
|
|
298
|
+
|
|
299
|
+
if (thisValue in toolIdToTfName) {
|
|
300
|
+
const thisTfName = toolIdToTfName[thisValue];
|
|
301
|
+
newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
// do nothing
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// add references to converted GHE integrations
|
|
313
|
+
if (isCompact || resourceName === 'ibm_cd_tekton_pipeline_trigger_property') {
|
|
314
|
+
for (const [k, v] of Object.entries(newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'])) {
|
|
315
|
+
try {
|
|
316
|
+
if (v['type'] === 'integration') {
|
|
317
|
+
const thisValue = v['value'];
|
|
318
|
+
|
|
319
|
+
if (thisValue in toolIdToTfName) {
|
|
320
|
+
const thisTfName = toolIdToTfName[thisValue];
|
|
321
|
+
newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
// do nothing
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
289
332
|
if (isCompact || resourceName === 'ibm_cd_toolchain_tool_githubconsolidated') {
|
|
290
333
|
if (hasGHE) {
|
|
291
334
|
newTfFileObj['resource']['ibm_cd_toolchain_tool_githubconsolidated'] = {
|