forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an Azure Resource Manager (ARM) template example (pulumi#187)
- Loading branch information
Showing
6 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/bin/ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |