This document provides step by step instructions to setup CDK for Azure CDK for Terraform (CDKTF).
- Homebrew (for MacOS) or Chocolatey (for Windows)
- Node.js and npm
- Terraform
- Microsoft Azure tenant and subscription
- Change
product: 'cdktf-example-for-azure'
to your project name in theconfig/default.ts
file. - Adjust each parameter in
config/<NODE_ENV>.ts
as per your project requirements. - The parameters in
config/default.ts
will be overridden by those inconfig/<NODE_ENV>.ts
. - Visual Studio Code (VS Code) for code editing (Download Here).
- ESLint and Prettier plugins for VS Code for better coding practices.
Terraform is required for the CDK for Terraform. For MacOS, you can install it via Homebrew. For Windows, you can use Chocolatey.
-
MacOS:
brew install terraform
-
Windows:
choco install terraform
To configure your Azure credentials and tenant/settings details, set the following environment variables:
-
MacOS:
export AZURE_TENANT_ID=<Your Azure Tenant ID> export AZURE_SUBSCRIPTION_ID=<Your Azure Subscription ID> export AZURE_LOCATION=<Your Azure Location> export NODE_ENV=<Your Node.js environment>
-
Windows:
$env:AZURE_TENANT_ID="<Your Azure Tenant ID>" $env:AZURE_SUBSCRIPTION_ID="<Your Azure Subscription ID>" $env:AZURE_LOCATION="<Your Azure Location>" $env:NODE_ENV="<Your Node.js environment>"
Please replace <Your Azure Tenant ID>
, <Your Azure Subscription ID>
, <Your Azure Location>
, and <Your Node.js environment>
with your actual Tenant ID, Subscription ID, location, and Node.js environment respectively.
Navigate to your working directory and install the required npm packages:
npm install
Run cdktf get
command to download necessary provider bindings:
cdktf get
To compile your TypeScript code into JavaScript, use:
npm run build
To see the differences between your current state and the changes the CDK for Terraform is going to deploy, use:
cdktf diff
To deploy your infrastructure, use the following command:
cdktf deploy
To destroy your infrastructure, use the following command:
cdktf destroy
It removes all the resources provisioned by your Terrform configuration. Be careful when using this command, as it will permanently destroy all your resources.
That's it. You've now deployed your infrastructure on Azure using CDK for Terraform!