1

So the idea is to create resource health alert for multiple storage accounts using terraform. It's fairly simple for one storage account as one would pass the value

output "id" {
description = "Id of the storage account created."
value       = azurerm_storage_account.storage.id
    } 

to the resource_id or hardcode the resource id with the resource actual id. But my ask here is how I can setup one single alert block for all the storage accounts provisioned by the terraform. I have been trying to use the above data block but the name variable would take only strings. Please provide a sample example as to how you would do it.

locals {
  activity_log_alerts = {
      resource_health_alerts= {
      environment         = var.environment
      resource_group_name = var.rgp
      enabled             = "true"
     ** scopes           = module.main.storage_account_name["storage_name"] **
      alert_name     = “Resource health alert for storage accounts”
      description    = format(“The state of the azure resource is unknown”}
      category       = "ResourceHealth"
      level          = "Critical"
      operation_name = null
      resource_health = [
        {
          current  = ["Unknown"]
          previous = ["Available"]
          reason   = ["PlatformInitiated"]
        }
      ]

The error I received is this: Error: Null value found in list

scopes = tolist([var.resource_id])

UPDATE: Another Approach With this approach I was hoping to get all the resource under the same RG and subscription but got the same error

data "azurerm_subscription" "current" {

  subscription_id = var.subscription_id
}

locals {
      activity_log_alerts = {
          resource_health_alerts= {
          environment         = var.environment
          resource_group_name = var.rgp
          enabled             = "true"
          scopes             = [data.azurerm_subscription.current.id]
          alert_name     = “Resource health alert for storage accounts”
          description    = format(“The state of the azure resource is unknown”}
          category       = "ResourceHealth"
          level          = "Critical"
          operation_name = null
          resource_health = [
            {
              current  = ["Unknown"]
              previous = ["Available"]
              reason   = ["PlatformInitiated"]
            }
          ]
The error I received is this: Error: Null value found in list

scopes              = tolist([var.resource_id])
JohnDoe27
  • 11
  • 2
  • Nope, that is not how this will work. You have to provide the code you have and what you have tried. – Marko E Apr 09 '22 at 11:35
  • @MarkoE I have updated my questions. I am still very new to terraform therefore let me know if anything else is required – JohnDoe27 Apr 09 '22 at 18:02
  • Can you add `var.resource_id` definition as well as values you are passing to it? – Marko E Apr 10 '22 at 06:21
  • Do you mean the literal value as URI of the resource? I am trying to get all the storage accounts under the scope . – JohnDoe27 Apr 10 '22 at 06:59
  • Not sure I understand. If that is a sensitive value you don't have to provide it, but the variable definition would be good. – Marko E Apr 10 '22 at 09:40

0 Answers0