Terraform bigtable 模块一次创建多个表

问题描述 投票:0回答:1

嗨,我正在使用下面提到的 terraform 来创建 bigtable 集群和表,我想一次创建多个表

模块

 resource "google_project_service" "gcp_services" {
  for_each = toset(var.gcp_service_list)
  project  = var.project_id
  service  = each.key
}

resource "google_bigtable_instance" "instance" {
  name                = var.bigtable_instance_name
  project             = var.project_id
  deletion_protection = var.deletion_protection
  labels              = var.labels

  cluster {
    cluster_id   = var.bigtable_cluster_name
    zone         = var.zone
    storage_type = var.bigtable_storage_type
    autoscaling_config {
      min_nodes  = var.min_nodes
      max_nodes  = var.max_nodes
      cpu_target = var.cpu_target
    }
  }

  lifecycle {
    prevent_destroy = false
  }

  depends_on = [
    google_project_service.gcp_services
  ]
}
    
  resource "google_bigtable_table" "table" {
  count = var.bigtable_count
  name = element(var.bigtable_table_name, count.index)
  instance_name = google_bigtable_instance.instance.name
  split_keys = [
    "a",
    "b",
    "c"]
  project = var.project_id

  lifecycle {
    prevent_destroy = false
  }

  column_family {
    family = lookup(var.family_type, element(var.bigtable_table_name, count.index ), "[]" )
  }
}

var 文件

variable "bigtable_count" {
  type = number
}
variable "family_type" {
  type = map(list(string))
  default = {
    "test-bigtable-tablename"= ["r", "s"]
    "test2-bigtable-tablename"= ["r", "o"]
  }
}

#错误

> Terraform v1.2.1
on linux_amd64
Initializing plugins and modules...
╷
│ Error: Invalid function argument
│
│   on ../../main.tf line 48, in resource "google_bigtable_table" "table":
│   48:     family = lookup(var.family_type, element(var.bigtable_table_name, count.index ), "[]" )
│
│ Invalid value for "default" parameter: the default value must have the same
│ type as the map elements.
╵
Operation failed: failed running terraform plan (exit 1)
terraform terraform-provider-gcp google-cloud-bigtable bigtable
1个回答
0
投票

您不需要在

[]
周围打问号。应该是:

lookup(var.family_type, element(var.bigtable_table_name, count.index ), [])
© www.soinside.com 2019 - 2024. All rights reserved.