Open Ranguna opened 2 months ago
Additionally, Terraform/1.9.4 has the following prompt for state migration:
Do you want to copy existing state to the new backend
But the cdktf cli seems to be looking for this instead: https://github.com/hashicorp/terraform-cdk/blob/4f8c0c9984b130ffa3ce0537977dc09a08281782/packages/%40cdktf/cli-core/src/lib/models/terraform-cli.ts#L148
I can open a separate issue for this if needed.
Expected Behavior
cdktf cli should trigger a state migration to the terraform process
Actual Behavior
Terraform fails to initialise and shows the following error:
Steps to Reproduce
cdktf diff --migrate-state
Versions
language: ts "cdktf": "^0.20. "cdktf-cli": "^0.20.8", "constructs": "^10.3.0" Terraform/1.5.7
Providers
hashicorp/google-beta@~> 5.41
Gist
Can't migrate state to a different backend.
Possible Solutions
No response
Workarounds
Manually editing
node_modules/cdktf-cli/bundle/bin/cmds/handlers.js
:migrateState:this.options.migrateState
tomigrateState:true
;,e.migrateState&&r.push("-migrate-state")
next toe.noColor&&r.push("-no-color")
and before the;
;Workaround for a possibly separate issue of migrating the state (see https://github.com/hashicorp/terraform-cdk/issues/3704#issuecomment-2295293154):
Should Terraform migrate your existing state
toDo you want to copy existing state to the new backend
innode_modules/cdktf-cli/bundle/bin/cmds/handlers.js
.Anything Else?
No response
References
A possible reason for this is that the
migrateState
flag is not being passed when thediff
handler initialises terraform here: https://github.com/hashicorp/terraform-cdk/blob/4f8c0c9984b130ffa3ce0537977dc09a08281782/packages/%40cdktf/cli-core/src/lib/cdktf-project.ts#L400The method
getStackExecutor
accepts a second argument with the cli options, which are spread here: https://github.com/hashicorp/terraform-cdk/blob/4f8c0c9984b130ffa3ce0537977dc09a08281782/packages/%40cdktf/cli-core/src/lib/cdktf-project.ts#L333 and later used here: https://github.com/hashicorp/terraform-cdk/blob/4f8c0c9984b130ffa3ce0537977dc09a08281782/packages/%40cdktf/cli-core/src/lib/cdktf-stack.ts#L261The value of
this.options.migrateState
isundefined
at that time.Not only that, but it seems the terraform cli package is also not passing the
-migrate-state
to the terraform process: https://github.com/hashicorp/terraform-cdk/blob/4f8c0c9984b130ffa3ce0537977dc09a08281782/packages/%40cdktf/cli-core/src/lib/models/terraform-cli.ts#L123Relevant docs: https://github.com/hashicorp/terraform-cdk/blob/4f8c0c9984b130ffa3ce0537977dc09a08281782/website/docs/cdktf/concepts/remote-backends.mdx#L348
Help Wanted
Community Note