ARM Template Deployment DataType Mismatch

I am attempting to deploy a resource using an ARM template.

here is my main.tf:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "2.41.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "resourcegroup" {
  location = "North Central US"
  name     = "test"
}

resource "azurerm_resource_group_template_deployment" "deployment" {
  name                = "test-${formatdate("YYYYMMDDhhmmss", timestamp())}"
  resource_group_name = azurerm_resource_group.resourcegroup.name
  deployment_mode     = "Incremental"
  template_content    = file("template.json")
  parameters_content = templatefile("parameters.json",
    {
      name = "vwtuvnpplzgelqey"
      supportsHttpsTrafficOnly = true
    }
  )
}

Here is the ARM template file:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string"
		},
		"supportsHttpsTrafficOnly": {
			"type": "bool"
		}
	},
    "variables": {},
    "resources": [
		{
		  "type": "Microsoft.Storage/storageAccounts",
		  "apiVersion": "2019-04-01",
		  "name": "[parameters('name')]",
		  "location": "northcentralus",
		  "sku": {
			"name": "Standard_LRS"
		  },
		  "kind": "StorageV2",
		  "properties": {
			"supportsHttpsTrafficOnly": "[parameters('supportsHttpsTrafficOnly')]"
		  }
		}
	]
}

Here is the parameters file:

{
    "name": {
        "value": "${name}"
    },
    "supportsHttpsTrafficOnly": {
        "value": "${supportsHttpsTrafficOnly}"
    }
}

When do a terraform apply, it fails with the following error:

: Code="InvalidTemplate" Message="Deployment template validation failed: 'Template parameter JToken type is not valid. Expected 'Boolean'. Actual 'String'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'." AdditionalInfo=[{"info":{"lineNumber":1,"linePosition":213,"path":"properties.template.parameters.supportsHttpsTrafficOnly"},"type":"TemplateViolation"}]

The error indicates that the supportsHttpsTrafficOnly parameter is a string, but it is clearly defined as a bool in the parameters. I am not sure why it is being treated as a string.

Hi. Can you get a peek at the resulting complete ARM template file? An educated guess could be TF is putting “” around true? According to the spec that would be treated as a string and invalid for a bool: Template structure and syntax - Azure Resource Manager | Microsoft Docs

I’m not certain if this will solve the problem, but its worth seeing as reference. In your main.tf, it appears that you may have the parameters_content incorrect. See this blog post, it may help.

1 Like

It turns out this is actually an easy fix, if not an obvious one.

Apparently all parameters need to be defined as string and then use the template conversion functions to convert to the correct value.

In the template.json, we would have this in the parameters section:

“supportsHttpsTrafficOnly”: {
“type”: “string”
}

And then in the resources section, convert the string to a boolean using a template conversion:

"properties": {
	"supportsHttpsTrafficOnly": "[bool(parameters('supportsHttpsTrafficOnly'))]"
}

Then finally in main.tf, pass the value as a string:

  parameters_content = templatefile("parameters.json",
    {
      name = "vwtuvnpplzgelqey"
      supportsHttpsTrafficOnly = "true"
    }