I have a JSON template used for a resource in the terraform project. My problem is that I cannot successfully reference the value from a parameters block in my json template when it is deployed in Azure Portal logic app code view
For my resource (azapi_resource type Microsoft.Logic/workflows@2019-05-01, I have this body:
body = jsonencode({
properties = {
definition = jsondecode(templatefile("${path.module}/xyz.json",
{
.
.
uri = "https://****"
requestBody = var.params_obj
}))
parameters = {
.
.
uri = { value = "https://****" } #it is a string;
reqBody = { value = var.params_obj #it is an object
}
state = "Enabled"
}
})
In my variables.tf I have the var declared:
variable "params_obj" {
type = object({
pipeline = object({
calculation_date = string
name = string
abc = optional(object({
.
.
})
})
})
}
In my sample json xyz.json I have to reference the var.params_obj but is not working and it is putting in Logic App Code View as it is and not the Object values of my variable.
In my json sample xyz.json I tried to reference as below:
"inputs": {
"subscribe": {
"body": "${reqBody}" #not working; I tried also with "[parameters('reqBody')]" #I tried with another forms... not working;
,
"method": "POST",
"uri": "${uri}" #it works to reference the string uri value;
"unsubscribe": {}
My question is how to reference that reqBody correctly in my json template? because it is a bit strange.
My sample json contains definition and schema for Microsoft.Logic/workflows;
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#"
Since you didn't really provide a clear example that I could use to reproduce I have taken a guess at what you are trying to achieve and simplified the problem.
Assuming you want the request body as a valid json string in the template you need to use the
jsondecodefunction to turn the var into a json string before you try to use it in the templatemain.tf
template
OUTPUT
without using
jsondecodefunction and trying to pass the var directly to template I would get the error