provider/azurerm: Add the documentation for the AzureRM Template

Deployment resource
This commit is contained in:
stack72 2016-03-21 15:59:56 +00:00
parent a4cd5eeb2b
commit fe79dcf6c1
4 changed files with 244 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"strings"
"time"
"github.com/Azure/azure-sdk-for-go/arm/resources/resources"
@ -44,6 +45,11 @@ func resourceArmTemplateDeployment() *schema.Resource {
Optional: true,
},
"outputs": &schema.Schema{
Type: schema.TypeMap,
Computed: true,
},
"deployment_mode": &schema.Schema{
Type: schema.TypeString,
Required: true,
@ -58,16 +64,26 @@ func resourceArmTemplateDeploymentCreate(d *schema.ResourceData, meta interface{
name := d.Get("name").(string)
resGroup := d.Get("resource_group_name").(string)
deployment_mode := d.Get("deployment_mode").(string)
deploymentMode := 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),
Mode: resources.DeploymentMode(deploymentMode),
}
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 {
@ -89,10 +105,10 @@ 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"},
Pending: []string{"creating", "updating", "accepted", "running"},
Target: []string{"succeeded"},
Refresh: templateDeploymentStateRefreshFunc(client, resGroup, name),
Timeout: 10 * time.Minute,
}
@ -123,8 +139,24 @@ 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)
}
var outputs map[string]string
if resp.Properties.Outputs != nil && len(*resp.Properties.Outputs) > 0 {
for key, output := range *resp.Properties.Outputs {
log.Printf("[INFO] Found Key %s", key)
outputMap := output.(map[string]interface{})
outputValue, ok := outputMap["value"]
if !ok {
// No value
continue
}
outputs[key] = outputValue.(string)
}
}
d.Set("outputs", outputs)
return nil
}
@ -151,7 +183,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
}
@ -176,6 +208,6 @@ func templateDeploymentStateRefreshFunc(client *ArmClient, resourceGroupName str
return nil, "", fmt.Errorf("Error issuing read request in templateDeploymentStateRefreshFunc to Azure ARM for Template Deployment '%s' (RG: '%s'): %s", name, resourceGroupName, err)
}
return res, *res.Properties.ProvisioningState, nil
return res, strings.ToLower(*res.Properties.ProvisioningState), nil
}
}

View File

@ -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
@ -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"
}
`

View File

@ -0,0 +1,95 @@
---
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.

View File

@ -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">