使用 Terraform 更新全域作用中表格

您可以使用 Terraform 修改現有的「全域作用中表格」

新增區域複本

您可以新增現有「全域作用中表格」的區域複本。

在此範例中,Global Active 表格 mr_test 已經存在,且在加拿大東南部 (蒙特婁) 區域中有一個區域複本。若要在加拿大東南部 (多倫多) 另一個區域新增此表格的區域複本,請使用下列 nosql.tf 檔案來定義區域複本。

附註:

即使來源表格和複本已存在,單一表格 (CREATE TABLE IF NOT EXISTS mr_test...) 和現有複本的定義也必須一律包含在 terraform 命令檔中。從 terraform 命令檔移除 CREATE TABLE 定義會從區域刪除表格。同樣地,從 terraform 命令檔移除現有的複本定義會刪除區域表格複本。
variable "compartment_ocid" {
}
variable "table_ddl_statement" {
  default = "CREATE TABLE IF NOT EXISTS mr_test(id INTEGER,
             name STRING, info JSON,PRIMARY KEY(id))
             using TTL 10 days with schema frozen"
}
resource "oci_nosql_table" "mr_test" {
  #Required
  compartment_id = var.compartment_ocid
  ddl_statement  = var.table_ddl_statement
  name           = "mr_test"
  table_limits {
    #Required
    max_read_units = 51
    max_write_units = 51
    max_storage_in_gbs = 2     
  }
}
resource "oci_nosql_table_replica" "replica_montreal" {
  table_name_or_id = oci_nosql_table.mr_test.id
  region = "ca-montreal-1"
  #Optional
  max_read_units     = "60"
  max_write_units    = "60"
}
#add a regional replica
resource "oci_nosql_table_replica" "replica_toronto" {
  compartment_id = var.compartment_ocid
  table_name_or_id = "mr_test"
  region = "ca-toronto-1"  
  depends_on = [oci_nosql_table.mr_test]
}

請依照使用 Terraform 建立全域作用中表格中所述的相同步驟,在新區域中新增表格的區域複本。Terraform 會提示您新增新的複本資源。確認之後,Terraform 會新增「全域作用中」表格的新區域複本。

刪除區域複本

您可以刪除現有「全域作用中表格」的區域複本。

在此範例中,Global Active 表格 mr_test 已經存在,且在 Canada Southeast (Montreal) 和 Canada Southeast (Toronto) 區域中有複本。若要從加拿大東南部 (多倫多) 區域刪除複本,請使用下列 nosql.tf 檔案,您可在其中加註 (或移除) 加拿大東南部 (多倫多) 複本的相關程式碼。

附註:

即使來源表格已經存在,單一表格 (CREATE TABLE IF NOT EXISTS mr_test...) 的定義必須一律包含在 terraform 命令檔中。從 terraform 命令檔移除 CREATE TABLE 定義會從區域刪除表格。
variable "compartment_ocid" {
}
variable "table_ddl_statement" {
  default = "CREATE TABLE IF NOT EXISTS mr_test(id INTEGER,
             name STRING, info JSON,PRIMARY KEY(id))
             using TTL 10 days with schema frozen"
}
resource "oci_nosql_table" "mr_test" {
  #Required
  compartment_id = var.compartment_ocid
  ddl_statement  = var.table_ddl_statement
  name           = "mr_test"
  table_limits {
    #Required
    max_read_units = 51
    max_write_units = 51
    max_storage_in_gbs = 2     
  }
}
resource "oci_nosql_table_replica" "replica_montreal" {
  table_name_or_id = oci_nosql_table.mr_test.id
  region = "ca-montreal-1"
  #Optional
  max_read_units     = "60"
  max_write_units    = "60"
}
#resource "oci_nosql_table_replica" "replica_toronto" {
#  compartment_id = var.compartment_ocid
#  table_name_or_id = "mr_test"
#  region = "ca-toronto-1"  
#  depends_on = [oci_nosql_table.mr_test]
#}

請依照使用 Terraform 建立全域作用中表格中所述的相同步驟,從加拿大東南部 (多倫多) 區域刪除表格複本。Terraform 會提示複製 oci_nosql_table_replica.replica_toronto 正在銷毀。確認之後,Terraform 將會刪除「全域作用中」表格的區域複本。

變更「全域作用中表格」的表格容量

您可以使用 Terraform 變更「全域作用中」表格的讀取單位、寫入單位、儲存容量以及表格 TTL。

在「全域作用中」表格中,變更讀取容量限制或寫入容量限制只會套用至變更它的本機區域。不過,變更儲存容量或變更預設表格層次 TTL 值會將變更套用至表格的所有區域複本。

若要變更 mr_test 表格的表格容量,請使用下列 nosql.tf 檔案來變更表格特性 (預設表格 TTL) 以及變更表格限制。
variable "compartment_ocid" {
}

variable "table_ddl_statement" {
  default = "CREATE TABLE IF NOT EXISTS mr_test(id INTEGER,
            name STRING, info JSON,PRIMARY KEY(id))
            using TTL 15 days with schema frozen"
}
resource "oci_nosql_table" "mr_test" {
  #Required
  compartment_id = var.compartment_ocid
  ddl_statement  = var.table_ddl_statement
  name           = "mr_test"
  table_limits {
    #Required
    max_read_units = 60
    max_write_units = 60
    max_storage_in_gbs = 2     
  }
}
resource "oci_nosql_table_replica" "replica_montreal" {
  table_name_or_id = oci_nosql_table.mr_test.id
  region = "ca-montreal-1"
}
resource "oci_nosql_table_replica" "replica_toronto" {
  compartment_id = var.compartment_ocid
  table_name_or_id = "mr_test"
  region = "ca-toronto-1"  
  depends_on = [oci_nosql_table.mr_test]
}
請依照與使用 Terraform 建立全域作用中表格中所述的相同步驟進行,並依照上述修改的 nosql.tf 檔案進行。

附註:

「全域作用中」表格包含對稱表格定義,包括所有區域複本中的綱要、索引、TTL 以及儲存體大小。如果您變更一個區域複本中的索引、TTL 或儲存體大小,則會自動套用至所有其他區域複本。因此建議您僅從一個區域管理這些表格定義。

編輯單一區域複本的表格容量

使用 Terraform 時,您無法直接編輯區域表格複本的容量。

例如,您無法直接使用 Terraform 在加拿大東南部 (多倫多) 區域中變更複本的讀取單位和寫入單位。在此情況下,您必須先匯入表格資源,然後變更限制,如下方範例所示。

附註:

即使來源表格已經存在,單一表格 (CREATE TABLE IF NOT EXISTS mr_test...) 的定義必須一律包含在 terraform 命令檔中。從 terraform 命令檔移除 CREATE TABLE 定義會從區域刪除表格。
#Table has been created on ca-montreal-1
#update table read/write units to 100/100
resource "oci_nosql_table" "mr_test" {
  #Required
  compartment_id = var.compartment_ocid
  ddl_statement  = "CREATE TABLE IF NOT EXISTS mr_test(id INTEGER,
                    name STRING, info JSON, PRIMARY KEY(id))
                    with schema frozen"
  name           = "mr_test"
  table_limits {
    #Required
    max_read_units     = "100"
    max_write_units    = "100"
    max_storage_in_gbs = "1"
  }
}

#Run terraform import 
#Import table on ca-montreal-1 to bring it under Terraform management
$terraform import oci_nosql_table.mr_test <OCID>
$terraform apply

Terraform shows the plan to be applied and prompts for confirmation as shown below.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.