@ibm-cloud/cd-tools 1.15.5 → 1.15.7

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.
@@ -109,13 +109,6 @@ async function main(options) {
109
109
  bearer = await getBearerToken(apiKey);
110
110
  const accountId = await getAccountId(bearer, apiKey);
111
111
 
112
- // check for continuous delivery instance in target region
113
- if (!await getCdInstanceByRegion(bearer, accountId, targetRegion)) {
114
- // give users the option to bypass
115
- logger.warn(`Warning! Could not find a Continuous Delivery instance in the target region ${targetRegion} or you do not have permission to view, please create one before proceeding if one does not exist already.`, LOG_STAGES.setup);
116
- await promptUserConfirmation(`Do you want to proceed anyway?`, 'yes', 'Toolchain migration cancelled.');
117
- }
118
-
119
112
  // check for existing .tf files in output directory
120
113
  if (fs.existsSync(outputDir)) {
121
114
  let files = fs.readdirSync(outputDir, { recursive: true });
@@ -164,8 +157,20 @@ async function main(options) {
164
157
  exit(1);
165
158
  }
166
159
 
160
+ // check for continuous delivery instance in target region and resource group
161
+ const cdInstances = await getCdInstanceByRegion(bearer, accountId, targetRegion);
162
+ const cdInstanceFound = cdInstances?.some((instance) => {
163
+ return instance.doc?.resource_group_id === sourceToolchainData['resource_group_id'];
164
+ });
165
+
166
+ if (!cdInstanceFound) {
167
+ // give users the option to bypass
168
+ logger.warn(`Warning! Could not find a Continuous Delivery instance in the target region ${targetRegion} and toolchain's resource group or you do not have permission to view, please create one before proceeding if one does not exist already.`, LOG_STAGES.setup);
169
+ await promptUserConfirmation(`Do you want to proceed anyway?`, 'yes', 'Toolchain migration cancelled.');
170
+ }
171
+
167
172
  const resourceGroups = await getResourceGroups(bearer, accountId, [targetRg || sourceToolchainData['resource_group_id']]);
168
- ({ id: targetRgId, name: targetRgName } = resourceGroups[0])
173
+ ({ id: targetRgId, name: targetRgName } = resourceGroups[0]);
169
174
  // reuse name if not provided
170
175
  if (!targetToolchainName) targetToolchainName = sourceToolchainData['name'];
171
176
  [targetToolchainName, targetTag] = await warnDuplicateName(bearer, accountId, targetToolchainName, sourceRegion, targetRegion, targetRgId, targetRgName, targetTag, skipUserConfirmation);
@@ -180,7 +180,7 @@ async function getCdInstanceByRegion(bearer, accountId, region) {
180
180
  const response = await axios(options);
181
181
  switch (response.status) {
182
182
  case 200:
183
- return response.data.items.length > 0;
183
+ return response.data.items.length > 0 ? response.data.items : null;
184
184
  default:
185
185
  throw Error('Get CD instance failed');
186
186
  }
@@ -268,7 +268,7 @@ async function setupTerraformFiles(config) {
268
268
  for (const [k, v] of Object.entries(newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger'])) {
269
269
  try {
270
270
  const thisUrl = v['source'][0]['properties'][0]['url'];
271
- if (!v['depends_on'] && thisUrl) {
271
+ if (!v['depends_on'] && thisUrl && repoToTfName[thisUrl]) {
272
272
  newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger'][k]['depends_on'] = [`ibm_cd_toolchain_tool_githubconsolidated.${repoToTfName[thisUrl]}`]
273
273
  }
274
274
  }
@@ -302,7 +302,7 @@ async function setupTerraformFiles(config) {
302
302
  for (const [k, v] of Object.entries(newTfFileObj['resource']['ibm_cd_tekton_pipeline_definition'])) {
303
303
  try {
304
304
  const thisUrl = v['source'][0]['properties'][0]['url'];
305
- if (!v['depends_on'] && thisUrl) {
305
+ if (!v['depends_on'] && thisUrl && repoToTfName[thisUrl]) {
306
306
  newTfFileObj['resource']['ibm_cd_tekton_pipeline_definition'][k]['depends_on'] = [`ibm_cd_toolchain_tool_githubconsolidated.${repoToTfName[thisUrl]}`]
307
307
  }
308
308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibm-cloud/cd-tools",
3
- "version": "1.15.5",
3
+ "version": "1.15.7",
4
4
  "description": "Tools and utilities for the IBM Cloud Continuous Delivery service and resources",
5
5
  "repository": {
6
6
  "type": "git",