I’m attempting to run cdktf get in my Java environment, but since I’ve upgraded to version 0.13.0, I get the following error
❯ cdktf get
Usage Error: The minor version of the library (0.12.3) and the CLI (0.13.0) are different. Please update the library to the same minor version and regenerate your provider bindings with 'cdktf get' and update your prebuilt providers.
It’s possible that my pom.xml isn’t working correctly. When I run mvn install -up -X, I see this in the debut logs
[DEBUG] Could not find metadata com.hashicorp:cdktf/maven-metadata.xml in local (/Users/zach/.m2/repository)
[DEBUG] Skipped remote request for com.hashicorp:cdktf/maven-metadata.xml, locally cached metadata up-to-date
...
[DEBUG] com.hashicorp:cdktf:jar:0.12.3:compile
...
It does seem like my pom.xml and my cdktf.json aren’t being respected, though, because my plugins are just using the latest versions, not what’s in cdktf.json. I’ll post that too in case it’s important
❯ cdktf get
Usage Error: The minor version of the library (0.12.3) and the CLI (0.13.0) are different. Please update the library to the same minor version and regenerate your provider bindings with 'cdktf get' and update your prebuilt providers.
Ah sorry, my bad. So I looked in the CLI code and we consult mvn dependency:list to understand which cdktf version is installed on the library side. It seems like the output indicates 0.12.3 as installed cdktf version (please check), so maybe running mvn install will help? Not much of a Java expert so I might have the wrong name in mind here. You can disable this check by setting the environment variable DISABLE_VERSION_CHECK=1
That was helpful. Thanks for the tricks. I did a bit more debugging with this new information and was able to get it to work. I think the end issue was a difference in dependency requirements on a couple of my cdktf providers
I updated these two as well
Ah I see, since you had a few providers in your cdktf.json I haven’t thought that you might also use pre-built ones. You might be able to remove these two providers from your cdktf.json then, that should make cdktf get faster.
So the issue I’m having with cdktf get and pom.xml is that cdktf get always creates an imports and resources directory which contain the entirety of the prebuilt providers downloaded on my machine. Then cdktf synth tries to synthesize the providers, which causes errors. Thoughts there?
cdktf get generates bindings for providers locally, it can be used instead of the pre-built providers you are using. It is expected to create those bindings in the folders you mentioned. In general you would normally only use either the pre-built version that is installed through maven or the generated local one, but not both.
Ah I see. That’s just my misunderstanding then. To make sure I’m understanding right, there are two files where providers can be set. pom.xml and cdktf.json. If I set the provider using cdktf provider add or by adding it to cdktf.json, TF will use the pre-built provider when synthesizing? However, if I set the providers in pom.xml, it will be installed with cdktf get and generate the local bindings? So if I don’t set it in pom.xml, I won’t download the providers when I run cdktf get?
You add the name of the provider in the pom.xml and install it through maven (they are loaded on mvn compile)
Generating provider bindings
All providers and modules are supported
You add the name (the same full name and version syntax you use in Terraform) of the provider / module into your cdktf.json file and run cdktf get. This creates local folder (that should ideally not be in version control) with the bindings you need for the provider / module
The cdktf provider add command takes one or multiple provider names (with version constraints) and checks if there is a pre-built provider in place with these constraints. If yes it installs the provider it found, if not it falls back to the cdktf.json and runs cdktf get for you.