'Create azure Action group with azure terraform with json format
Hi i am trying to create "azurerm_monitor_action_group" based on json format i have github_link please go through the github link and update me changes which i missed..
Solution 1:[1]
Tried with your code was getting the same error.
Solution :
The reason you are seeing the error is because jsonencode
returns a string, when for_each
expects a map or a set. Instead of using jsonencode
, use Terraform's map directly.
You can use this below code for me terraform plan
is succesful while terraform apply
getting error as email
is not valid for me. You can test the same in your enviorment it will succesfully apply for you.
main.tf
############## azurerm provider ######################################
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.99.0"
}
}
}
provider "azurerm" {
subscription_id = var.subscription_id
tenant_id = var.tenant_id
# client_id = var.client_id
# client_secret = var.client_secret
features {
}
}
###################
locals {
our_widgets = {
"dashboard1" ={
"type": "sbns",
"sme": ["[email protected]","[email protected]"],
"tech_support": ["[email protected]","[email protected]"],
"primary_support": ["[email protected]","[email protected]"],
"secondary_support": ["[email protected]","[email protected]"],
"all": ["[email protected]","[email protected]"]
},
"dashboard2" ={
"type": "sta",
"sme": ["[email protected]","[email protected]"],
"tech_support": ["[email protected]","[email protected]"],
"primary_support": ["[email protected]","[email protected]"],
"secondary_support": ["[email protected]","[email protected]"]
},
"dashboard3" ={
"type": "kv",
"sme": ["[email protected]","[email protected]"],
"tech_support": ["[email protected]","[email protected]"],
"primary_support": ["[email protected]","[email protected]"],
"secondary_support": ["[email protected]","[email protected]"]
},
"dashboard3"={
"type": "redis",
"sme": ["[email protected]","[email protected]"],
"tech_support": ["[email protected]","[email protected]"],
"primary_support": ["[email protected]","[email protected]"],
"secondary_support": ["[email protected]","[email protected]"]
},
"dashboard5"={
"type": "postgres",
"sme": ["[email protected]","[email protected]"],
"tech_support": ["[email protected]","[email protected]"],
"primary_support": ["[email protected]","[email protected]"],
"secondary_support": ["[email protected]","[email protected]"]
}
}
}
############################
########## Creating ResourceGroup #######################
data "azurerm_resource_group" "rg" {
name = "v-rXXXXXe"
#location = "westus"
}
##################################
resource "azurerm_monitor_action_group" "monitor_action_group" {
#for_each = local.resource
name = "test4574365"
resource_group_name = data.azurerm_resource_group.rg.name
short_name = "short-alert"
dynamic "email_receiver" {
for_each = local.our_widgets
content {
name = "Email"
email_address = "email_receiver.value.primary_support" # here it is not working
use_common_alert_schema = true #Enables or disables the common alert schema
}
}
}
For more information you can refer this link
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | RahulKumarShaw-MT |