Terraform.Aspire.Hosting.Cdk
0.1.0-preview.3
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
<PackageReference Include="Terraform.Aspire.Hosting.Cdk" Version="0.1.0-preview.3" />
<PackageVersion Include="Terraform.Aspire.Hosting.Cdk" Version="0.1.0-preview.3" />
<PackageReference Include="Terraform.Aspire.Hosting.Cdk" />
paket add Terraform.Aspire.Hosting.Cdk --version 0.1.0-preview.3
#r "nuget: Terraform.Aspire.Hosting.Cdk, 0.1.0-preview.3"
#:package Terraform.Aspire.Hosting.Cdk@0.1.0-preview.3
#addin nuget:?package=Terraform.Aspire.Hosting.Cdk&version=0.1.0-preview.3&prerelease
#tool nuget:?package=Terraform.Aspire.Hosting.Cdk&version=0.1.0-preview.3&prerelease
Aspire.Terraform
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
Install CDK TF from here
dotnet add package Terraform.Aspire.Hosting.CdkCreate a
cdktf.jsonfile 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": {} }Add the CDK publisher to your Aspire Host:
builder.AddTerraformCdkPublishing();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" }); } }Use cdktf CLI or just generate stack with '''dotnet run --publisher terraform --output-path infra''' command
| Product | Versions 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. |
-
net8.0
- Aspire.Hosting (>= 9.5.2)
- Handlebars.Net (>= 2.1.6)
- Handlebars.Net.Extension.Json (>= 1.0.0)
- Handlebars.Net.Helpers (>= 2.5.3)
- Handlebars.Net.Helpers.DynamicLinq (>= 2.5.3)
- HashiCorp.Cdktf (>= 0.21.0)
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 |