Skip to main content

A collection of CDK modules for provisioning and managing Terraform resources efficiently.

Project description

Azure Terraform CDK Constructs

Welcome to the Azure Terraform CDK Constructs project! This library offers a comprehensive suite of L2 Constructs designed to simplify and enhance the experience of building and managing Azure infrastructure with the Cloud Development Kit for Terraform (CDKTF).

Benefits of Using L2 Constructs

With L2 Constructs, you get the following benefits:

  • Abstraction: Higher-level abstractions over Azure resources make your infrastructure code more declarative and easier to understand.
  • Reusability: Encapsulate common patterns and best practices in your infrastructure code, promoting reusability across different projects and teams.
  • Rapid Development: Accelerate your cloud development process with pre-built constructs that have been tested for common use cases, allowing you to focus on your unique application logic.
  • Direct IDE Integration: Access detailed documentation directly within your Integrated Development Environment (IDE), streamlining your development workflow: alt text

Quick Example

This is a quick example that showcases the simplicity and power of L2 Constructs. We'll create a storage account, add a container to it, and then upload a blob—all with a few lines of intuitive, object-oriented code:

// Create a new instance of a storage account as an object
const sa = new azcdk.azure_storageaccount.Account(stack, "storageaccount", {
  name: "testStorageAccount",
  location: "eastus",
});

// Add a container to the storage account by calling a method on the storage account object
const container = sa.addContainer("testcontainer");

// Add a blob to the container by calling a method on the container object
// The path "../../../test.txt" points to the source file to be uploaded as a blob
container.addBlob("testblob.txt", "../../../test.txt");

Getting Started

This guide will walk you through the process of using the Azure L2 Constructs to define and provision infrastructure on Azure.

Prerequisites

Make sure you have Node.js and npm installed on your machine. These will be used to install the CDK for Terraform and Azure provider packages.

Installation

First, install the CDK for Terraform CLI globally using npm:

npm install -g cdktf-cli

Next, initialize a new CDK for Terraform project with TypeScript template:

cdktf init --template="TypeScript" --local

Install the AzureRM provider for CDKTF:

npm install @cdktf/provider-azurerm

Then, add the Microsoft Terraform CDK constructs for Azure:

npm install @micrsoft/terraform-cdk-constructs

Example 1: Creating a Storage Account

Now let's create a simple Azure storage account. The following TypeScript snippet defines a storage account resource using the CDKTF:

// Import necessary modules and classes
import * as azcdk from "@microsoft/terraform-cdk-constructs";
import { Construct } from 'constructs';
import { App, TerraformStack } from 'cdktf';
import { AzurermProvider } from "@cdktf/provider-azurerm/lib/provider";

// Define a new Terraform stack
class AzureAppInfra extends TerraformStack {
 constructor(scope: Construct, name: string) {
   super(scope, name);

   // Initialize Azure provider
   new AzurermProvider(this, "azureFeature", { features: {} });

   // Create a new Azure storage account with the specified name and location
   new azcdk.azure_storageaccount.Account(this, "storageaccount", {
     name: "test42348808",
     location: "eastus",
   });
 }
}

// Initialize the CDK app and synthesize Terraform configurations
const app = new App();
new AzureAppInfra(app, 'cdk');
app.synth();

After defining your infrastructure, generate the Terraform configuration files:

cdktf synth

Finally, deploy your infrastructure to Azure:

cdktf deploy

Supported Languages

Currently, our CDK L2 constructs are available in the following languages:

Language Status
TypeScript Available
Python Available
Java Coming soon
C# Available

Stay tuned for updates as we work to expand support to other popular programming languages!

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

We welcome contributions to this project! See our documentation on how to get started contributing.

Code Spaces

To open this repository in a Code Space, click the button below:

Open in Code Spaces

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

microsoft-cdktfconstructs-0.0.3.dev12.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

File details

Details for the file microsoft-cdktfconstructs-0.0.3.dev12.tar.gz.

File metadata

File hashes

Hashes for microsoft-cdktfconstructs-0.0.3.dev12.tar.gz
Algorithm Hash digest
SHA256 5c3c604adbccc42f6011bc1a7920f89b271e5b25782c383a0b786be1b4048a64
MD5 4699df25b62941191a4e41cf193d1d3b
BLAKE2b-256 9811ad7eac85faa17a5f7b1827e9ddcf2ec1a5f485168686ca521ccb488c9d74

See more details on using hashes here.

File details

Details for the file microsoft_cdktfconstructs-0.0.3.dev12-py3-none-any.whl.

File metadata

File hashes

Hashes for microsoft_cdktfconstructs-0.0.3.dev12-py3-none-any.whl
Algorithm Hash digest
SHA256 3fe2de593e1564804cecab8e4293f87f5ef0ed9c34c6cf3085966bcc51d21760
MD5 116ea0608f5034893b82c63c8f246bbc
BLAKE2b-256 8aa2b5af260b4d8493cf7432eacbf04ae693aba3572c6b57411656ed0a413fa3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page