Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

azure - Terraform dynamic block with for_each

Need suggestion. I am trying to run the below code. First adf is imported which has the vsts configuration. For second adf, i dont need the vsts configuration. I have tried using dymanic block, but getting error as below.

on main.tf line 16, in resource "azurerm_data_factory" "adf": 2020-12-24T08:13:44.3101544Z 16: dynamic [4m"action"

[0m { 2020-12-24T08:13:44.3101802Z [0m 2020-12-24T08:13:44.3102076Z Blocks of type "action" are not expected here.

Main.tf

resource "azurerm_data_factory" "adf"{

for_each = var.purposes
name=lower("${var.component}-${var.project}-${var.regionname}-${var.azureregion}-${var.environment}-${each.value.purpose}")

  location            = data.azurerm_resource_group.rg.location
  resource_group_name = data.azurerm_resource_group.rg.name
 

  identity{
    
    type="SystemAssigned"
    
    
  }

  dynamic "action" {
  for_each = var.vsts_config ? [1] : []
  
content {

  vsts_configuration {
    
    account_name = var.accountname
    branch_name = var.branchname
    project_name = var.projectname
    repository_name = var.repository
    tenant_id       = "__tenantId__"
    root_folder     = var.rootfolder

    }
  
}


  }

}

input.tfvars
purposes = {
  a =  {
        purpose = "load",
        
    }
  b =  {
        purpose = "live",
      
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

action is not a valid block in azurerm_data_factory. If you want to make vsts_configuration block optional, then you code should be:

dynamic "vsts_configuration" {

    for_each = var.vsts_config ? [1] : []
  
    content {
        account_name    = var.accountname
        branch_name     = var.branchname
        project_name    = var.projectname
        repository_name = var.repository
        tenant_id       = "__tenantId__"
        root_folder     = var.rootfolder  
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...