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

Upgrading to CDKTF 0.16.0 or 0.16.1 breaks random provider in go #2856

Closed
eahrend opened this issue May 3, 2023 · 15 comments
Closed

Upgrading to CDKTF 0.16.0 or 0.16.1 breaks random provider in go #2856

eahrend opened this issue May 3, 2023 · 15 comments
Labels
bug Something isn't working pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager stale An issue or pull request that has not been updated in a very long time waiting-on-answer

Comments

@eahrend
Copy link

eahrend commented May 3, 2023

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

cdktf & Language Versions

cdktf.json

{
  "language": "go",
  "app": "go run main.go",
  "codeMakerOutput": "generated",
  "projectId": "#####",
  "sendCrashReports": "true",
  "terraformProviders": [
    {
      "name": "google",
      "source": "hashicorp/google",
      "version": "~> 4.51.0"
    },
    {
      "name": "googleworkspace",
      "source": "hashicorp/googleworkspace",
      "version": "~> 0.7.0"
    }
  ],
  "terraformModules": [],
  "context": {
    "excludeStackIdFromLogicalIds": "true",
    "allowSepCharsInLogicalIds": "true"
  }
}

go.mod

go 1.20

require github.com/aws/constructs-go/constructs/v10 v10.1.236

require (
	github.com/aws/jsii-runtime-go v1.79.0
	github.com/hashicorp/cdktf-provider-random-go/random v1.0.2
	github.com/hashicorp/terraform-cdk-go/cdktf v0.16.0
	github.com/smartystreets/goconvey v1.7.2
	gopkg.in/yaml.v3 v3.0.1
)

require (
	github.com/Masterminds/semver/v3 v3.2.0 // indirect
	github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
	github.com/jtolds/gls v4.20.0+incompatible // indirect
	github.com/mattn/go-isatty v0.0.17 // indirect
	github.com/smartystreets/assertions v1.2.0 // indirect
	github.com/yuin/goldmark v1.4.13 // indirect
	golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
	golang.org/x/mod v0.9.0 // indirect
	golang.org/x/sys v0.6.0 // indirect
	golang.org/x/tools v0.7.0 // indirect
)

Other stuff:

go version go1.20.3 darwin/arm64
node version: v16.19.0

Affected Provider / Resource(s)

github.com/hashicorp/cdktf-provider-random-go/random
cdktf version 0.16.0 and 0.16.1

Debug Output

https://gist.github.com/eahrend/794c87066cc6ad36901bbf8ac4024e8b

Expected Behavior

CDKTF should synth and apply as usual

Actual Behavior

Errors out with debug in gist

Steps to Reproduce

Start with cdktf 0.15.3, create a resource that uses the random provider like so:

func createRandomSuffix(s cdktf.TerraformStack, id string, suffixLength int, specialCharacters, uppercaseAllowed bool) random.StringResource {
	return random.NewStringResource(s, jsii.String(fmt.Sprintf("%s-random-id", id)), &random.StringResourceConfig{
		Length:  jsii.Number(float64(suffixLength)),
		Special: jsii.Bool(specialCharacters),
		Upper:   jsii.Bool(uppercaseAllowed),
	})
}

run cdktf apply --auto-approve

Upgrade to cdktf versions 0.16.0 or 0.16.1

re-run cdktf apply --auto-approve

Important Factoids

N/A

References

N/A

@eahrend eahrend added bug Something isn't working new Un-triaged issue pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager labels May 3, 2023
@ansgarm
Copy link
Member

ansgarm commented May 4, 2023

Hi @eahrend 👋

From your debug log it looks like you are using v1.0.2 of the pre-built random provider. The current version is 7.0.0 – Could you try upgrading to that version?

@ansgarm ansgarm added waiting-on-answer and removed new Un-triaged issue labels May 4, 2023
@eahrend
Copy link
Author

eahrend commented May 4, 2023

