Skip to content
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

Testing: fullSynth generated incorrect stack is having incoming cross-stack references #3538

Open
1 task
Hi-Fi opened this issue Mar 6, 2024 · 0 comments
Open
1 task
Labels
bug/has-workaround A bug with a workaround (may not be elegant) bug Something isn't working priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. testing

Comments

@Hi-Fi
Copy link

Hi-Fi commented Mar 6, 2024

Expected Behavior

When stack generated has incoming stack references, I would expect those to be correct even stack is generated with fullSynth (to be utilized with toBeValidTerraform)

Actual Behavior

Error:

"severity": "error",
"summary": "Reference to undeclared resource",
"detail": "A managed resource \"azurerm_container_registry\" \"acr_containerRegistry_94E5FAA8\" has not been declared in the root module.",

Steps to Reproduce

  1. Create 2 stacks with cross-stack reference
  2. Generate testStack that uses the value from other stack
  3. Create tests with expect(fullSynth(testStack)).toBeValidTerraform();

Versions

language: typescript
cdktf-cli: 0.20.3
node: v18.17.1
cdktf: 0.20.3
constructs: 10.3.0
jsii: null
terraform: 1.7.4
arch: x64
os: win32 10.0.19044

Providers

┌───────────────┬──────────────────┬─────────┬────────────┬─────────────────────────┬─────────────────┐
│ Provider Name │ Provider Version │ CDKTF   │ Constraint │ Package Name            │ Package Version │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤
│ azure/azapi   │ 1.12.1           │         │ ~> 1.12    │                         │                 │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤
│ azurerm       │ 3.92.0           │ ^0.20.0 │            │ @cdktf/provider-azurerm │ 12.6.0          │
└───────────────┴──────────────────┴─────────┴────────────┴─────────────────────────┴─────────────────┘

Gist

No response

Possible Solutions

Synth should somehow be able to generate references from the code, as I at least expect fullSynth to be ~same than with CLI synth.

It could allow also multiple stacks to be done on one go, and that way to understand that there are references

Workarounds

Make full synth and check those from file system:

const app = Testing.app();
const stack = generateStack(app);
app.synth();
expect(app.outdir).toBeValidTerraform();

Anything Else?

In tests fullSynth currently generates "empty" manifest:

{
  "version": "stubbed",
  "stacks": {
    "aca": {
      "name": "aca",
      "constructPath": "aca",
      "workingDirectory": "stacks\\aca",
      "synthesizedStackPath": "stacks\\aca\\cdk.tf.json",
      "stackMetadataPath": "stacks\\aca\\metadata.json",
      "annotations": [],
      "dependencies": []
    }
  }
}

And refers to that specific value like:

        "scope": "${azurerm_container_registry.acr_containerRegistry_94E5FAA8.id}"

Compared to normal synth, manifest has 2 stacks

{
  "version": "0.20.3",
  "stacks": {
    "acr": {
      "name": "acr",
      "constructPath": "acr",
      "workingDirectory": "stacks\\acr",
      "synthesizedStackPath": "stacks\\acr\\cdk.tf.json",
      "stackMetadataPath": "stacks\\acr\\metadata.json",
      "annotations": [],
      "dependencies": []
    },
    "aca": {
      "name": "aca",
      "constructPath": "aca",
      "workingDirectory": "stacks\\aca",
      "synthesizedStackPath": "stacks\\aca\\cdk.tf.json",
      "stackMetadataPath": "stacks\\aca\\metadata.json",
      "annotations": [],
      "dependencies": [
        "acr"
      ]
    }
  }
} 

And reference to other stack value looks like:

"scope": "${data.terraform_remote_state.cross-stack-reference-input-acr.outputs.cross-stack-output-azurerm_container_registryacr_containerRegistry_94E5FAA8id}"

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@Hi-Fi Hi-Fi added bug Something isn't working new Un-triaged issue labels Mar 6, 2024
@ansgarm ansgarm added priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. bug/has-workaround A bug with a workaround (may not be elegant) testing and removed new Un-triaged issue labels Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/has-workaround A bug with a workaround (may not be elegant) bug Something isn't working priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. testing
Projects
None yet
Development

No branches or pull requests

2 participants