Skip to content

fix: fail step on non-zero exit code#352

Merged
wilsonjord merged 1 commit intomainfrom
fix-terrform-fmt-errors
Mar 5, 2026
Merged

fix: fail step on non-zero exit code#352
wilsonjord merged 1 commit intomainfrom
fix-terrform-fmt-errors

Conversation

@wilsonjord
Copy link
Contributor

Currently, terraform errors for terraform fmt are not failing the build:
https://github.com/GeoNet/terraform-aws/actions/runs/22419354659/job/64913111658

Run terraform fmt -check -diff=true -recursive
╷
│ Error: Unclosed configuration block
│ 
│   on modules/ecs_docker_task_ng/main.tf line 851, in resource "aws_iam_role_policy" "ecs_taskprotection_policy":
│  851: resource "aws_iam_role_policy" "ecs_taskprotection_policy" {
│ 
│ There is no closing brace for this block before the end of the file. This
│ may be caused by incorrect brace nesting elsewhere in this file.
╵

The reason this failure still passed was due to the fact that the terraform setup action uses a wrapper by default - this wrapper captures stdout, stderr, and exitcode, and exposes those in outputs:

terraform_wrapper - (optional) Whether to install a wrapper to wrap subsequent calls of the terraform binary and expose its STDOUT, STDERR, and exit code as outputs named stdout, stderr, and exitcode respectively. Defaults to true.

As none of those outputs are captured / utilised in this workflow, simplest is to disable the wrapper, and have the normal cli fail -> non zero exit code -> build fails process.

Turn off use of terraform wrapper, and allow the cli to directly return
non-zero exit code.
@wilsonjord wilsonjord force-pushed the fix-terrform-fmt-errors branch from 6d4f124 to c9b4581 Compare February 27, 2026 02:28
@wilsonjord wilsonjord requested a review from jajera February 27, 2026 02:31
@jajera
Copy link
Contributor

jajera commented Mar 4, 2026

@wilsonjord can you please share your last PR which silently exited?

@wilsonjord
Copy link
Contributor Author

@jajera
Copy link
Contributor

jajera commented Mar 5, 2026

Copy link
Contributor

@jajera jajera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets give this a go.

@wilsonjord
Copy link
Contributor Author

@jajera Just for extra context, I believe the key difference between the two is that in one case, terraform fmt was able to be successfully run, parsed valid files, and determined there was a genuine issue.

The other case, terraform fmt wasn't even able to be run, as it detected broken files, so couldn't perform it's task at all.

@wilsonjord wilsonjord merged commit 68c6edb into main Mar 5, 2026
16 checks passed
@wilsonjord wilsonjord deleted the fix-terrform-fmt-errors branch March 5, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants