cdktf deploy does not respect `--output` directory for `.terraform/terraform.tfstate`
See original GitHub issueCommunity 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
cdktf & Language Versions
cdktf v0.10.1 Python 3.9.12
Affected Resource(s)
When running cdktf deploy --output=/deployed/deployed_cdktf_state
from /tmp
The synthesized cdk.tf.json
ends up containing:
"backend": {
"local": {
"path": "/tmp/terraform.stack-name.tfstate"
}
},
ā¦and saves the tfstate there (/tmp/terraform.stack-name.tfstate
) on deployment - which is surprising.
Expected Behavior
Expected /tmp/terraform.stack-name.tfstate
to be at /deployed/deployed_cdktf_state/terraform.stack-name.tfstate
instead.
Surprisingly /deployed/deployed_cdktf_state/stacks/stack-name/.terraform/terraform.tfstate
is created under the stated --output
directory (/deployed/deployed_cdktf_state
) but it too contains:
"backend": {
"type": "local",
"config": {
"path": "/tmp/terraform.stack-name.tfstate",
"workspace_dir": null
},
},
- Is there a way to explicitly use a different directory for
terraform.stack-name.tfstate
? - Is this a bug or expected?
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Deploy Lambda Functions with TypeScript and CDK for ...
In this tutorial, you will deploy a CDKTF application made up of two ... that the directories containing the Lambda handlers are not...
Read more >Use Your Preferred Programming Language with CDKTF
HashiCorp Terraform now supports writing configurations in HCL or your choice of C#, Python, TypeScript, Java, or Go with Cloud DevelopmentĀ ...
Read more >SweetOps #terraform for September, 2020
Not sure if this from the logs helpsā¦sure doesn't help me: ... steps: https://github.com/cloudposse/terraform-aws-tfstate-backend#create.
Read more >Managing Terraform State | Google Cloud Skills Boost
If Terraform doesn't output a message, state locking is still occurring. Not all backends support locking. View the list of backend types for...
Read more >Hashicorp Terraform & Packer. Kubernetes Boilerplates
HashiCorp Cloud Platform is a fully managed platform for Terraform, Vault, ... nitheeshp.dev: Practical CI/CD Guide to Deploying AWS Infrastructure throughĀ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @gc-ss, you donāt have to use another backend provider, you could also explictly add a
LocalBackend
yourself. However, it is currently not possible to pass any configuration to theLocalBackend
that is automatically added in case no backend was defined explicitly.If you donāt want to configure the backend explicitly in every stack, you could subclass the
TerraformStack
class and use that new stack class for all your stacks. That stack could then add a correctly configuredLocalBackend
for example in its constructor. Another option would be to use an Aspect that adds the requiredLocalBackend
.You would do
We donāt need to override the local backend, itās only added if you donāt have one configured for your stack. As for the output directory, I disagree with the notion that it should be taken into consideration. More often than not the output directory is in the gitignore (like in all our templates), because if you donāt have a strong reason you donāt want to commit the HCL JSON files. If we change it like you propose this would mean we ignore the state file. Plus this folder gets cleaned by us, e.g. if you delete a stack, again making you loose your state.