Skip to content

Commit

Permalink
fix: remove resource refresh from output plans (#40)
Browse files Browse the repository at this point in the history
This removes the terraform resource refresh output
from plans that only have output changes.
  • Loading branch information
patheard authored Aug 13, 2021
1 parent 0b1f884 commit fbf74f0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
11 changes: 9 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,16 @@ const removePlanRefresh = (plan) => {
const startTokens = [
"No changes. Infrastructure is up-to-date",
"Resource actions are indicated with the following symbols",
"Changes to Outputs",
];

// This will only strip the first refresh token it finds in the plan ouput
for (let token of startTokens) {
plan = plan.substring(plan.indexOf(token));
let index = plan.indexOf(token);
if (index > -1) {
plan = plan.substring(index);
break;
}
}
return plan;
};
Expand Down
2 changes: 1 addition & 1 deletion src/policy/policy.js

Large diffs are not rendered by default.

Binary file modified src/policy/policy.wasm
Binary file not shown.
27 changes: 25 additions & 2 deletions test/github.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,20 @@ describe("removePlanRefresh", () => {
~ update in-place
- destroy
Terraform will perform the following actions:`;
Terraform will perform the following actions:
Changes to Outputs:
foo=bar`;
const expected = `Resource actions are indicated with the following symbols:
+ create
~ update in-place
- destroy
Terraform will perform the following actions:`;
Terraform will perform the following actions:
Changes to Outputs:
foo=bar`;
expect(removeRefreshOutput(plan)).toBe(expected);
});

Expand All @@ -224,6 +230,23 @@ describe("removePlanRefresh", () => {
expect(removeRefreshOutput(plan)).toBe(expected);
});

test("remove refresh for plan with only output changes", async () => {
const plan = `aws_lambda_permission.api: Refreshing state... [id=AllowAPIGatewayInvoke]
aws_api_gateway_integration.integration: Refreshing state... [id=agi]
Changes to Outputs:
+ scan_websites_kms_key_arn = "arn:aws:kms:ca-central-1:12345:key/67890"
You can apply this plan to save these new output values to the Terraform
state, without changing any real infrastructure.`;
const expected = `Changes to Outputs:
+ scan_websites_kms_key_arn = "arn:aws:kms:ca-central-1:12345:key/67890"
You can apply this plan to save these new output values to the Terraform
state, without changing any real infrastructure.`;
expect(removeRefreshOutput(plan)).toBe(expected);
});

test("no change if start tokens do not exist", async () => {
const plan = `This is a string without any plan start tokens
for good measure, there's a line break in the mix`;
Expand Down

0 comments on commit fbf74f0

Please sign in to comment.