diff --git a/node/README.md b/node/README.md index d4fd824..ede339c 100644 --- a/node/README.md +++ b/node/README.md @@ -77,15 +77,20 @@ The order of precedence of the arguments is: - Alias: `-p` ### Blueprint ID -> The Blueprint ID you would like to deploy with (Required for new environments) +> The Blueprint ID you wish to deploy with (Required for new environments) - Usage: `--blueprintId` - Alias: `-b` ### Environment Name -> The environment name you would like to create, or deploy to an existing one (Required for existing environments) +> The environment name you wish to create, or deploy to an existing one (Required for existing environments) - Usage: `--environmentName` - Alias: `-e` +### Environment ID +> The environment id you wish to re-deploy. If both the environment name and ID are specified, the environment ID will take precedence +- Usage: `--environmentId` +- Alias: N/A + ### Workspace Name > (Optional) - A name for Terraform Workspace created for your new environment. This cannot be changed after an environment was created - Usage: `--workspaceName` @@ -138,6 +143,7 @@ This file holds your last action's required parameters and will spare you from r - `ENV0_PROJECT_ID` - `ENV0_BLUEPRINT_ID` - `ENV0_ENVIRONMENT_NAME` +- `ENV0_ENVIRONMENT_ID` ## API Reference diff --git a/node/src/config/arguments.js b/node/src/config/arguments.js index 705a990..8f9366d 100644 --- a/node/src/config/arguments.js +++ b/node/src/config/arguments.js @@ -8,6 +8,7 @@ const { BLUEPRINT_ID, WORKSPACE_NAME, ENVIRONMENT_NAME, + ENVIRONMENT_ID, ENVIRONMENT_VARIABLES, TERRAFORM_VARIABLES, SENSITIVE_ENVIRONMENT_VARIABLES, @@ -67,6 +68,13 @@ const argumentsMap = { prompt: 'Environment Name', group: ['deploy', 'destroy', 'approve', 'cancel', 'configure'] }, + [ENVIRONMENT_ID]: { + name: ENVIRONMENT_NAME, + type: String, + description: 'The environment id you want to perform the action on', + prompt: 'Environment ID', + group: ['deploy', 'destroy', 'approve', 'cancel', 'configure'] + }, [BLUEPRINT_ID]: { name: BLUEPRINT_ID, alias: 'b', diff --git a/node/src/config/constants.js b/node/src/config/constants.js index 61e8d45..0c7c466 100644 --- a/node/src/config/constants.js +++ b/node/src/config/constants.js @@ -5,6 +5,7 @@ const options = { PROJECT_ID: 'projectId', BLUEPRINT_ID: 'blueprintId', ENVIRONMENT_NAME: 'environmentName', + ENVIRONMENT_ID: 'environmentId', WORKSPACE_NAME: 'workspaceName', ENVIRONMENT_VARIABLES: 'environmentVariables', TERRAFORM_VARIABLES: 'terraformVariables', diff --git a/node/src/lib/config-manager.js b/node/src/lib/config-manager.js index 5fcf306..67f45ab 100644 --- a/node/src/lib/config-manager.js +++ b/node/src/lib/config-manager.js @@ -7,7 +7,7 @@ const logger = require('./logger'); const CONFIG_FILE = path.join(os.homedir(), '.env0', 'config.json'); -const { API_KEY, API_SECRET, ORGANIZATION_ID, PROJECT_ID, BLUEPRINT_ID, ENVIRONMENT_NAME } = options; +const { API_KEY, API_SECRET, ORGANIZATION_ID, PROJECT_ID, BLUEPRINT_ID, ENVIRONMENT_NAME, ENVIRONMENT_ID } = options; const INCLUDED_OPTIONS = [API_KEY, API_SECRET, ORGANIZATION_ID, PROJECT_ID, BLUEPRINT_ID, ENVIRONMENT_NAME]; @@ -17,7 +17,8 @@ const envVarToOptionMapper = { ENV0_ORGANIZATION_ID: ORGANIZATION_ID, ENV0_PROJECT_ID: PROJECT_ID, ENV0_BLUEPRINT_ID: BLUEPRINT_ID, - ENV0_ENVIRONMENT_NAME: ENVIRONMENT_NAME + ENV0_ENVIRONMENT_NAME: ENVIRONMENT_NAME, + ENV0_ENVIRONMENT_ID: ENVIRONMENT_ID }; const getEnvVars = () => { diff --git a/node/src/lib/deploy-utils.js b/node/src/lib/deploy-utils.js index ce544a4..345e546 100644 --- a/node/src/lib/deploy-utils.js +++ b/node/src/lib/deploy-utils.js @@ -23,10 +23,18 @@ class DeployUtils { await apiClient.init(options[API_KEY], options[API_SECRET]); } - async getEnvironment(environmentName, projectId) { - const environments = await apiClient.callApi('get', `environments?projectId=${projectId}&name=${environmentName}`); + async getEnvironment(options) { + const { environmentName, environmentId, projectId } = options; - return isEmpty(environments) ? undefined : environments[0]; + if (environmentId) { + return await apiClient.callApi('get', `environments/${environmentId}`); + } else { + const environments = await apiClient.callApi( + 'get', + `environments?projectId=${projectId}&name=${environmentName}` + ); + return isEmpty(environments) ? undefined : environments[0]; + } } async getDeployment(deploymentLogId) { @@ -34,15 +42,13 @@ class DeployUtils { } async getDeploymentSteps(deploymentLogId) { - return await apiClient.callApi('get', `deployments/${deploymentLogId}/steps`) + return await apiClient.callApi('get', `deployments/${deploymentLogId}/steps`); } async getDeploymentStepLog(deploymentLogId, stepName, startTime) { - return await apiClient.callApi( - 'get', - `deployments/${deploymentLogId}/steps/${stepName}/log`, - { params: { startTime } } - ) + return await apiClient.callApi('get', `deployments/${deploymentLogId}/steps/${stepName}/log`, { + params: { startTime } + }); } async updateEnvironment(environment, data) { @@ -106,8 +112,8 @@ class DeployUtils { const { status } = steps.find(step => step.name === stepName); const stepInProgress = status === 'IN_PROGRESS'; - const { events, nextStartTime, hasMoreLogs } = await withRetry( - () => this.getDeploymentStepLog(deploymentLogId, stepName, startTime) + const { events, nextStartTime, hasMoreLogs } = await withRetry(() => + this.getDeploymentStepLog(deploymentLogId, stepName, startTime) ); events.forEach(event => logger.info(event.message));