English 中文(简体)
理解住宿的条件
原标题:Struggling to understand FOR loop

The following code successfully deploys 2 x log analytic workspaces in different regions in azure in their own region based resource groups

我在努力理解这一 FOR木工程如何运作

是否有人能够打断。 我研究了正式文件,但我仍然看不到。

感谢

locals.tf

locals {
  resource_groups = {
    for k, v in var.workspaces : k => {
      location = v.location
    }
  }
}

main.tf

resource "azurerm_resource_group" "workspaces" {
  for_each = local.resource_groups

  name     = each.key
  location = each.value.location
}

resource "azurerm_log_analytics_workspace" "workspaces" {
  for_each = var.workspaces

  name                = each.key
  location            = each.value.location
  resource_group_name = azurerm_resource_group.workspaces[each.key].name
  sku                 = "PerGB2018"
  retention_in_days   = each.value.retention_in_days
}

variables.tf

variable "workspaces" {
  type = map(object({
    location          = string
    retention_in_days = number
  }))
  default = {
    workspace1 = {
      location          = "australiasoutheast"
      retention_in_days = 30
    }
    workspace2 = {
      location          = "australiaeast"
      retention_in_days = 30
    }
    # Add more workspaces as needed
  }
}

outputs.tf

# Define outputs
output "workspace_ids" {
  value = azurerm_log_analytics_workspace.workspaces[*].id
}

output "workspace_names" {
  value = azurerm_log_analytics_workspace.workspaces[*].name
}

output "resource_group_ids" {
  value = azurerm_resource_group.workspaces[*].id
}

output "resource_group_names" {
  value = azurerm_resource_group.workspaces[*].name
}

output "resource_group_locations" {
  value = azurerm_resource_group.workspaces[*].location
}
问题回答

页: 1 它没有任何用处,但从<代码>var.workspaces上删除了<代码>retention_in_days。 通常使用<代码>var.workspaces 直接:

resource "azurerm_resource_group" "workspaces" {
  for_each = local.workspaces

  name     = each.key
  location = each.value.location
}




相关问题
Windows Azure WorkerRole response

I am working on an Azure demo to run Powershell in a worker role. In my web role I add the name of the Powershell script which is to be run to a CloudQueue object. I can print the script output to ...

Windows Azure WebRole stuck in a deployment loop

I ve been struggling with this one for a couple of days now. My current Windows Azure WebRole is stuck in a loop where the status keeps changing between Initializing, Busy, Stopping and Stopped. It ...

Getting a token for Windows Azure

We are looking at Windows Azure, but getting a token appears to be hard now, at least that s what I m seeing in web searches. Anyone tried it or know how to accelerate that process? Any idea how long ...

Developing Azure .Net 4.0 Applications

Presently .Net 4.0 is not supported on Azure. This thread indicates that you will not be able to use .Net 4.0 with VS 2010 until it is supported in the cloud. http://social.msdn.microsoft.com I d ...

.NET 4.0 on Windows Azure?

My google-fu is failing me on this one. As a possible solution to Unit Testing .NET 3.5 projects using MStest in VS2010 (but I ve put this in a seperate question because it s kind of unrelated): Is ...

热门标签