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

cdktf-go: Error when following the examples in the documentation #3436

Open
1 task
nikpivkin opened this issue Jan 18, 2024 · 4 comments
Open
1 task

cdktf-go: Error when following the examples in the documentation #3436

nikpivkin opened this issue Jan 18, 2024 · 4 comments
Labels

Comments

@nikpivkin
Copy link

Description

Running the cdktf synth command with the example from the documentation returns an error:

cdktf synth
(node:49956) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

⠙  Synthesizing
[2024-01-18T16:15:58.781] [ERROR] default - # github.com/cdktf/cdktf-provider-aws-go/aws/v10/instance
../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:14:2: duplicate method Count
        ../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:36:2: other declaration of Count
../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:14:2: duplicate method SetCount
        ../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:38:2: other declar
ERROR: cdktf encountered an error while synthesizing

Synth command: go run main.go
Error:         non-zero exit code 1

Command output on stderr:

    # github.com/cdktf/cdktf-provider-aws-go/aws/v10/instance
    ../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:14:2: duplicate method Count
        ../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:36:2: other declaration of Count
    ../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:14:2: duplicate method SetCount
        ../../../go/pkg/mod/github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]/instance/instance_Instance.go:38:2: other declaration of SetCount




⠇  Synthesizing

cdktf --version
0.20.1
(node:50111) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

go version
go version go1.21.2 darwin/arm64

Links

https://developer.hashicorp.com/terraform/tutorials/cdktf/cdktf-build?in=terraform%2Fcdktf&variants=cdk-language%3Ago

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@nikpivkin nikpivkin added documentation Improvements or additions to documentation new Un-triaged issue labels Jan 18, 2024
@xiehan
Copy link
Member

xiehan commented Jan 18, 2024

I think you're running into a duplicate/combination of both #3188 and #2907.

There are two issues:

  1. The tutorial currently asks users to run the command cdktf init --template="typescript" --providers="aws@~>4.0" when it should be asking users to run the command cdktf init --template="typescript" --providers="aws" (i.e. no version constraint). The issue is that there is no prebuilt provider available for the combination of CDKTF 0.20 and AWS 4.x, we only have a prebuilt package available for the combination of CDKTF 0.20 and AWS 5.x. Since it can't find a prebuilt provider, what it's actually doing is installing locally-built bindings, yet the rest of the tutorial assumes the prebuilt provider is installed, which causes conflicts. I've submitted a PR in the tutorials repo (HashiCorp internal only so I can't link to it here) and will get it shepherded through ASAP because you're not the first to get tripped up by this.
  2. For Go specifically, the issue is that the prebuilt providers have to have the version number in the import statements, i.e.:
import (
    "github.com/cdktf/cdktf-provider-aws-go/aws/v10/instance"
    awsprovider "github.com/cdktf/cdktf-provider-aws-go/aws/v10/provider"
)

The problem is that these version numbers get incremented relatively frequently, at minimum with every new feature release of CDKTF. The tutorials were written at the time when CDKTF was at v0.13 and the corresponding AWS prebuilt provider was at v10. Now CDKTF is at v0.20 and the corresponding AWS prebuilt provider is at v19, so the import statements should instead read:

import (
    "github.com/cdktf/cdktf-provider-aws-go/aws/v19/instance"
    awsprovider "github.com/cdktf/cdktf-provider-aws-go/aws/v19/provider"
)

Because the tutorials live in an entirely different repo managed by the Education team and not by us, we don't have any way to automate updating these when we do releases, unfortunately, which is why there's this regression.

In any case, I've also included updating these to v19 in my PR on the tutorial, which should address the issue for anyone trying the tutorial today, but I can't guarantee this problem won't reoccur in the future. For Go users, we may have no choice but to add a note of some kind to double-check the version numbers in the import statements because they may become outdated in the future.

@nikpivkin
Copy link
Author

@xiehan Thank you for such a detailed response!

I tried to initialise the project without specifying the aws provider version, but got an error:

cdktf init --template="go" --providers="aws" --local
...
[2024-01-18T21:23:33.016] [INFO] default - Checking whether pre-built provider exists for the following constraints:
  provider: aws
  version : latest
  language: go
  cdktf   : 0.20.1

[2024-01-18T21:23:36.472] [INFO] default - Found pre-built provider.
Adding package github.com/cdktf/cdktf-provider-aws-go/aws @ 19.1.1
[2024-01-18T21:24:25.965] [ERROR] default - go: downloading github.com/cdktf/cdktf-provider-aws-go/aws/v19 v19.1.1

go: downloading github.com/cdktf/cdktf-provider-aws-go/aws/v19 v19.1.1
[2024-01-18T21:24:36.972] [ERROR] default - go: github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]: create zip: module source tree too large (max size is 524288000 bytes)

go: github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]: create zip: module source tree too large (max size is 524288000 bytes)
non-zero exit code 1
Error: non-zero exit code 1
    at ChildProcess.<anonymous> (/opt/homebrew/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:99:8179)
    at Object.onceWrapper (node:events:634:26)
    at ChildProcess.emit (node:events:519:28)
    at ChildProcess.emit (node:domain:488:12)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Socket.emit (node:domain:488:12)
    at Pipe.<anonymous> (node:net:337:12)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17)
Collecting Debug Information...
/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

Error: non-zero exit code 1
    at ChildProcess.<anonymous> (/opt/homebrew/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:99:8179)
    at Object.onceWrapper (node:events:634:26)
    at ChildProcess.emit (node:events:519:28)
    at ChildProcess.emit (node:domain:488:12)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Socket.emit (node:domain:488:12)
    at Pipe.<anonymous> (node:net:337:12)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {
  stderr: 'go: downloading github.com/cdktf/cdktf-provider-aws-go/aws/v19 v19.1.1\n' +
    'go: github.com/cdktf/cdktf-provider-aws-go/aws/[email protected]: create zip: module source tree too large (max size is 524288000 bytes)\n'
}

I found a related issue, but it's closed as solved.

@xiehan
Copy link
Member

xiehan commented Jan 18, 2024

It's closed as solved because it will be fixed the next time the AWS provider does a release, which will trigger a new release of our prebuilt provider for AWS. The AWS provider does weekly releases on Thursday nights, so a new version should be out and this should be resolved by tomorrow morning.

@ansgarm
Copy link
Member

ansgarm commented Jan 19, 2024

Hi @nikpivkin 👋 There's a new release out now of the pre-built provider that fixes this. I just checked and was able to install the latest package locally 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants