I am using terraform resource google_firestore_document to create firestor document db and i was abel to create it successfully. I am trying to convert it to a module for which I need to build the values in jsonencode format. example:
` + fields = jsonencode(
{
+ akey = {
+ stringValue = "avalue"
}
+ createdBy = {
+ stringValue = "xyz"
}
}
)`
I have created a variable as below.
`variable "fields" {
description = "field details"
default = {"fname":{"stringValue":"xyz"}}
}`
and main.tf is:
` resource "google_firestore_document" "default" {
project = "var.project"
collection = "var.collection"
document_id = "var.document_id"
fields = jsonencode({ fields = var.fields})
}`
output is and it is not correct.
` + fields = jsonencode(
{
+ fields = {
+ fname = {
+ stringValue = "xyz"
}
}
}
)`
I tried to build with fields = jsonencode({var.fields})
but it says
Expected an equals sign ("=") to mark the beginning of the attribute value
Please let me know how can we achieve it without two fields section.