Hey @ansgarm thanks for the quick response. I tried upgrading to the random v7 provider and had some issues with upgrading to it in go, I could use some guidance here because I've had the same issue a couple times.

Going off of the readme file, it says to import the random provider as github.com/cdktf/cdktf-provider-random-go, however if I try to use that in my code like this:

package modules

import (
	"fmt"
	"github.com/aws/jsii-runtime-go"

	//"github.com/hashicorp/cdktf-provider-random-go/random"
	random "github.com/cdktf/cdktf-provider-random-go/random/v7"
	"github.com/hashicorp/terraform-cdk-go/cdktf"
)

func createRandomSuffix(s cdktf.TerraformStack, id string, suffixLength int, specialCharacters, uppercaseAllowed bool) random.StringResource {
	return random.NewStringResource(s, jsii.String(fmt.Sprintf("%s-random-id", id)), &random.StringResourceConfig{
		Length:  jsii.Number(float64(suffixLength)),
		Special: jsii.Bool(specialCharacters),
		Upper:   jsii.Bool(uppercaseAllowed),
	})
}

Then go mod tidy returns the following error:

go: finding module for package github.com/cdktf/cdktf-provider-random-go/random/v7
eahrend/tf/src/modules imports
	github.com/cdktf/cdktf-provider-random-go/random/v7: module github.com/cdktf/cdktf-provider-random-go/random/v7@latest found (v7.0.0), but does not contain package github.com/cdktf/cdktf-provider-random-go/random/v7

So then I try to trim the /v7 from the import

package modules

import (
	"fmt"
	"github.com/aws/jsii-runtime-go"

	//"github.com/hashicorp/cdktf-provider-random-go/random"
	"github.com/cdktf/cdktf-provider-random-go/random"
	"github.com/hashicorp/terraform-cdk-go/cdktf"
)

func createRandomSuffix(s cdktf.TerraformStack, id string, suffixLength int, specialCharacters, uppercaseAllowed bool) random.StringResource {
	return random.NewStringResource(s, jsii.String(fmt.Sprintf("%s-random-id", id)), &random.StringResourceConfig{
		Length:  jsii.Number(float64(suffixLength)),
		Special: jsii.Bool(specialCharacters),
		Upper:   jsii.Bool(uppercaseAllowed),
	})
}

And then go mod tidy returns this error:

go: finding module for package github.com/cdktf/cdktf-provider-random-go/random
go: found github.com/cdktf/cdktf-provider-random-go/random in github.com/cdktf/cdktf-provider-random-go/random v1.0.2
go: eahrend/tf/src/modules imports
	github.com/cdktf/cdktf-provider-random-go/random: github.com/cdktf/cdktf-provider-random-go/[email protected]: parsing go.mod:
	module declares its path as: github.com/hashicorp/cdktf-provider-random-go/random
	        but was required as: github.com/cdktf/cdktf-provider-random-go/random

Then I try to update my go.mod file to use v7 of the random provider

module eahrend/tf

go 1.20

require github.com/aws/constructs-go/constructs/v10 v10.1.236

require (
	github.com/aws/jsii-runtime-go v1.79.0
	//github.com/hashicorp/cdktf-provider-random-go/random v1.0.2
	github.com/cdktf/cdktf-provider-random-go/random v7
	github.com/hashicorp/terraform-cdk-go/cdktf v0.15.3
	github.com/smartystreets/goconvey v1.7.2
	gopkg.in/yaml.v3 v3.0.1
)

require (
	github.com/Masterminds/semver/v3 v3.2.0 // indirect
	github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
	github.com/jtolds/gls v4.20.0+incompatible // indirect
	github.com/mattn/go-isatty v0.0.17 // indirect
	github.com/smartystreets/assertions v1.2.0 // indirect
	github.com/yuin/goldmark v1.4.13 // indirect
	golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
	golang.org/x/mod v0.9.0 // indirect
	golang.org/x/sys v0.6.0 // indirect
	golang.org/x/tools v0.7.0 // indirect
)

And this returns the following:

