-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multistack-cross-stack-refference-error: bug? #3514
Comments
Update: export function setupProvidersAndStateBackend(scope: Construct, envConfig: EnvConfig, tags: Tags): [AwsProvider, ExternalProvider] {
validateEnvConfig(envConfig);
const externalProvider = new ExternalProvider(scope, "external", {});
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;
.... |
In general this should / can only happen if a token created in one stack is being used in another one. The example is too small / not complete enough to understand where the issue is coming from. There must be an implicit dependency between the two where e.g. the result from this function is used in both or sth similar. It would be helpful if you could share a complete example (ideally a minimal one). |
thx for the feedback. I found the issue, all on my end. 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. 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,
},
},
],
.... |
My own bad code, not a bug 👍 |
I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Expected Behavior
I expect stack A to be independant of stack B since no dependencies are defined.
Actual Behavior
When using multistacks. I get an error on cross-referencing. Where the top stack is apparently dependent on the second stack, even when it should not be.
update:
Both the stacks sets up their own External Provider which used External Data. This is what caused the issue. Don't know if it's expected behaviour, though.
See comment.
Steps to Reproduce
Run cdktf plan "app-dev" - gives the unable to find remote state error.
Run cdktf plan "app-api-dev" No error
Versions
language: typescript
cdktf-cli: 0.20.3
node: v20.11.0
cdktf: 0.20.2
constructs: 10.3.0
jsii: null
terraform: 1.7.2
arch: arm64
os: darwin 22.5.0
providers
external@~>2.3.2 (LOCAL)
terraform provider version: 2.3.3
@cdktf/provider-aws (PREBUILT)
terraform provider version: 5.33.0
prebuilt provider version: 19.2.0
cdktf version: ^0.20.0
Providers
┌───────────────┬──────────────────┬─────────┬────────────┬─────────────────────┬─────────────────┐
│ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────┼─────────────────┤
│ external │ 2.3.3 │ │ ~>2.3.2 │ │ │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────┼─────────────────┤
│ aws │ 5.33.0 │ ^0.20.0 │ │ @cdktf/provider-aws │ 19.2.0 │
└───────────────┴──────────────────┴─────────┴────────────┴─────────────────────┴─────────────────┘
Gist
https://gist.github.com/Dill-Dall/f8214e40fc6bba1fe71763d804d6a2e3
Possible Solutions
No response
Workarounds
Removed the External providers (the outputs were cross reffed it seems. See comment)
Anything Else?
First timer on the repo.
References
https://discuss.hashicorp.com/t/cdk-multistacking-workspace-cross-reff-error/63108
Help Wanted
Community Note
The text was updated successfully, but these errors were encountered: