Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terrafrom fmt in github actions doesn't fail the steps #32472

Closed
7adityaraj opened this issue Jan 6, 2023 · 6 comments
Closed

terrafrom fmt in github actions doesn't fail the steps #32472

7adityaraj opened this issue Jan 6, 2023 · 6 comments
Labels
bug new new issue not yet triaged

Comments

@7adityaraj
Copy link

7adityaraj commented Jan 6, 2023

Terraform Version

terraform_version: 1.3.6

and 

terraform_version: 0.13.6

Terraform Configuration Files

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: '1.3.6'
          terraform_wrapper: true
      
      - run: | 
          terraform fmt -recursive -write=true
          echo $?
        id: fmt

Debug Output

Run hashicorp/setup-terraform@v2
  with:
    terraform_version: 1.3.6
    terraform_wrapper: true
    cli_config_credentials_hostname: app.terraform.io
/usr/bin/unzip -o -q /home/runner/work/_temp/da8cf4e5-8a8f-4bf5-ac29-2bec1cbd9ec1
1s
Run terraform fmt -recursive -write=true
/home/runner/work/_temp/25fd5672-224d-4d3e-a390-20f1258ff026/terraform-bin fmt -recursive -write=true
╷
│ Error: Invalid multi-line string
│ 
│   on services/faktory/locals.tf line 11, in locals:
│   11:   default_region = "us-east-1
│ 
│ Quoted strings may not be split over multiple lines. To produce a
│ multi-line string, either use the \n escape to represent a newline
│ character or use the "heredoc" multi-line template syntax.
╵

╷
│ Error: Unterminated template string
│ 
│   on services/faktory/locals.tf line 11, in locals:
│   11:   default_region = "us-east-1
│ 
│ No closing marker was found for the string.
╵

╷
│ Error: Invalid multi-line string
│ 
│   on services/faktory/service.tf line 1:
│    1: module "service {
│    2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"
│ 
│ Quoted strings may not be split over multiple lines. To produce a
│ multi-line string, either use the \n escape to represent a newline
│ character or use the "heredoc" multi-line template syntax.
╵

╷
│ Error: Invalid string literal
│ 
│   on services/faktory/service.tf line 1:
│    1: module "service {
│    2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"
│ 
│ This item is not valid in a string literal.
╵

╷
│ Error: Invalid character
│ 
│   on services/faktory/service.tf line 2:
│    2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"
│ 
│ This character is not used within the language.
╵

0

^^ status code return

Expected Behavior

previously it used to return error

Run terraform fmt -recursive -write=true
/home/runner/work/_temp/a298dee1-1d82-4385-9f9b-9c71b8bce7b6/terraform-bin fmt -recursive -write=true

Error: Missing item separator

  on services/abc/service.tf line 40, in module "service":
  33:   port_mappings = [{
  34:     "containerPort" : local.container_port,
  35:     "hostPort" : 0,
  36:     "protocol" : "tcp"
  37:     },
  38:   
  40:   aws_tags    = local.aws_tags

Expected a comma to mark the beginning of the next item.


Error: Terraform exited with code 2.
Error: Process completed with exit code 1.

Actual Behavior

It returns status code as '0' and doesn't fail the step.

Run terraform fmt -recursive -write=true
/home/runner/work/_temp/25fd5672-224d-4d3e-a390-20f1258ff026/terraform-bin fmt -recursive -write=true
╷
│ Error: Invalid multi-line string
│ 
│   on services/faktory/locals.tf line 11, in locals:
│   11:   default_region = "us-east-1
│ 
│ Quoted strings may not be split over multiple lines. To produce a
│ multi-line string, either use the \n escape to represent a newline
│ character or use the "heredoc" multi-line template syntax.
╵

╷
│ Error: Unterminated template string
│ 
│   on services/faktory/locals.tf line 11, in locals:
│   11:   default_region = "us-east-1
│ 
│ No closing marker was found for the string.
╵

╷
│ Error: Invalid multi-line string
│ 
│   on services/faktory/service.tf line 1:
│    1: module "service {
│    2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"
│ 
│ Quoted strings may not be split over multiple lines. To produce a
│ multi-line string, either use the \n escape to represent a newline
│ character or use the "heredoc" multi-line template syntax.
╵

╷
│ Error: Invalid string literal
│ 
│   on services/faktory/service.tf line 1:
│    1: module "service {
│    2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"
│ 
│ This item is not valid in a string literal.
╵

╷
│ Error: Invalid character
│ 
│   on services/faktory/service.tf line 2:
│    2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"
│ 
│ This character is not used within the language.
╵

0

Steps to Reproduce

create Github actions workflow and add tf files with broken format

name: Lint Check
on:
  pull_request:
    branches:
      - 'master'

jobs:
  lint-check:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: '1.3.6'
          terraform_wrapper: true
      
      - run: | 
          terraform fmt -recursive -write=true
          echo $?
        id: fmt
      

Additional Context

the same changes when I run the cmd locally, the status code is 2

└─ $ terraform fmt  -recursive -write=true

Error: Invalid multi-line string

  on locals.tf line 11, in locals:
  11:   default_region = "us-east-1

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.


Error: Unterminated template string

  on locals.tf line 11, in locals:
  11:   default_region = "us-east-1

No closing marker was found for the string.


Error: Invalid multi-line string

  on service.tf line 1:
   1: module "service {
   2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"

Quoted strings may not be split over multiple lines. To produce a multi-line
string, either use the \n escape to represent a newline character or use the
"heredoc" multi-line template syntax.


Error: Invalid string literal

  on service.tf line 1:
   1: module "service {
   2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"

This item is not valid in a string literal.


Error: Invalid character

  on service.tf line 2:
   2:   source = "git@github.com:companya/terraform-mod-ecs-service//modules/core?ref=10.6.3"

This character is not used within the language.


└─ $ echo $?
2

└─ $ tf-ver 
Terraform v1.3.6
on darwin_amd64

Your version of Terraform is out of date! The latest version
is 1.3.7. You can update by downloading from https://www.terraform.io/downloads.html

References

No response

@7adityaraj 7adityaraj added bug new new issue not yet triaged labels Jan 6, 2023
@crw
Copy link
Contributor

crw commented Jan 7, 2023

Thanks for this report! One question, are you saying that 0.13.6 had the exit codes and 1.3.6 and 1.3.7 do not?

@7adityaraj
Copy link
Author

Thanks for this report! One question, are you saying that 0.13.6 had the exit codes and 1.3.6 and 1.3.7 do not?

Hi @crw,

Both don't work, but to add we were using 0.13.6 which was working before but now both versions don't work, wondering if it has anything to do with GitHub action versions.

@alisdair
Copy link
Contributor

alisdair commented Jan 9, 2023

Thanks for the report! This doesn't appear to be caused by Terraform, but rather the hashicorp/setup-terraform GitHub action. I've confirmed that Terraform exits correctly with a non-zero exit code when fmt encounters errors.

While I'm not sure this is the issue, the use of terraform_wrapper: true in your configuration is suspect. This wrapper script captures the exit code (among other things) and may be interfering with your expected behaviour. You may want to disable the wrapper script and retry.

If that doesn't work, I recommend filing an issue on the setup-terraform repository. I'm closing this out as it does not appear to be a bug in Terraform itself.

@alisdair alisdair closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2023
@7adityaraj
Copy link
Author

@alisdair thank you for the response. I will check with terraform_wrapper: false and update to hashicorp/setup-terraform

thank you

@7adityaraj
Copy link
Author

@alisdair yes that was the issue, seems something changed from the setup-terraform side but all is good now.

Have a good day.

@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants