Skip to content

Hard to reach terraform_wrapper: false from CDKTF error #338

@LumaKernel

Description

@LumaKernel

Situation

  • Run cdktf get in GitHub Actions
    • It's working in local, but show errors like following.
> cdktf get

SyntaxError: Unexpected token c in JSON at position 1
    at JSON.parse (<anonymous>)
    at /home/runner/work/<REDACTED>/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:94:49074
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async KM (/home/runner/work/<REDACTED>/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:45:1221)
    at async c$ (/home/runner/work/<REDACTED>/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:94:48908)
    at async _$.generateTypescriptProvider (/home/runner/work/<REDACTED>/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:96:6837)
    at async _$.generateTypescript (/home/runner/work/<REDACTED>/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:96:8841)
    at async Promise.all (index 3)
    at async _$.generate (/home/runner/work/<REDACTED>/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:99:372)
    at async qDe (/home/runner/work/<REDACTED>/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:176:8163)
⠹ downloading and generating modules and providers...
SyntaxError: Unexpected token c in JSON at position 1
npm ERR! Lifecycle script `get` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: <REDACTED> 
npm ERR!   at location: /home/runner/work/<REDACTED>

Here is no hint to know when it gets c character while it's parsing JSON.

I checked handlers.js:94:49074 and I figured out that the original code is this.

https://github.com/hashicorp/terraform-cdk/blob/49a7072948a115ef20ea5ebe62f8d04117de81c9/packages/%40cdktf/provider-generator/lib/get/generator/provider-schema.ts#L309-L313

    providerSchema = JSON.parse(
      await exec(terraformBinaryName, ["providers", "schema", "-json"], {
        cwd: outdir,
      })
    ) as ProviderSchema;

Then I tried terraform providers schema -json in GitHub Actions and get it's wrapping the CLI.

$ terraform providers schema -json
[command]/home/runner/work/_temp/e3701105-a0d4-426d-80e2-575b823dd917/terraform-bin providers schema -json
{"format_version":"1.0"}
::debug::Terraform exited with code 0.
::debug::stdout: {"format_version":"1.0"}%0A
::debug::stderr:
::debug::exitcode: 0
::set-output name=stdout::{"format_version":"1.0"}%0A
::set-output name=stderr::
::set-output name=exitcode::0

Now we get the character c is coming from [command]

Solution candidates

I have no right solution for this, but have ideas.

  • Defaulting to terraform_wrapper: false
    • simple
  • Having 2 binaries, one is terraform which is not wrapped, and one another terraform-wrapped which is wrapped
  • Make the ability to force disabling wrapping even if wrapped like with environment var like NO_GHA_TERRAFORM_WRAP=1, and setting this from CDKTF side to prevent this potential unrecognizable barrier for CDKTF starters.

I like third solution. How about that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions