mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #13670 from StephenWeatherford/dev/stephweatherford/9694
[MS] Fix crash #7353, and support bool and int outputs
This commit is contained in:
commit
3383222667
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -155,20 +156,40 @@ func resourceArmTemplateDeploymentRead(d *schema.ResourceData, meta interface{})
|
||||
if resp.Properties.Outputs != nil && len(*resp.Properties.Outputs) > 0 {
|
||||
outputs = make(map[string]string)
|
||||
for key, output := range *resp.Properties.Outputs {
|
||||
log.Printf("[DEBUG] Processing deployment output %s", key)
|
||||
outputMap := output.(map[string]interface{})
|
||||
outputValue, ok := outputMap["value"]
|
||||
if !ok {
|
||||
// No value
|
||||
log.Printf("[DEBUG] No value - skipping")
|
||||
continue
|
||||
}
|
||||
outputType, ok := outputMap["type"]
|
||||
if !ok {
|
||||
log.Printf("[DEBUG] No type - skipping")
|
||||
continue
|
||||
}
|
||||
|
||||
outputs[key] = outputValue.(string)
|
||||
var outputValueString string
|
||||
switch strings.ToLower(outputType.(string)) {
|
||||
case "bool":
|
||||
outputValueString = strconv.FormatBool(outputValue.(bool))
|
||||
|
||||
case "string":
|
||||
outputValueString = outputValue.(string)
|
||||
|
||||
case "int":
|
||||
outputValueString = fmt.Sprint(outputValue)
|
||||
|
||||
default:
|
||||
log.Printf("[WARN] Ignoring output %s: Outputs of type %s are not currently supported in azurerm_template_deployment.",
|
||||
key, outputType)
|
||||
continue
|
||||
}
|
||||
outputs[key] = outputValueString
|
||||
}
|
||||
}
|
||||
|
||||
d.Set("outputs", outputs)
|
||||
|
||||
return nil
|
||||
return d.Set("outputs", outputs)
|
||||
}
|
||||
|
||||
func resourceArmTemplateDeploymentDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
|
@ -68,6 +68,29 @@ func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMTemplateDeployment_withOutputs(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMTemplateDeployment_withOutputs, ri, ri, ri)
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"),
|
||||
resource.TestCheckOutput("tfIntOutput", "-123"),
|
||||
resource.TestCheckOutput("tfStringOutput", "Standard_GRS"),
|
||||
resource.TestCheckOutput("tfFalseOutput", "false"),
|
||||
resource.TestCheckOutput("tfTrueOutput", "true"),
|
||||
resource.TestCheckResourceAttr("azurerm_template_deployment.test", "outputs.stringOutput", "Standard_GRS"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMTemplateDeployment_withError(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMTemplateDeployment_withError, ri, ri)
|
||||
@ -352,6 +375,126 @@ DEPLOY
|
||||
|
||||
`
|
||||
|
||||
var testAccAzureRMTemplateDeployment_withOutputs = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acctestRG-%d"
|
||||
location = "West US"
|
||||
}
|
||||
|
||||
output "tfStringOutput" {
|
||||
value = "${azurerm_template_deployment.test.outputs.stringOutput}"
|
||||
}
|
||||
|
||||
output "tfIntOutput" {
|
||||
value = "${azurerm_template_deployment.test.outputs.intOutput}"
|
||||
}
|
||||
|
||||
output "tfFalseOutput" {
|
||||
value = "${azurerm_template_deployment.test.outputs.falseOutput}"
|
||||
}
|
||||
|
||||
output "tfTrueOutput" {
|
||||
value = "${azurerm_template_deployment.test.outputs.trueOutput}"
|
||||
}
|
||||
|
||||
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."
|
||||
}
|
||||
},
|
||||
"intParameter": {
|
||||
"type": "int",
|
||||
"defaultValue": -123
|
||||
},
|
||||
"falseParameter": {
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
},
|
||||
"trueParameter": {
|
||||
"type": "bool",
|
||||
"defaultValue": true
|
||||
}
|
||||
},
|
||||
"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": {
|
||||
"stringOutput": {
|
||||
"type": "string",
|
||||
"value": "[parameters('storageAccountType')]"
|
||||
},
|
||||
"intOutput": {
|
||||
"type": "int",
|
||||
"value": "[parameters('intParameter')]"
|
||||
},
|
||||
"falseOutput": {
|
||||
"type": "bool",
|
||||
"value": "[parameters('falseParameter')]"
|
||||
},
|
||||
"trueOutput": {
|
||||
"type": "bool",
|
||||
"value": "[parameters('trueParameter')]"
|
||||
}
|
||||
}
|
||||
}
|
||||
DEPLOY
|
||||
parameters {
|
||||
dnsLabelPrefix = "terraform-test-%d"
|
||||
storageAccountType = "Standard_GRS"
|
||||
}
|
||||
deployment_mode = "Incremental"
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
// StorageAccount name is too long, forces error
|
||||
var testAccAzureRMTemplateDeployment_withError = `
|
||||
resource "azurerm_resource_group" "test" {
|
||||
|
@ -98,6 +98,7 @@ The following arguments are supported:
|
||||
The following attributes are exported:
|
||||
|
||||
* `id` - The Template Deployment ID.
|
||||
* `outputs` - 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).
|
||||
|
||||
## Note
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user