# Pass terraform variable into json

**URL:** <https://discuss.hashicorp.com/t/pass-terraform-variable-into-json/43524>\
**Category:** Azure\
**Tags:** azure\
**Created:** [August 24, 2022, 10:28am UTC](https://discuss.hashicorp.com/t/pass-terraform-variable-into-json/43524 "2022-08-24T10:28:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![justigi](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/justigi/32/25792_2.png) [@justigi](https://discuss.hashicorp.com/u/justigi)\
**Post date:** [August 24, 2022, 10:28am UTC](https://discuss.hashicorp.com/t/pass-terraform-variable-into-json/43524/1 "2022-08-24T10:28:07Z")

</div>

Hi HCP fellas,  
I have a case where I need to create packer image following this [link](https://docs.microsoft.com/en-us/azure/developer/terraform/create-vm-scaleset-network-disks-using-packer-hcl)  
I want to perform all the steps with Terraform but I need to pass terraform variable into json file for the packer image.

In my case below doesn’t pass the variable into the json and I don’t know what I’m missing

> data “azuread\_client\_config” “current” {}

resource “azuread\_application” “packer” {  
display\_name = “test-packer-spn”  
owners = [data.azuread\_client\_config.current.object\_id]  
}

resource “azuread\_service\_principal” “example” {  
application\_id = azuread\_application.packer.application\_id  
app\_role\_assignment\_required = false  
owners = [data.azuread\_client\_config.current.object\_id]  
}  
resource “azuread\_service\_principal\_password” “example” {  
service\_principal\_id = azuread\_service\_principal.example.object\_id  
}

resource “azurerm\_resource\_group” “example” {  
name = “myPackerImages”  
location = “eastus”  
}

locals {  
data = jsondecode(file(“./ubuntu.json”))  
client\_id = “azuread\_application.packer.application\_id”  
client\_secret = “azuread\_service\_principal\_password.example.value”  
tenant\_id = “var.tenant\_id”  
subscription\_id = “var.subscription\_id”  
}

resource “null\_resource” “provisioner” {  
provisioner “local-exec” {  
command = “packer.exe build ${local.data}”  
}  
}

---

<div class="post-metadata">

**Author:** ![pavel-snyk](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/pavel-snyk/32/30093_2.png) [@pavel-snyk](https://discuss.hashicorp.com/u/pavel-snyk)\
**Post date:** [August 24, 2022, 1:39pm UTC](https://discuss.hashicorp.com/t/pass-terraform-variable-into-json/43524/2 "2022-08-24T13:39:37Z")

</div>

Hey fella 🙂,  
you could use `templatefile` function ([see an example here](https://spacelift.io/blog/terraform-templates#creating-json-files-using-templatefile)).
