Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
961 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 Answer

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  
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...