Hi, I have a setup with multiple stacks using GCS as the state backend. It looks something like this:
class MyStack extends TerraformStack {
constructor(scope: Construct, name: string) {
super(scope, name);
new GcsBackend(this, {
bucket: "myBucket",
});
}
// stack code ...
}
class MyOtherStack extends TerraformStack {
constructor(scope: Construct, name: string) {
super(scope, name);
new GcsBackend(this, {
bucket: "myBucket",
});
}
// stack code ...
}
Now, this will not work because both state files are stored in “myBucket/default.tfstate” and they will overwrite each other. I can fix this by setting a prefix which works fine:
new GcsBackend(this, {
bucket: "myBucket",
prefix: `stacks/${name}`
});
But I was wondering, am I missing something here or is there really no way to change the name of “default.tfstate”? The documentation says it should be the name of the stack, but that only seems to work if you use the Terraform Cloud backend.
If this is intended, maybe it should be in the documentation? Since it’s not really obvious the first time. The state just gets overwritten without any warning, which causes quite a bit of chaos.