Skip to content

Commit

Permalink
Add an Azure Resource Manager (ARM) template example (pulumi#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeduffy committed Dec 2, 2018
1 parent 7f19daa commit ca7b0b1
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 0 deletions.
2 changes: 2 additions & 0 deletions azure-ts-arm-template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
3 changes: 3 additions & 0 deletions azure-ts-arm-template/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: azure-arm-template
runtime: nodejs
description: An example of deploying an Azure Resource Manager (ARM) template using Pulumi.
76 changes: 76 additions & 0 deletions azure-ts-arm-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)

# Deploy an Azure Resource Manager (ARM) Template in Pulumi

This example simply deploys an existing Azure Resource Manager (ARM) template using Pulumi. This accepts
any existing valid ARM template, enabling easy migration from existing JSON templates and towards infrastructure
as code using Pulumi. Once deployed, it is easy to incrementally refactor resources at a time out of the template
and into code.

[Read more about ARM templates here](
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview#template-deployment).

## Prerequisites

Ensure you have [downloaded and installed the Pulumi CLI](https://pulumi.io/install).

We will be deploying to Azure, so you will need an Azure account. If you don't have an account,
[sign up for free here](https://azure.microsoft.com/en-us/free/). [Follow the instructions
here](https://pulumi.io/install/azure.html) to connect Pulumi to your Azure account.

Now, install dependencies:

```sh
npm install
```

## Running the App

1. Create a new stack:

```sh
$ pulumi stack init
Enter a stack name: azure-arm-dev
```

2. Set the required configuration variables for this program, and log into Azure:

```bash
$ pulumi config set azure:environment public
$ az login
```

3. Perform the deployment:

```sh
$ pulumi up
Updating stack 'azure-arm-dev'
Performing changes:

Type Name Status
+ pulumi:pulumi:Stack azure-arm--azure-arm-dev created
+ ├─ azure:core:ResourceGroup rg created
+ └─ azure:core:TemplateDeployment arm-dep created

Outputs:
storageAccountName: "abevrwebgje2wstorage"

Resources:
+ 3 created

Duration: 1m8s
```

Notice here that the `storageAccountName` allocated by the ARM template deployment is exported.

4. Tidy up and delete all resources allocated by your deployment:

```bash
$ pulumi destroy -y --skip-preview
$ pulumi stack rm -y --skip-preview
```

# Next Steps

For more Azure examples, please [check out the Azure Getting Started Guide](
https://pulumi.io/quickstart/azure/).
74 changes: 74 additions & 0 deletions azure-ts-arm-template/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";

// Create a resource group to deploy all ARM template resources into.
const resourceGroup = new azure.core.ResourceGroup("test", { location: "WestUS" });

// Create an ARM template deployment using an ordinary JSON ARM template. This could be read from disk, of course.
const armDeployment = new azure.core.TemplateDeployment("test-dep", {
resourceGroupName: resourceGroup.name,
templateBody: JSON.stringify({
"$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": `${pulumi.getProject()}-${pulumi.getStack()}`
},
"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",
});

// Finally, export the allocated storage account name.
export const storageAccountName = armDeployment.outputs.apply(outs => outs["storageAccountName"]);
10 changes: 10 additions & 0 deletions azure-ts-arm-template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "azure-arm-template",
"devDependencies": {
"@types/node": "latest"
},
"dependencies": {
"@pulumi/pulumi": "latest",
"@pulumi/azure": "latest"
}
}
22 changes: 22 additions & 0 deletions azure-ts-arm-template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"lib": [
"es6"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
}

0 comments on commit ca7b0b1

Please sign in to comment.