I have this Terraform code that decodes a JSON and CSV file.
provider "azurerm" {
features{}
}
locals {
resource_groupname = csvdecode(file("./ResourceTypes.csv"))
json_data = jsondecode(file("${path.module}/Monitor.json"))
}
resource "azurerm_resource_group" "Main" {
count = length(local.resource_groupname)
name = local.resource_groupname[count.index].resourcetype
location = "North europe"
}
resource "azurerm_resource_group" "name" {
# (other settings)
name = local.json_data.name
location = "North europe"
}
output "local_json_data" {
value = local.json_data
}
when I run the terraform code I have the output as below
# azurerm_resource_group.Main[212] will be created
+ resource "azurerm_resource_group" "Main" {
+ id = (known after apply)
+ location = "northeurope"
+ name = "Wandisco.Fusion"
}
# azurerm_resource_group.name will be created
+ resource "azurerm_resource_group" "name" {
+ id = (known after apply)
+ location = "northeurope"
+ name = "Azure-APIManagement-FailedRequests"
}
Plan: 214 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ local_json_data = {
+ classification = "anomaly"
+ id = 16020941
+ message = <<-EOT
Azure - API Management - Failed Requests
{{name.name}} exceeds the previously estimated average.
Please refer to the following reaction process:
https://apptemetry/knowledgebase/Article.aspx?id=54321
Alerts generate an AIM ticket, viewable here (search via CI or Alert Name):
https://apptemetry/AIM/alertsearch.aspx
EOT
+ name = "Azure-APIManagement-FailedRequests"
+ options = {
+ escalation_message = ""
+ include_tags = true
+ locked = false
+ new_host_delay = 300
+ no_data_timeframe = null
+ notify_audit = false
+ notify_no_data = false
+ renotify_interval = 0
+ require_full_window = true
+ silenced = {}
+ threshold_windows = {
+ recovery_window = "last_15m"
+ trigger_window = "last_15m"
}
+ thresholds = {
+ critical = 1
+ critical_recovery = 0
}
+ timeout_h = 1
}
+ priority = null
+ query = "avg(last_4h):anomalies(avg:azure.apimanagement_service.failed_requests{*} by {name}, 'agile', 2, direction='above', alert_window='last_15m', interval=60, count_default_zero='true', seasonality='hourly') >= 1"
+ tags = [
+ "Sev:54",
]
+ type = "query alert"
}
Is there a way I can hold the attributes from the JSON and CSV file, and save it to a variable as a string in terraform? and then make a new terraform script from the variables?
My end goal is to try and create a terraform script from a JSON file.