From 6999fa8f8cd0816d02d07e7521fa8f9c4b059969 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Tue, 1 Nov 2022 18:02:41 +0800 Subject: [PATCH] Fixed error when running apply and the environment doesn't exist for a project --- .changeset/grumpy-turkeys-fail.md | 5 +++++ libs/nx-terraform/src/executors/apply/executor.ts | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 .changeset/grumpy-turkeys-fail.md diff --git a/.changeset/grumpy-turkeys-fail.md b/.changeset/grumpy-turkeys-fail.md new file mode 100644 index 0000000..bb4f110 --- /dev/null +++ b/.changeset/grumpy-turkeys-fail.md @@ -0,0 +1,5 @@ +--- +'@arkahna/nx-terraform': patch +--- + +Fixed apply erroring when an environment doesn't exist for a project diff --git a/libs/nx-terraform/src/executors/apply/executor.ts b/libs/nx-terraform/src/executors/apply/executor.ts index 6f8d9af..31418ad 100644 --- a/libs/nx-terraform/src/executors/apply/executor.ts +++ b/libs/nx-terraform/src/executors/apply/executor.ts @@ -1,6 +1,7 @@ import { ExecutorContext } from '@nrwl/devkit' import execa from 'execa' import { getEscapedCommand } from 'execa/lib/command' +import { existsSync } from 'fs' import publicIp from 'public-ip' import { addFirewallRulesWithRetry } from '../../common/addFirewallRulesWithRetry' import { createTerragruntCliArgs } from '../../common/createTerragruntCliArgs' @@ -50,6 +51,13 @@ export default async function runExecutor(options: ApplyExecutorSchema, context: subscriptionId, } = config + if (!existsSync(terragruntConfigFile)) { + console.log('No terragrunt config file found, skipping apply') + return { + success: true, + } + } + const currentAccount = await getCurrentAzAccount() if (subscriptionId !== currentAccount.id) {