@ibm-cloud/cd-tools 1.12.0 → 1.13.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.
@@ -283,7 +283,8 @@ async function main(options) {
283
283
  moreTfResources: moreTfResources,
284
284
  gritMapping: gritMapping,
285
285
  skipUserConfirmation: skipUserConfirmation,
286
- includeS2S: includeS2S
286
+ includeS2S: includeS2S,
287
+ timeSuffix: TIME_SUFFIX
287
288
  });
288
289
  } catch (err) {
289
290
  if (err.message && err.stack) {
@@ -332,8 +333,11 @@ async function main(options) {
332
333
  // create toolchain, which invokes script to create s2s if applicable
333
334
  await runTerraformApply(true, outputDir, verbosity, `ibm_cd_toolchain.${toolchainTfName}`);
334
335
 
335
- const hasS2SFailures = fs.existsSync(resolve(`${outputDir}/.s2s-script-failures`));
336
- if (hasS2SFailures) logger.warn('\nWarning! One or more service-to-service auth policies could not be created!\n', LOG_STAGES.setup, true);
336
+ const hasS2SFailures = fs.existsSync(resolve(`${outputDir}/.s2s-script-failures-${TIME_SUFFIX}`));
337
+ if (hasS2SFailures) {
338
+ logger.print(''); // newline for spacing
339
+ logger.warn(`Warning! One or more service-to-service auth policies could not be created! See ${outputDir}/.s2s-script-failures-${TIME_SUFFIX} for more details.\n`, LOG_STAGES.setup, true);
340
+ }
337
341
 
338
342
  // create the rest
339
343
  await runTerraformApply(skipUserConfirmation, outputDir, verbosity).catch((err) => {
@@ -346,7 +350,7 @@ async function main(options) {
346
350
 
347
351
  if (verbosity >= 1) logger.print(''); // newline for spacing
348
352
  logger.info(`Toolchain "${sourceToolchainData['name']}" from ${sourceRegion} was cloned to "${targetToolchainName ?? sourceToolchainData['name']}" in ${targetRegion} ${applyErrors ? 'with some errors' : 'successfully'}, with ${numResourcesCreated} / ${numResourcesPlanned} resources created!`, LOG_STAGES.info, true);
349
- if (hasS2SFailures) logger.warn('One or more service-to-service auth policies could not be created, see .s2s-script-failures for more details.');
353
+ if (hasS2SFailures) logger.warn(`One or more service-to-service auth policies could not be created, see ${outputDir}/.s2s-script-failures-${TIME_SUFFIX} for more details.`, '', true);
350
354
  if (newTcId) logger.info(`Cloned toolchain: https://${CLOUD_PLATFORM}/devops/toolchains/${newTcId}?env_id=ibm:yp:${targetRegion}`, LOG_STAGES.info, true);
351
355
  } else {
352
356
  logger.info(`DRY_RUN: ${dryRun}, skipping terraform apply...`, LOG_STAGES.tf);
@@ -280,7 +280,7 @@ async function main(options) {
280
280
  const commonProps = {
281
281
  toolchain_id: toolchainId,
282
282
  destination: {
283
- is_private: false, // TODO: set this back to 'true' once 'otc-api' has the 'export_secret' endpoint, should always use SM private endpoint
283
+ is_private: true,
284
284
  is_production: CLOUD_PLATFORM === 'cloud.ibm.com',
285
285
  secrets_manager_crn: smInstance.crn,
286
286
  secret_name: smSecretName,
@@ -68,7 +68,7 @@ async function initProviderFile(targetRegion, dir) {
68
68
  return writeFilePromise(`${dir}/provider.tf`, jsonToTf(newProviderTfStr));
69
69
  }
70
70
 
71
- async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag, targetToolchainName, targetRgId, disableTriggers, isCompact, outputDir, tempDir, moreTfResources, gritMapping, skipUserConfirmation, includeS2S }) {
71
+ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag, targetToolchainName, targetRgId, disableTriggers, isCompact, outputDir, tempDir, moreTfResources, gritMapping, skipUserConfirmation, includeS2S, timeSuffix }) {
72
72
  const promises = [];
73
73
 
74
74
  const writeProviderPromise = await initProviderFile(targetRegion, outputDir);
@@ -359,7 +359,9 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
359
359
 
360
360
  const newTfFileObjStr = JSON.stringify(newTfFileObj);
361
361
  let newTfFile = replaceDependsOn(jsonToTf(newTfFileObjStr));
362
- if (includeS2S && (isCompact || resourceName === 'ibm_cd_toolchain')) newTfFile = addS2sScriptToToolchainTf(newTfFile);
362
+ if (includeS2S && (isCompact || resourceName === 'ibm_cd_toolchain')) {
363
+ newTfFile = addS2sScriptToToolchainTf(newTfFile, timeSuffix);
364
+ }
363
365
  const copyResourcesPromise = writeFilePromise(`${outputDir}/${fileName}`, newTfFile);
364
366
  promises.push(copyResourcesPromise);
365
367
  }
@@ -487,7 +489,7 @@ function replaceDependsOn(str) {
487
489
  }
488
490
  }
489
491
 
490
- function addS2sScriptToToolchainTf(str) {
492
+ function addS2sScriptToToolchainTf(str, timeSuffix) {
491
493
  const provisionerStr = (tfName) => `\n\n provisioner "local-exec" {
492
494
  command = "node create-s2s-script.cjs"
493
495
  on_failure = continue
@@ -496,6 +498,7 @@ function addS2sScriptToToolchainTf(str) {
496
498
  TARGET_TOOLCHAIN_ID = ibm_cd_toolchain.${tfName}.id
497
499
  IBMCLOUD_PLATFORM = "${CLOUD_PLATFORM}"
498
500
  IAM_BASE_URL = "${IAM_BASE_URL}"
501
+ GENERATED_TIME = "${timeSuffix}" # corresponds with error log
499
502
  }\n }`
500
503
  try {
501
504
  if (typeof str === 'string') {
@@ -23,8 +23,11 @@ if (!CLOUD_PLATFORM) throw Error(`Missing 'IBMCLOUD_PLATFORM'`);
23
23
  const IAM_BASE_URL = process.env['IAM_BASE_URL'] || 'https://iam.cloud.ibm.com';
24
24
  if (!IAM_BASE_URL) throw Error(`Missing 'IAM_BASE_URL'`);
25
25
 
26
+ const GENERATED_TIME = process.env['GENERATED_TIME'];
27
+ if (!GENERATED_TIME) throw Error(`Missing 'GENERATED_TIME'`);
28
+
26
29
  const INPUT_PATH = resolve('create-s2s.json');
27
- const ERROR_PATH = resolve('.s2s-script-failures');
30
+ const ERROR_PATH = resolve(`.s2s-script-failures-${GENERATED_TIME}`);
28
31
 
29
32
  async function getBearer() {
30
33
  const url = `${IAM_BASE_URL}/identity/token`;
@@ -125,12 +128,23 @@ getBearer().then(async (bearer) => {
125
128
  promises.push(createS2sAuthPolicy(bearer, item));
126
129
  });
127
130
 
128
- try {
129
- await Promise.all(promises);
130
- } catch (e) {
131
- console.error(e);
132
- // create temp file on error
133
- fs.writeFileSync(ERROR_PATH, e);
134
- exit(1);
135
- }
131
+ await Promise.allSettled(promises).then((res) => {
132
+ const rejectReasons = res.filter(r => r.status === 'rejected').map(r => r.reason);
133
+
134
+ if (rejectReasons.length > 0) {
135
+ let errFileContents = '';
136
+ rejectReasons.forEach((reason) => {
137
+ console.error(reason);
138
+ // create temp file on error
139
+ errFileContents += reason;
140
+ errFileContents += '\n';
141
+ });
142
+ fs.writeFileSync(ERROR_PATH, errFileContents);
143
+ exit(1);
144
+ }
145
+ });
146
+ }).catch((reason) => {
147
+ console.error(reason);
148
+ // create temp file on error
149
+ fs.writeFileSync(ERROR_PATH, reason + '\n');
136
150
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibm-cloud/cd-tools",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Tools and utilities for the IBM Cloud Continuous Delivery service and resources",
5
5
  "repository": {
6
6
  "type": "git",