首页 > 解决方案 > Terrafrom Dynamic block with tags

问题描述

Terraform Variable file 
    ---- Variable File ----
    variable "vm_tags" {
    type = map(string)
    default = {
    "owner" = "abc",
    "Env"   = "Prod"
     }
     }

-----------------------------------------------------------------------------
---- main.tf ----
     dynamic "tags" {
     for_each = var.vm_tags
     content{
     tags.key = tags.value
        }
     }
   
---------------------------------------------------------------

Below is the error i am getting while terraform plan

    Error: Argument or block definition required

on main.tf line 45, in resource "azurerm_windows_virtual_machine" "myvm": tags.key = tags.value

An argument or block definition is required here. To set an argument, use the
equals sign "=" to introduce the argument value.

Tags count will be dynamic 

标签: azureterraform

解决方案


这里不需要做动态块。Terraform 期望tags是一张地图,而您的 tags 变量是一个map. 您可以通过以下方式直接使用地图: tags = var.vm_tags


推荐阅读