0

我想用下一种方式调用 terraform 模块:

module "database_role" {
source = "modules/roles"

project_id = "testid"
role_name = "testrole"

  actions = {
    action: ["ENABLE_PROFILER", "DROP_DATABASE"]
    database_name: ["test_db", test_db_2"]
  }

我创建的角色模块定义是:

resource "mongodbatlas_custom_db_role" "custom_role" {
  project_id = "xxx-xxx"
  role_name  = "yyy-yyy"

  dynamic "actions" {
    for_each = flatten([
      for item in range(length(local.actions["action"])): {
        act = local.actions["action"][item]
        db_name = local.actions.database_name
      }
     ])
     content {
       action = actions.value.act
       resources {
         cluster = "false"
         database_name = actions.value.db_name
       }
     }
   }
 }

结果我想看到正确生成的 4 个动作(每个数据库定义了角色 2):

  actions {
    action = "ENABLE_PROFILER"
    resources {
      cluster         = "false"
      database_name   = "test_db"
    }
  }


  actions {
    action = "DROP_DATABASE"
    resources {
      cluster         = "false"
      database_name   = "test_db"
    }
  }

  actions {
    action = "ENABLE_PROFILER"
    resources {
      cluster         = "false"
      database_name   = "test_db_2"
    }
  }


  actions {
    action = "DROP_DATABASE"
    resources {
      cluster         = "false"
      database_name   = "test_db_2"
    }
  }

我收到错误:给定的键未标识此集合值中的元素。我在模块动态资源中做错了什么?谢谢

4

0 回答 0