JSONおよびCSVファイルをデコードするこのTerraformコードがあります
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
}
Terraform コードを実行すると、次のような出力が得られます。
# 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"
}
JSON および CSV ファイルの属性を保持し、テラフォームの文字列として変数に保存する方法はありますか? 次に、変数から新しいテラフォーム スクリプトを作成しますか?
私の最終目標は、JSON ファイルからテラフォーム スクリプトを作成することです。