go: errors parsing go.mod:
#####/go.mod:10:2: no matching versions for query "v7"

I've tried a couple other permutations as well, but nothing seems to allow me to import version 7 of the random provider.

@eahrend
Copy link
Author

eahrend commented May 12, 2023

@ansgarm any thoughts on how to proceed on this?

@eahrend
Copy link
Author

eahrend commented May 15, 2023

smh, just read the notice #2146, I'll try to follow this guideline to use the provided random provider and see if it works tomorrow.

@moonlord899
Copy link

@eahrend not sure if worked for you, i didn't have any luck with this. Same setup as you, only using go 1.20.4

@eahrend
Copy link
Author

eahrend commented May 17, 2023

I haven't had the chance to try to re-upgrade to 0.16.X @moonord89 , I'll let you know if #2146 helps once I do, but due to the nature of $work, other things have been taking my time lol.

@moonlord899
Copy link

@ansgarm this doesn't seem to work. If i try adding the package give me this error:

github.com/cdktf/cdktf-provider-random-go/random/v7: module github.com/cdktf/cdktf-provider-random-go/random/v7@latest found (v7.0.0), but does not contain package github.com/cdktf/cdktf-provider-random-go/random/v7

Any thoughts on this?

@moonlord899
Copy link

I see that a new version of the random provider has been published. Tried with this one as well but still got the same result:

github.com/cdktf/cdktf-provider-random-go/random/v7: module github.com/cdktf/cdktf-provider-random-go/random/v7@latest found (v7.0.1), but does not contain package github.com/cdktf/cdktf-provider-random-go/random/v7

@eahrend
Copy link
Author

eahrend commented Jun 27, 2023

@ansgarm , I hate to bother you on this, but we're trying to update cdktf to 0.17 from 0.15 and we're still getting this issue.

@eahrend
Copy link
Author

eahrend commented Jun 30, 2023

Nvm, got it working @moonord89 in addition to the things #2146 requires you to do, you need to import the specific resource as a sub path.

Rather than

import (
  random "github.com/cdktf/cdktf-provider-random-go/random/v8"
)

You need to specify that you're importing the stringresource in your import path.

import (
 random "github.com/cdktf/cdktf-provider-random-go/random/v8/stringresource"
)

Let me know if this fixes it for you, because this fixed it for me on most of my stuff.

WRT the go.mod file, this is what's working for me.

module eahrend/tf

go 1.20

require (
	github.com/aws/constructs-go/constructs/v10 v10.2.52
	github.com/aws/jsii-runtime-go v1.84.0
	github.com/cdktf/cdktf-provider-google-go/google/v8 v8.0.2
	github.com/cdktf/cdktf-provider-helm-go/helm/v7 v7.0.0
	github.com/cdktf/cdktf-provider-random-go/random/v8 v8.0.0
)

@moonlord899
Copy link

@eahrend yes it did, thanks a lot for the info, it really helped. @ansgarm maybe this can be added to the documentation for future reference. I can see how this can cause issues when coming from v1 or v2 of the random provider.

@eahrend
Copy link
Author

eahrend commented Jul 7, 2023

@moonord89 so interesting thing, I noticed that some providers will actually have this documentation already, if you check out the provider docs on the kubernetes provider it's all there
https://github.com/cdktf/cdktf-provider-kubernetes/blob/main/docs/manifest.go.md

It may be a repo-by-repo thing we have to bug them to update, or if there is a template for pre-built providers that hashicorp has maybe it now autogenerates these?

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

Hi there! 👋 We haven't heard from you in 15 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.

@github-actions github-actions bot added the stale An issue or pull request that has not been updated in a very long time label Aug 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

I'm closing this issue because we haven't heard back in 45 days. ⌛️ If you still need help, feel free to comment or reopen the issue!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2023

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've 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 Oct 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager stale An issue or pull request that has not been updated in a very long time waiting-on-answer
Projects
None yet
Development

No branches or pull requests

3 participants