Go tutorial: cannot install kreuzwerker/docker package

Issue

Following steps Install CDK for Terraform and Run a Quick Start Demo | Terraform - HashiCorp Learn

Tried to run cdktf depoy, I got:

[2022-09-21T00:31:38.341] [ERROR] default - main.go:8:5: no required module provides package cdk.tf/go/stack/generated/kreuzwerker/docker; to add it:
ERROR: cdktf encountered an error while synthesizing

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

Command output on stderr:

    main.go:8:5: no required module provides package cdk.tf/go/stack/generated/kreuzwerker/docker; to add it:
    	go get cdk.tf/go/stack/generated/kreuzwerker/docker

then tried to install kreuzwerker/docker package:

go: unrecognized import path "cdk.tf/go/stack/generated/kreuzwerker/docker": reading https://cdk.tf/go/stack/generated/kreuzwerker/docker?go-get=1: 404 Not Found
	server response: The page could not be found

a simple go get gives almost same response:

cdk.tf/go/stack imports
	cdk.tf/go/stack/generated/kreuzwerker/docker: cannot find module providing package cdk.tf/go/stack/generated/kreuzwerker/docker

Environment

$ go version
go version go1.19.1 darwin/amd64

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="~/Library/Caches/go-build"
GOENV="~/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="~/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="~/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.19.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.19.1/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="${PWD}/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/var/folders/5p/hf0sb08n7dd1pry4464lxjb40000gn/T/go-build3786579222=/tmp/go-build -gno-record-gcc-switches -fno-common"

Workaround

This fixed by replacing cdk.tf/go/stack/generated/kreuzwerker/docker with github.com/hashicorp/cdktf-provider-docker-go/docker/v2 in main.go


Is this fix correct? Or am I missing something?

Hi @triggerwoods91 :wave:

Just to make sure: Did you run cdktf get to generate the bindings (that are going to go into the generated directory?
What is your module name (at the top in the go.mod file)?

– Ansgar

Hi @ansgarm !

Just launched cdktf get, I got the following:

[2022-09-21T21:46:48.857] [WARN] default - WARNING: No providers or modules found in "cdktf.json" config file, therefore cdktf get does nothing.

I guess the cdktf provider add kreuzwerker/docker command should add provider into cdktf.json, but the latest still do not have any providers:

{
  "language": "go",
  "app": "go run main.go",
  "codeMakerOutput": "generated",
  "projectId": "005ec15d-a690-43bc-adbe-356e9bf0ad07",
  "sendCrashReports": "false",
  "terraformProviders": [],
  "terraformModules": [],
  "context": {
    "excludeStackIdFromLogicalIds": "true",
    "allowSepCharsInLogicalIds": "true"
  }
}

What is your module name (at the top in the go.mod file)?

Module name is cdk.tf/go/stack

go.mod contents:

module cdk.tf/go/stack

go 1.16

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

require (
	github.com/hashicorp/cdktf-provider-docker-go/docker/v2 v2.0.65 // indirect
	github.com/hashicorp/terraform-cdk-go/cdktf v0.12.2
)

So I added kreuzwerker/docker to cdktf.json manually and then run cdktf get:

Generated go constructs in the output directory: generated

The generated code depends on jsii-runtime-go. If you haven't yet installed it, you can run go mod tidy to automatically
install it.

Then cdktf deploy:

⠹  Synthesizing
[2022-09-21T22:28:10.559] [ERROR] default - main.go:8:5: package cdk.tf/go/stack/generated/kreuzwerker/docker imports github.com/aws/jsii-runtime-go/runtime from implicitly required module; to add missing requirements, run:
	go get github.com/aws/jsii-runtime-go@v1.67.0
generated/kreuzwerker/docker/docker_Config.go:5:2: package cdk.tf/go/stack/generated/kreuzwerker/docker/jsii imports github.com/aws/jsii-runtime-go/runtime from implicitly required module; to add missing requirements, run:
ERROR: cdktf encountered an error while synthesizing

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

Command output on stderr:

    main.go:8:5: package cdk.tf/go/stack/generated/kreuzwerker/docker imports github.com/aws/jsii-runtime-go/runtime from implicitly required module; to add missing requirements, run:
    	go get github.com/aws/jsii-runtime-go@v1.67.0
    generated/kreuzwerker/docker/docker_Config.go:5:2: package cdk.tf/go/stack/generated/kreuzwerker/docker/jsii imports github.com/aws/jsii-runtime-go/runtime from implicitly required module; to add missing requirements, run:
    	go get github.com/aws/jsii-runtime-go@v1.67.0

so then I launched go mod tidy and then finally fixed cdktf deploy:

learn-cdktf-docker  Initializing the backend...
learn-cdktf-docker
                    Successfully configured the backend "local"! Terraform will automatically
                    use this backend unless the backend configuration changes.
learn-cdktf-docker  Initializing provider plugins...
learn-cdktf-docker  - Finding kreuzwerker/docker versions matching "2.22.0"...
learn-cdktf-docker  - Using kreuzwerker/docker v2.22.0 from the shared cache directory
learn-cdktf-docker  Terraform has created a lock file .terraform.lock.hcl to record the provider
                    selections it made above. Include this file in your version control repository
                    so that Terraform can guarantee to make the same selections by default when
                    you run "terraform init" in the future.
learn-cdktf-docker  Terraform has been successfully initialized!
...

Thanks for guiding. Go guide possible needs to have missing steps such as adding provider name to cdktf.json, running cdktf get, compiling by go mod ...