depends_on "A static list expression is required."

depends_on "A static list expression is required."

我在创建对象存储时使用带有条件检查的 depends_on 块。令人惊讶的是,我看到了以下错误。关于如何解决它的任何指示?

代码:

locals {
        is_gov = local.realm == "oc2" || local.realm == "oc3" ? true : false
    }
    

resource "oci_identity_compartment" "gov_comp" {
  compartment_id = var.comp1
  description    = "GOV COMP"
  name           = "gov_comp"

  defined_tags  = { "Operations.CostCenter" = "001" }
  freeform_tags = { "Department" = "Executives" }
}

resource "oci_identity_compartment" "non_gov_comp" {
  compartment_id = var.comp3
  description    = "commerical comp"
  name           = "non_gov_cmop"

  defined_tags  = { "Operations.CostCenter" = "000" }
  freeform_tags = { "Department" = "Non-Executives" }
}

resource "oci_objectstorage_bucket" "test_bucket" {
  compartment_id = var.compartment_id
  name           = var.bucket_name
  namespace      = var.bucket_namespace

  depends_on = is_gov ? [oci_identity_compartment.gov_comp] : [oci_identity_compartment.non_gov_comp]
}


Error:

depends_on = local.is_gov ? [oci_identity_compartment.gov_comp] : [   
   
A static list expression is required.  

您的 gov_compnon_gov_comp 总是一起创建的。它们不是排他性的。因此,您的 test_bucket 应该在创建这两个资源时创建:

resource "oci_objectstorage_bucket" "test_bucket" {
  compartment_id = var.compartment_id
  name           = var.bucket_name
  namespace      = var.bucket_namespace

  depends_on = [oci_identity_compartment.gov_com, oci_identity_compartment.non_gov_comp]
}