Terraform.Aspire.Hosting.Cdk 0.1.0-preview.3

This is a prerelease version of Terraform.Aspire.Hosting.Cdk.
dotnet add package Terraform.Aspire.Hosting.Cdk --version 0.1.0-preview.3
                    
NuGet\Install-Package Terraform.Aspire.Hosting.Cdk -Version 0.1.0-preview.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Terraform.Aspire.Hosting.Cdk" Version="0.1.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Terraform.Aspire.Hosting.Cdk" Version="0.1.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="Terraform.Aspire.Hosting.Cdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Terraform.Aspire.Hosting.Cdk --version 0.1.0-preview.3
                    
#r "nuget: Terraform.Aspire.Hosting.Cdk, 0.1.0-preview.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Terraform.Aspire.Hosting.Cdk@0.1.0-preview.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Terraform.Aspire.Hosting.Cdk&version=0.1.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Terraform.Aspire.Hosting.Cdk&version=0.1.0-preview.3&prerelease
                    
Install as a Cake Tool

Aspire.Terraform

Quality Build Release to NuGet License GitHub Tag

Libraries for .NET Aspire to create terraform code based on templates or Cloud Development Kit (CDK) for Terraform (CDKTF).

Alpha Version is still in development - APIs may change

Aspire.Terraform supports template based generation as well as CDK for Terraform (CDKTF).

Template based

Aspire.Terraform provides a set of templates that can be used to generate Terraform code for various resource types. These templates are stored in the .\templates folder and use Handlebars syntax for dynamic content generation.

dotnet add package Terraform.Aspire.Hosting
// or
dotnet add package Terraform.Aspire.Hosting.Azure

Add .Azure package for support of Azure resources.

Add the following lines to you Aspire Host:

builder.AddTerraformTemplatePublishing()
// or
builder.AddTerraformAzureTemplatePublishing()

Define the location of template files either by defining it in the appsettings.json

  "Terraform": {
    "Templates": {
      "TemplatesPath": "https://raw.githubusercontent.com/lolochristen/Aspire.Terraform/refs/heads/main/templates/container-apps/"
    } 
  } 

or in code

builder.AddTerraformAzureTemplatePublishing(configureOptions: options =>
{
    options.TemplatesPath = "../my-templates";
});

The ./templates/container-apps in this repository contains a base template to deploy to Azure Container Apps. Other templates or targets will eventually be added.

Publish

To execute the publisher for terraform use the following command line from your Aspire Host project folder:

dotnet run --publisher terraform --output-path terraform

An integration into terragrunt is also possible by using run_cmd, see ./playground/AzureContainerApps/terragrunt for an example.

Use of CDK for Terraform

In addition to template-based generation, Aspire.Terraform also supports the use of CDK for Terraform (CDKTF). This allows developers to define their infrastructure using familiar programming languages and leverage the power of the CDK ecosystem.

Install / Setup

  1. Install CDK TF from here

    dotnet add package Terraform.Aspire.Hosting.Cdk
    
  2. Create a cdktf.json file in your Aspire Host project folder with the following content:

    {
      "language": "csharp",
      "app": "dotnet run -project [Project].csproj --publisher terraform --output-path infra",
      "projectId": "d8c23291-21cf-4f76-b40d-90cc2e384901",
      "output": "infra", 
      "terraformProviders": [
        "azure/azapi@~> 2.4"
      ],
      "context": {}
    }
    
  3. Add the CDK publisher to your Aspire Host:

    builder.AddTerraformCdkPublishing();
    
  4. Define your environment and stacks

    var terraform = builder.AddTerraformCdkEnvironment("terraform");
    var mystack = terraform.AddStack<MyStack>("mystack");
    
    public class MyStack : TerraformStack
    {
       public MyStack(Construct scope, string id) : base(scope, id)
       {
           new TerraformOutput(this, "output1", new TerraformOutputConfig()
           {
               Value = "Hello from MyStack"
           });
       }
    }
    
  5. Use cdktf CLI or just generate stack with '''dotnet run --publisher terraform --output-path infra''' command

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Terraform.Aspire.Hosting.Cdk:

Package Downloads
Terraform.Aspire.Hosting.Azure.Cdk

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-preview.3 119 10/27/2025
0.1.0-preview.2 70 10/24/2025
0.1.0-preview.1 116 10/21/2025
0.1.0-preview.0 110 10/21/2025