TemplateDeployment

class TemplateDeployment : KotlinCustomResource

Manages a template deployment of resources

Note on ARM Template Deployments: Due to the way the underlying Azure API is designed, this provider can only manage the deployment of the ARM Template - and not any resources which are created by it. This means that when deleting the azure.core.TemplateDeployment resource, this provider will only remove the reference to the deployment, whilst leaving any resources created by that ARM Template Deployment. One workaround for this is to use a unique Resource Group for each ARM Template Deployment, which means deleting the Resource Group would contain any resources created within it - however this isn't ideal. More information.

Example Usage

Note: This example uses Storage Accounts and Public IP's which are natively supported by this provider - we'd highly recommend using the Native Resources where possible instead rather than an ARM Template, for the reasons outlined above.

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const example = new azure.core.ResourceGroup("example", {
name: "example-resources",
location: "West Europe",
});
const exampleTemplateDeployment = new azure.core.TemplateDeployment("example", {
name: "acctesttemplate-01",
resourceGroupName: example.name,
templateBody: `{
"schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS"
],
"metadata": {
"description": "Storage Account type"
}
}
},
"variables": {
"location": "[resourceGroup().location]",
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'storage')]",
"publicIPAddressName": "[concat('myPublicIp', uniquestring(resourceGroup().id))]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15",
"dnsLabelPrefix": "example-acctest"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('dnsLabelPrefix')]"
}
}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
}
}
}
`,
parameters: {
storageAccountType: "Standard_GRS",
},
deploymentMode: "Incremental",
});
export const storageAccountName = exampleTemplateDeployment.outputs.storageAccountName;
import pulumi
import pulumi_azure as azure
example = azure.core.ResourceGroup("example",
name="example-resources",
location="West Europe")
example_template_deployment = azure.core.TemplateDeployment("example",
name="acctesttemplate-01",
resource_group_name=example.name,
template_body="""{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS"
],
"metadata": {
"description": "Storage Account type"
}
}
},
"variables": {
"location": "[resourceGroup().location]",
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'storage')]",
"publicIPAddressName": "[concat('myPublicIp', uniquestring(resourceGroup().id))]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15",
"dnsLabelPrefix": "example-acctest"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('dnsLabelPrefix')]"
}
}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
}
}
}
""",
parameters={
"storageAccountType": "Standard_GRS",
},
deployment_mode="Incremental")
pulumi.export("storageAccountName", example_template_deployment.outputs["storageAccountName"])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;
return await Deployment.RunAsync(() =>
{
var example = new Azure.Core.ResourceGroup("example", new()
{
Name = "example-resources",
Location = "West Europe",
});
var exampleTemplateDeployment = new Azure.Core.TemplateDeployment("example", new()
{
Name = "acctesttemplate-01",
ResourceGroupName = example.Name,
TemplateBody = @"{
""$schema"": ""https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"",
""contentVersion"": ""1.0.0.0"",
""parameters"": {
""storageAccountType"": {
""type"": ""string"",
""defaultValue"": ""Standard_LRS"",
""allowedValues"": [
""Standard_LRS"",
""Standard_GRS"",
""Standard_ZRS""
],
""metadata"": {
""description"": ""Storage Account type""
}
}
},
""variables"": {
""location"": ""[resourceGroup().location]"",
""storageAccountName"": ""[concat(uniquestring(resourceGroup().id), 'storage')]"",
""publicIPAddressName"": ""[concat('myPublicIp', uniquestring(resourceGroup().id))]"",
""publicIPAddressType"": ""Dynamic"",
""apiVersion"": ""2015-06-15"",
""dnsLabelPrefix"": ""example-acctest""
},
""resources"": [
{
""type"": ""Microsoft.Storage/storageAccounts"",
""name"": ""[variables('storageAccountName')]"",
""apiVersion"": ""[variables('apiVersion')]"",
""location"": ""[variables('location')]"",
""properties"": {
""accountType"": ""[parameters('storageAccountType')]""
}
},
{
""type"": ""Microsoft.Network/publicIPAddresses"",
""apiVersion"": ""[variables('apiVersion')]"",
""name"": ""[variables('publicIPAddressName')]"",
""location"": ""[variables('location')]"",
""properties"": {
""publicIPAllocationMethod"": ""[variables('publicIPAddressType')]"",
""dnsSettings"": {
""domainNameLabel"": ""[variables('dnsLabelPrefix')]""
}
}
}
],
""outputs"": {
""storageAccountName"": {
""type"": ""string"",
""value"": ""[variables('storageAccountName')]""
}
}
}
",
Parameters =
{
{ "storageAccountType", "Standard_GRS" },
},
DeploymentMode = "Incremental",
});
return new Dictionary<string, object?>
{
["storageAccountName"] = exampleTemplateDeployment.Outputs.Apply(outputs => outputs.StorageAccountName),
};
});
package main
import (
"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := core.NewResourceGroup(ctx, "example", &core.ResourceGroupArgs{
Name: pulumi.String("example-resources"),
Location: pulumi.String("West Europe"),
})
if err != nil {
return err
}
exampleTemplateDeployment, err := core.NewTemplateDeployment(ctx, "example", &core.TemplateDeploymentArgs{
Name: pulumi.String("acctesttemplate-01"),
ResourceGroupName: example.Name,
TemplateBody: pulumi.String(`{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS"
],
"metadata": {
"description": "Storage Account type"
}
}
},
"variables": {
"location": "[resourceGroup()&#46;location]",
"storageAccountName": "[concat(uniquestring(resourceGroup()&#46;id), 'storage')]",
"publicIPAddressName": "[concat('myPublicIp', uniquestring(resourceGroup()&#46;id))]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15",
"dnsLabelPrefix": "example-acctest"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('dnsLabelPrefix')]"
}
}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
}
}
}
`),
Parameters: pulumi.StringMap{
"storageAccountType": pulumi.String("Standard_GRS"),
},
DeploymentMode: pulumi.String("Incremental"),
})
if err != nil {
return err
}
ctx.Export("storageAccountName", exampleTemplateDeployment.Outputs.ApplyT(func(outputs map[string]string) (string, error) {
return outputs.StorageAccountName, nil
}).(pulumi.StringOutput))
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azure.core.ResourceGroup;
import com.pulumi.azure.core.ResourceGroupArgs;
import com.pulumi.azure.core.TemplateDeployment;
import com.pulumi.azure.core.TemplateDeploymentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new ResourceGroup("example", ResourceGroupArgs.builder()
.name("example-resources")
.location("West Europe")
.build());
var exampleTemplateDeployment = new TemplateDeployment("exampleTemplateDeployment", TemplateDeploymentArgs.builder()
.name("acctesttemplate-01")
.resourceGroupName(example.name())
.templateBody("""
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS"
],
"metadata": {
"description": "Storage Account type"
}
}
},
"variables": {
"location": "[resourceGroup()&#46;location]",
"storageAccountName": "[concat(uniquestring(resourceGroup()&#46;id), 'storage')]",
"publicIPAddressName": "[concat('myPublicIp', uniquestring(resourceGroup()&#46;id))]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15",
"dnsLabelPrefix": "example-acctest"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('dnsLabelPrefix')]"
}
}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
}
}
}
""")
.parameters(Map.of("storageAccountType", "Standard_GRS"))
.deploymentMode("Incremental")
.build());
ctx.export("storageAccountName", exampleTemplateDeployment.outputs().applyValue(outputs -> outputs.storageAccountName()));
}
}
resources:
example:
type: azure:core:ResourceGroup
properties:
name: example-resources
location: West Europe
exampleTemplateDeployment:
type: azure:core:TemplateDeployment
name: example
properties:
name: acctesttemplate-01
resourceGroupName: ${example.name}
templateBody: |
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS"
],
"metadata": {
"description": "Storage Account type"
}
}
},
"variables": {
"location": "[resourceGroup()&#46;location]",
"storageAccountName": "[concat(uniquestring(resourceGroup()&#46;id), 'storage')]",
"publicIPAddressName": "[concat('myPublicIp', uniquestring(resourceGroup()&#46;id))]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15",
"dnsLabelPrefix": "example-acctest"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "[variables('apiVersion')]",
"location": "[variables('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "[variables('apiVersion')]",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[variables('dnsLabelPrefix')]"
}
}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
}
}
}
parameters:
storageAccountType: Standard_GRS
deploymentMode: Incremental
outputs:
storageAccountName: ${exampleTemplateDeployment.outputs.storageAccountName}

