Reputation: 450
I am using cdktf in Python and maintaining multiple stacks using Terraform and the states are being stored in azure storage account as backend. I would need to fetch any stack at any point in time and make changes to the resources in the stack. However, I do not maintain the state locally. How can I fetch the state from azure backend and then make changes to the resources in the stack?
Upvotes: 1
Views: 729
Reputation: 11921
If I get you correctly you want to configure the backend to use Azure. In Terraform CDK this is done via constructs, there is a AzurermBackend you can use.
This is the example from the CDKTF repo
import { Construct } from "constructs";
import { App, TerraformStack, AzurermBackend } from "cdktf";
class MyStack extends TerraformStack {
constructor(scope: Construct, name: string) {
super(scope, name);
// Azurerm Backend - https://www.terraform.io/docs/backends/types/azurerm.html
new AzurermBackend(this, {
resourceGroupName: "StorageAccount-ResourceGroup",
storageAccountName: "abcd1234",
containerName: "tfstate",
key: "prod.terraform.tfstate",
});
// define resources here
}
}
const app = new App();
new MyStack(app, "typescript-backends");
app.synth();
Once you have this configured, every cdktf deploy
or cdktf destroy
will run using this backend.
Upvotes: 1