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..
Asked
Active
Viewed 687 times
-1
-
what is the error you are getting ? – RahulKumarShaw Apr 19 '22 at 09:56
-
1Hi @RahulKumarShaw-MT error i am getting is "Can't access attributes on a primitive-typed value (string)." – Venki Apr 19 '22 at 10:55
-
Please check this it may help you :https://github.com/avinor/terraform-azurerm-monitor-action-group – RahulKumarShaw Apr 20 '22 at 12:22
1 Answers
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": ["sme1@bechtel.com","sme2@bechtel.com"],
"tech_support": ["tech1@bechtel.com","tech2@bechtel.com"],
"primary_support": ["primary@bechtel.com","primary2@bechtel.com"],
"secondary_support": ["secondary1@bechtel.com","secondary2@bechtel.com"],
"all": ["all1@bechtel.com","all2@bechtel.com"]
},
"dashboard2" ={
"type": "sta",
"sme": ["sme1@bechtel.com","sme2@bechtel.com"],
"tech_support": ["tech1@bechtel.com","tech2@bechtel.com"],
"primary_support": ["primary@bechtel.com","primary2@bechtel.com"],
"secondary_support": ["secondary1@bechtel.com","secondary2@bechtel.com"]
},
"dashboard3" ={
"type": "kv",
"sme": ["sme1@bechtel.com","sme2@bechtel.com"],
"tech_support": ["tech1@bechtel.com","tech2@bechtel.com"],
"primary_support": ["primary@bechtel.com","primary2@bechtel.com"],
"secondary_support": ["secondary1@bechtel.com","secondary2@bechtel.com"]
},
"dashboard3"={
"type": "redis",
"sme": ["sme1@bechtel.com","sme2@bechtel.com"],
"tech_support": ["tech1@bechtel.com","tech2@bechtel.com"],
"primary_support": ["primary@bechtel.com","primary2@bechtel.com"],
"secondary_support": ["secondary1@bechtel.com","secondary2@bechtel.com"]
},
"dashboard5"={
"type": "postgres",
"sme": ["sme1@bechtel.com","sme2@bechtel.com"],
"tech_support": ["tech1@bechtel.com","tech2@bechtel.com"],
"primary_support": ["primary@bechtel.com","primary2@bechtel.com"],
"secondary_support": ["secondary1@bechtel.com","secondary2@bechtel.com"]
}
}
}
############################
########## 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

RahulKumarShaw
- 4,192
- 2
- 5
- 11