From 5bf63f277b9f91ba61a935134af82e6736ee691f Mon Sep 17 00:00:00 2001 From: Charles Kenney Date: Tue, 8 Jan 2019 13:47:31 -0500 Subject: [PATCH] handle no changes --- src/index.ts | 6 ++++++ test/unit/data/13-no-changes.expected.json | 5 +++++ test/unit/data/13-no-changes.stdout.txt | 12 ++++++++++++ test/unit/terraform-plan-parser.test.ts | 4 ++++ 4 files changed, 27 insertions(+) create mode 100644 test/unit/data/13-no-changes.expected.json create mode 100644 test/unit/data/13-no-changes.stdout.txt diff --git a/src/index.ts b/src/index.ts index 472ec23..92e045a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,7 @@ export interface ParseResult { changedDataSources: Array; } +const NO_CHANGES_STRING = '\nNo changes. Infrastructure is up-to-date.\n'; const CONTENT_START_STRING = '\nTerraform will perform the following actions:\n'; const CONTENT_END_STRING = '\nPlan:'; const OLD_NEW_SEPARATOR = ' => '; @@ -356,6 +357,11 @@ export function parseStdout (logOutput: string): ParseResult { let lastChange = null; + if (logOutput.includes(NO_CHANGES_STRING)) { + // no changes to parse... + return result; + } + const startPos = findParseableContentStartPos(logOutput); if (startPos === -1) { result.errors.push({ diff --git a/test/unit/data/13-no-changes.expected.json b/test/unit/data/13-no-changes.expected.json new file mode 100644 index 0000000..5d9206d --- /dev/null +++ b/test/unit/data/13-no-changes.expected.json @@ -0,0 +1,5 @@ +{ + "errors": [], + "changedResources": [], + "changedDataSources": [] +} diff --git a/test/unit/data/13-no-changes.stdout.txt b/test/unit/data/13-no-changes.stdout.txt new file mode 100644 index 0000000..d805ed4 --- /dev/null +++ b/test/unit/data/13-no-changes.stdout.txt @@ -0,0 +1,12 @@ +Refreshing Terraform state in-memory prior to plan... +The refreshed state will be used to calculate this plan, but will not be +persisted to local or remote state storage. + + +------------------------------------------------------------------------ + +No changes. Infrastructure is up-to-date. + +This means that Terraform did not detect any differences between your +configuration and real physical resources that exist. As a result, no +actions need to be performed. diff --git a/test/unit/terraform-plan-parser.test.ts b/test/unit/terraform-plan-parser.test.ts index 597a9af..9d66107 100644 --- a/test/unit/terraform-plan-parser.test.ts +++ b/test/unit/terraform-plan-parser.test.ts @@ -74,3 +74,7 @@ test('should handle tainted resources', async (t) => { test('should handle modules', async (t) => { return runTest('12-modules', t); }); + +test('should handle no changes', async (t) => { + return runTest('13-no-changes', t); +});