RemoteBackend with Python

What is the correct way to define a RemoteBackend for cdk with Python? I tried the following based on the blog example, but it didn’t work.

from cdktf import App, TerraformStack, TerraformOutput, RemoteBackend
stack = MyStack(app, "hello-terraform")
    hostname= "",
    workspaces= {"name": 'hello-terraform'}

Thanks for raising this question. workspaces expects an object of a class which implements the IRemoteWorkspace interface. That would be either the class NamedRemoteWorkspace or PrefixedRemoteWorkspaces from the cdktf package.

A working RemoteBackend would look like this:

    hostname= "",

@jsteinich do you remember why the workspace values are wrapped in classes rather than an interface?

1 Like

Thanks @skorfmann!

Your example above with the following line worked for me.
from cdktf import RemoteBackend, NamedRemoteWorkspace

Was missing NamedRemoteWorkspace earlier.

I believe that’s trying to indicate that name and prefix are conflicting options.
Even if it were an interface, workspaces= {"name": 'hello-terraform'} might not work due to some limitations in jsii

@skorfmann - hello, sir. How can I get this working with TypeScript?

I’m trying to use Artifactory as a remote backend. I am aware that the Artifactory provider is deprecated, but according to Artifactory documentation, this is still a valid place for storing statefiles since it does not rely on the provider itself.

I’m currently doing:

import { RemoteBackend, NamedRemoteWorkspace } from "cdktf";

export class TestStack extends TerraformStack {
   new RemoteBackend(this, {
     hostname: "<insert_url>",
     organization: "<insert_artifactory_repo_name>", 
     workspace: new NamedRemoteWorkspace("my-test-workspace-name"),

The following code appears to be correct syntax (at least vscode doesn’t complain). I tried doing name: "my-test-workspace-name" but that threw a syntax error of Cannot find name ‘name’. Did you mean the static member ‘’?ts(2662) .

With the code snippet above, I am able to run cdktf synth successfully. When I get to cdktf deploy I get an error saying Unexpected token } in JSON at position 178. The cdktf.out/stacks/ directory is empty outside of having a file.

If I comment out the new RemoteBackend codeblock and replace it with either localBackend or S3Backend, the rest of my code works just fine.

Any help would be greatly appreciated.

[jon@laptop]$ cdktf --version
[jon@laptop]$ grep 'cdktf' package.json
"@cdktf/aws-cdk": "^0.5.2"
"@cdktf/provider-aws": "^5.0.52"
"cdktf": "^0.9.4"

Thank you in advance for any help!.

Looks like the property is called workspaces rather than workspace. If that was just a typo here, can you please show a snipped (can be obfuscated) of your file?