Skip to content

Commit

Permalink
provider/azurerm: Add the documentation for the AzureRM Template
Browse files Browse the repository at this point in the history
Deployment resource
  • Loading branch information
stack72 committed Mar 21, 2016
1 parent 8d7c0fa commit ecd5c4b
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 5 deletions.
69 changes: 64 additions & 5 deletions builtin/providers/azurerm/resource_arm_template_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func resourceArmTemplateDeployment() *schema.Resource {
Optional: true,
},

"outputs": &schema.Schema{
Type: schema.TypeMap,
Computed: true,
},

"deployment_mode": &schema.Schema{
Type: schema.TypeString,
Required: true,
Expand All @@ -60,14 +65,24 @@ func resourceArmTemplateDeploymentCreate(d *schema.ResourceData, meta interface{
resGroup := d.Get("resource_group_name").(string)
deployment_mode := d.Get("deployment_mode").(string)

log.Printf("[INFO] preparing arguments for Azure ARM Virtual Machine creation.")
log.Printf("[INFO] preparing arguments for Azure ARM Template Deployment creation.")
properties := resources.DeploymentProperties{
Mode: resources.DeploymentMode(deployment_mode),
}

if v, ok := d.GetOk("parameters"); ok {
params := v.(map[string]interface{})
properties.Parameters = &params

newParams := make(map[string]interface{}, len(params))
for key, val := range params {
newParams[key] = struct {
Value interface{}
}{
Value: val,
}
}

properties.Parameters = &newParams
}

if v, ok := d.GetOk("template_body"); ok {
Expand All @@ -89,7 +104,7 @@ func resourceArmTemplateDeploymentCreate(d *schema.ResourceData, meta interface{

d.SetId(*resp.ID)

log.Printf("[DEBUG] Waiting for Template Deploymnet (%s) to become available", name)
log.Printf("[DEBUG] Waiting for Template Deployment (%s) to become available", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"Creating", "Updating", "Accepted", "Running"},
Target: []string{"Succeeded"},
Expand Down Expand Up @@ -123,7 +138,51 @@ func resourceArmTemplateDeploymentRead(d *schema.ResourceData, meta interface{})
return nil
}
if err != nil {
return fmt.Errorf("Error making Read request on Azure Template Deployment %s: %s", name, err)
return fmt.Errorf("Error making Read request on Azure RM Template Deployment %s: %s", name, err)
}

if resp.Properties.Outputs != nil {
outputs := make(map[string]string, len(*resp.Properties.Outputs))
for key, output := range *resp.Properties.Outputs {
outputMap, ok := output.(map[string]interface{})
if !ok {
// Not a map
continue
}

outputType, ok := outputMap["type"]
if !ok {
// No type
continue
}

outputTypeString, ok := outputType.(string)
if !ok {
// Type description not a string
continue
}

if outputTypeString != "string" {
// Type instance is not "string"
continue
}

outputValue, ok := outputMap["value"]
if !ok {
// No value
continue
}

outputValueString, ok := outputValue.(string)
if !ok {
// Value isn't a string
continue
}

outputs[key] = outputValueString
}

d.Set("outputs", outputs)
}

return nil
Expand Down Expand Up @@ -151,7 +210,7 @@ func expandTemplateBody(template string) (map[string]interface{}, error) {
var templateBody map[string]interface{}
err := json.Unmarshal([]byte(template), &templateBody)
if err != nil {
return nil, fmt.Errorf("dont be a dumb fuck")
return nil, fmt.Errorf("Error Expanding the template_body for Azure RM Template Deployment")
}
return templateBody, nil
}
Expand Down
103 changes: 103 additions & 0 deletions builtin/providers/azurerm/resource_arm_template_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ func TestAccAzureRMTemplateDeployment_basic(t *testing.T) {
})
}

func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMTemplateDeployment_withParams, ri, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"),
resource.TestCheckResourceAttr("azurerm_template_deployment.test", "outputs.testOutput", "Output Value"),
),
},
},
})
}

func testCheckAzureRMTemplateDeploymentExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -146,3 +165,87 @@ DEPLOY
}
`

var testAccAzureRMTemplateDeployment_withParams = `
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = "West US"
}
output "test" {
value = "${azurerm_template_deployment.test.outputs.testOutput}"
}
resource "azurerm_template_deployment" "test" {
name = "acctesttemplate-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
template_body = <<DEPLOY
{
"$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"
}
},
"dnsLabelPrefix": {
"type": "string",
"metadata": {
"description": "DNS Label for the Public IP. Must be lowercase. It should match with the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$ or it will raise an error."
}
}
},
"variables": {
"location": "[resourceGroup().location]",
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'storage')]",
"publicIPAddressName": "[concat('myPublicIp', uniquestring(resourceGroup().id))]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15"
},
"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": "[parameters('dnsLabelPrefix')]"
}
}
}
],
"outputs": {
"testOutput": {
"type": "string",
"value": "Output Value"
}
}
}
DEPLOY
parameters {
dnsLabelPrefix = "terraform-test-%d"
storageAccountType = "Standard_GRS"
}
deployment_mode = "Complete"
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_template_deployment"
sidebar_current: "docs-azurerm-resource-template-deployment"
description: |-
Create a template deployment of resources.
---

# azurerm\_template\_deployment

Create a template deployment of resources

## Example Usage

```
resource "azurerm_resource_group" "test" {
name = "acctestrg-01"
location = "West US"
}
resource "azurerm_template_deployment" "test" {
name = "acctesttemplate-01"
resource_group_name = "${azurerm_resource_group.test.name}"
template_body = <<DEPLOY
{
"$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": "terraform-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')]"
}
}
}
]
}
DEPLOY
deployment_mode = "Complete"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Specifies the name of the template deployment. Changing this forces a
new resource to be created.

* `resource_group_name` - (Required) The name of the resource group in which to
create the template deployment.

* `template_body` - (Optional) Specifies the JSON definition for the template.

* `parameters` - (Optional) Specifies the name and value pairs that define the deployment parameters for the template.
* `deploymnet_mode` - (Optional) Specifies the mode that is used to deploy resources. This value could be either `Incremental` or `Complete`.

## Attributes Reference

The following attributes are exported:

* `id` - The Template Deployment ID.
4 changes: 4 additions & 0 deletions website/source/layouts/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
</ul>
</li>

<li<%= sidebar_current("docs-azurerm-resource-template-deployment") %>>
<a href="/docs/providers/azurerm/r/template_deployment.html">azurerm_template_deployment</a>
</li>

<li<%= sidebar_current(/^docs-azurerm-resource-virtualmachine/) %>>
<a href="#">Virtual Machine Resources</a>
<ul class="nav nav-visible">
Expand Down

0 comments on commit ecd5c4b

Please sign in to comment.