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

Getting error Argument or block definition required; An argument or block definition is required here #244

Open
Pardeep009 opened this issue Aug 24, 2022 · 1 comment

Comments

@Pardeep009
Copy link

Pardeep009 commented Aug 24, 2022

We are submitting a file_name.hcl.json to atlantis, before plan and apply runs, pre-workflow-hook terragrunt-atlantis-config_1.14.2_linux_amd64 generate --output atlantis.yaml --parallel=false --autoplan --automerge --ignore-dependency-blocks=true runs which should have generated atlantis.yaml, but it didn't generate any such file and when I manually ran the pre-workflow-hook command it gave error as file_name.hcl.json:1,1-2: Argument or block definition required; An argument or block definition is required here.
content of file_name.hcl.json

{
  "include": [
    {
      "path": "${find_in_parent_folders()}"
    }
  ],
  "terraform": [
    {
      "source": "<referring some open source tf-module>"
    }
  ],
  "dependency": [
    {
      "project": [
        {
          "config_path": "${get_parent_terragrunt_dir()}/<referring project terragrunt file>"
        }
      ]
    }
  ],
  "inputs": {
    "a" : "b",
    "c" : "d"
  }
}

but if I run terragrunt plan locally in that file location it works.
captured server logs from atlantis when file_name.hcl.json is submitted

Aug 24 19:40:50 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:50.484Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:40:51 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:51.523Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:40:53 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:53.534Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:40:54 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:54.983Z","caller":"events/events_controller.go:461","msg":"identified event as type \"updated\"","json":{}}
Aug 24 19:40:54 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:54.983Z","caller":"events/events_controller.go:346","msg":"executing autoplan","json":{}}
Aug 24 19:40:55 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:55.013Z","caller":"events/working_dir.go:202","msg":"creating dir \"/opt/atlantis/.atlantis/repos/iac/iac/XXX/default\"","json":{"repo":"iac/iac","pull":"XXX"}}
Aug 24 19:40:55 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:55.483Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:40:56 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:56.523Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:40:58 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:40:58.533Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:41:00 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:00.483Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:41:00 atlantis-vm atlantis[93604]: {"level":"error","ts":"2022-08-24T19:41:00.606Z","caller":"events/command_runner.go:159","msg":"Error running pre-workflow hooks exit status 1: running \"terragrunt-atlantis-config_1.14.2_linux_amd64 generate --output atlantis.yaml  --parallel=false --autoplan --automerge --ignore-dependency-blocks=true\" in \"/opt/atlantis/.atlantis/repos/iac/iac/XXX/default\": \ntime=\"2022-08-24T19:40:55Z\" level=info msg=\"Could not find an old config file. Starting from scratch\"\ntime=\"2022-08-24T19:40:55Z\" level=info msg=\"Created project for /opt/atlantis/.atlantis/repos/iac/iac/XXX/default/terragrunt.hcl\"\ntime=\"2022-08-24T19:40:55Z\" ...."}
Aug 24 19:41:00 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:00.975Z","caller":"events/project_command_builder.go:266","msg":"found no atlantis.yaml file","json":{"repo":"iac/iac","pull":"584"}}
Aug 24 19:41:00 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:00.975Z","caller":"events/project_command_builder.go:271","msg":"automatically determined that there were 0 projects modified in this pull request: []","json":{"repo":"iac/iac","pull":"584"}}
Aug 24 19:41:00 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:00.975Z","caller":"events/plan_command_runner.go:84","msg":"determined there was no project to run plan in","json":{"repo":"iac/iac","pull":"584"}}
Aug 24 19:41:01 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:01.522Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:41:03 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:03.533Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:41:05 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:05.483Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
Aug 24 19:41:06 atlantis-vm atlantis[93604]: {"level":"info","ts":"2022-08-24T19:41:06.523Z","caller":"server/server.go:864","msg":"Apply Lock: {false 0001-01-01 00:00:00 +0000 UTC }","json":{}}
@maitreya-source
Copy link
Contributor

maitreya-source commented Sep 3, 2022

I was able to replicate this issue and tried to do some root cause analysis. My understanding of the issue is as follows:

Underlying issue

Context

  • As per my understanding and debugging, this tool works as follows:
flowchart TB
    subgraph generate.go
    main-- for every hcl/json file --> createProject --> getDependencies
    end
    subgraph parse_hcl.go
    getDependencies-->parseModule
    parseModule-->decodeAsTerragruntInclude
    decodeAsTerragruntInclude--decodes only the `include` blocks using-->decodeHcl
    decodeHcl--calls to check bare include blocks-->updateBareIncludeBlock
    end
    subgraph parse_locals.go
    decodeHcl--if configuration updated by updateBareInlucdeBlock: reparse hcl using-->parseHcl
    parseModule--calls to parse hcl-->parseHcl
    end
    subgraph hclWrite_library
    updateBareIncludeBlock--calls to update bare include blocks-->ParseConfig
    end
  • During the course of execution, the tool checks if include blocks in terragrunt have a label or not. If there is no label, it calls updateBareIncludeBlock to update the bare include blocks with an empty label ("") .
  • It uses hclwrite to update the bare include blocks.
  • However, due to the bug in the hclWrite library, when the hcl objects converted from .hcl.json file are passed as input to hclWrite, it throws following error:
Error: file_name.hcl.json:1,1-2: Argument or block definition required; An argument or block definition is required here.

Possible fix/workaround?

  "include": [
    {
      "": [     "<-- Note the addition of a bare string."
        {
            "path": "${find_in_parent_folders()}"
        }
      ]
    }
  ],  

Raising a pull request with the workaround.

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

No branches or pull requests

2 participants