'Fetch stack state from terraform remote(azure) without local config file

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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Schmidt