CDK - multistacking - workspace cross reff error

Cheers. First timer here.
Posted it as a possible bug on

Getting error when multistacking in a CDK project.

I don´t understand why a cross reff is set up. Also I´m not using workspace.
The stacks should not reff each other. See update for resolution. Which I don’t understand.

cdktf plan “app-dev”


Error : 
⠋  Processing
[2024-02-24T01:36:36.851] [ERROR] default - ╷
│ Error: Unable to find remote state
│
│   with data.terraform_remote_state.cross-stack-reference-input-app-dev,
│   on cdk.tf.json line 64, in data.terraform_remote_state.cross-stack-reference-input-cargostream-gateway-dev:
│   64:         "workspace": "${terraform.workspace}"
│
│ No stored state was found for the given workspace in the given backend.
cargostream-dev  ╷
                 │ Error: Unable to find remote state
                 │
                 │   with data.terraform_remote_state.cross-stack-reference-input-cargostream-gateway-dev,
                 │   on cdk.tf.json line 64, in data.terraform_remote_state.cross-stack-reference-input-cargostream-gateway-dev:
                 │   64:         "workspace": "${terraform.workspace}"
                 │
                 │ No stored state was found for the given workspace in the given backend.

ts - code 
```class ApiStack extends TerraformStack {
  constructor(scope: Construct, id: string, envConfig: EnvConfig) {
    super(scope, id);
    setupProvidersAndStateBackend(this, envConfig, tags);
    new ApiGateway(this, "gateway");
  }
}



const app = new App();
// statekeys are backed into to config.
//  domain/app/env-dev.tfstate
//  commerce/cargostream/cargostream-dev.tfstate
new cargostream(app, "app-dev", devConfig);
//  domain/app/env-api-dev.tfstate
new ApiStack(app, "app-api-dev", devApiConfig);

app.synth();

cdk.tf.json


    "terraform_remote_state": {
      "cross-stack-reference-input-cargostream-gateway-dev": {
        "backend": "s3",
        "config": {
          "assume_role": {
            "role_arn": "arn:aws:iam::*:role/DiPlatform"
          },
          "bucket": "terraform-state-dev-*",
          "encrypt": true,
          "key": "commerce/    "terraform_remote_state": {
      "cross-stack-reference-input-app-api-dev": {
        "backend": "s3",
        "config": {
          "assume_role": {
            "role_arn": "arn:aws:iam::*:role/DiPlatform"
          },
          "bucket": "terraform-state-dev-*",
          "encrypt": true,
          "key":  domain/app-api/env-dev.tfstate",
          "region": "eu-north-1"
        },
        "workspace": "${terraform.workspace}"
      }-api/env-dev.tfstate",
          "region": "eu-north-1"
        },
        "workspace": "${terraform.workspace}"
      }

Update:
I removed the ExternalProvider from provider setup. The provider generated two outputs.
I don´t understand why this created the cross stack error though

        const terraformVersion = new DataExternal(scope, "terraform_version", {
            program: ["bash", "-c", "echo '{\"version\": \"\'$(terraform version | grep 'Terraform v' | cut -d ' ' -f 2)\'\"}'"],
        });
        const cdktfVersion = new DataExternal(scope, "cdktf_version", {
            program: ["bash", "-c", "echo '{\"version\": \"\'$(cdktf --version)\'\"}'"],
        });

        tags.terraform_version = terraformVersion.result.lookup("version") as string;
        tags.cdkf_version = cdktfVersion.result.lookup("version") as string;

My github answer:

thx for the feedback. I found the issue. The reason was because I changed the “tags” constant. Meaning it made a cross stack reff for when multiple stacks used the same “tags” const.
Fixed it by creating a copy instead.

export function setupProvidersAndStateBackend(scope: Construct, envConfig: EnvConfig, tags: Tags, alignWithLegacy: boolean = false): ProviderStateConfig {
validateEnvConfig(envConfig);

const configGeneratedTags: { [key: string]: any } = {};

const externalProvider = new ExternalProvider(scope, "external", {});
if (alignWithLegacy == false) {


    const terraformVersion = new DataExternal(scope, "terraform_version", {
        program: ["bash", "-c", "echo '{\"version\": \"\'$(terraform version | grep 'Terraform v' | cut -d ' ' -f 2)\'\"}'"],

    });
    const cdktfVersion = new DataExternal(scope, "cdktf_version", {
        program: ["bash", "-c", "echo '{\"version\": \"\'$(cdktf --version)\'\"}'"],
    });

    configGeneratedTags['terraform_version'] = terraformVersion.result.lookup("version");
    configGeneratedTags['cdktf_version'] = cdktfVersion.result.lookup("version");

}

const awsProvider = new AwsProvider(scope, "AWS", {
    region: envConfig.region || "eu-north-1",
    defaultTags: [
        {
            tags: {
                ...tags,
                ...configGeneratedTags,
                realm: envConfig.env,
            },
        },
    ],