Artifactory remote backend with cdktf

Hi everyone,

With Terraform, it is possible to specify in a .tf file a remote backend that resides in artifactory :

image

Doing terraform init will initialize the remote backend in artifactory :
image

How can I do the same with cdktf ?

As far as I know, there is no equivalent of this in cdktf (well there is a CloudBackend block, but it’s for Terraform Cloud only)

Even if I terraform init before with a .tf file it doesn’t matter because after with cdktf synth or deploy, the stack get built in a new folder cdktf.out//stacks/MyStackName with a local provider in the json file.

Any help would be appreciated.

Regards,

Hi @francois.munger :wave:

The Artifactory backend was deprecated in Terraform, which is why CDKTF stopped supporting it as well. The Terraform 1.3 upgrade guide has docs on how to migrate: Upgrading to Terraform v1.3 | Terraform | HashiCorp Developer

Hi @ansgarm :wave:

From JFrog Artifactory 7.38.4 or later, Artifactory has support for the state storage protocol used by Terraform’s remote backend, using a special repository type called a Terraform Backend Repository.

In my previous post i’m using Terraform 1.3.7
image

I’m aldready using the remote backend as stated in the link you sent.

(main.tf)
image

So no problem here, the backend works fine - it stores the state in artifactory if I terraform init and then terraform apply with a .tf file containing the above backend with Terraform 1.3.7

I want to reproduce the same behavior (having a backend in artifactory) using cdktf, not Terrraform.
In other words, how do I translate the above in my main.ts file in cdktf ?

Cheers,
Francois

1 Like

Got it by looking at the API reference :

To use a remote backend hosted in Artifactory with cdktf, use this block of code in your main.ts (or other depending on your language) :

const artifactoryRemoteBackendConfig: RemoteBackendConfig = { 
  organization: "terraform-backend",
  workspaces: new NamedRemoteWorkspace("your_project_aa"),
  hostname: "xoxoxoxoxoxo.jfrog.io"
 }
new RemoteBackend(this, artifactoryRemoteBackendConfig);

assuming you have a remote backend in Artifactory :

Hope it helps someone in the future…

1 Like

Glad that you found it!