Note

This provider does not know about the individual resources created by Azure using a deployment template and therefore cannot delete these resources during a destroy. Destroying a template deployment removes the associated deployment operations, but will not delete the Azure resources created by the deployment. In order to delete these resources, the containing resource group must also be destroyed. More information.

Properties

Link copied to clipboard
val deploymentMode: Output<String>

Specifies the mode that is used to deploy resources. This value could be either Incremental or Complete. Note that you will almost always want this to be set to Incremental otherwise the deployment will destroy all infrastructure not specified within the template, and this provider will not be aware of this.

Link copied to clipboard
val id: Output<String>
Link copied to clipboard
val name: Output<String>

Specifies the name of the template deployment. Changing this forces a new resource to be created.

Link copied to clipboard
val outputs: Output<Map<String, String>>

A map of supported scalar output types returned from the deployment (currently, Azure Template Deployment outputs of type String, Int and Bool are supported, and are converted to strings - others will be ignored) and can be accessed using .outputs["name"].

Link copied to clipboard
val parameters: Output<Map<String, String>>?

Specifies the name and value pairs that define the deployment parameters for the template.

Link copied to clipboard
val parametersBody: Output<String>?

Specifies a valid Azure JSON parameters file that define the deployment parameters. It can contain KeyVault references

Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The name of the resource group in which to create the template deployment. Changing this forces a new resource to be created.

Link copied to clipboard
val templateBody: Output<String>

Specifies the JSON definition for the template.

Link copied to clipboard
val urn: Output<String>