Open iridian-ks opened 2 years ago
Hi @iridian-ks 👋
If no backend construct is used, the CDKTF will default to using local state (and thereby render a local backend in the generated cdk.tf.json
). That one probably overrides the one you are manually setting separately.
You can instead try to use an override on your Stack instance: https://www.terraform.io/cdktf/concepts/providers-and-resources#escape-hatch
However, we should add the kubernetes backend to the ones we support.
Tentatively, it looks like I'm getting this:
"terraform": {
"backend": {
"kubernetes": {
},
"local": {
"path": ".../cdk/terraform.gloo.tfstate"
}
}
}
Not sure if that's the intended behavior.
But it's resulting in:
[2022-03-21T19:34:03.007] [ERROR] default - ╷
│ Error: Duplicate backend configuration
│
│ on cdk.tf.json line 38, in terraform.backend:
│ 38: "local": {
│
│ A module may have only one backend configuration. The backend was
│ previously configured at cdk.tf.json:36,21-22.
╵
╷
│ Error: Duplicate backend configuration
│
│ on cdk.tf.json line 38, in terraform.backend:
│ 38: "local": {
│
│ A module may have only one backend configuration. The backend was
│ previously configured at cdk.tf.json:36,21-22.
Sorry for the spam, but looks like this is better:
self.add_override("terraform.backend.kubernetes", {})
self.add_override("terraform.backend.local", None)
Community Note
Description
The Kubernetes backend in Terraform: https://www.terraform.io/language/settings/backends/kubernetes Seems to be missing from Terraform CDK: https://www.terraform.io/cdktf/concepts/remote-backends#supported-backends
It looks like CDK is generating a JSON file for backends, which I tried creating manually like so:
remote.tf.json
Then in the Pod setting
KUBE_IN_CLUSTER_CONFIG
andKUBE_NAMESPACE
env vars and runningcdktf deploy
does not initialize the backend and uses local state.