Terraform을 사용하여 Global Active Table 배치

Terraform을 사용하여 OCI에서 Global Active Table을 쉽게 배포할 수 있습니다.

Terraform은 클라우드 및 온프레미스 리소스를 안전하고 효율적으로 구축, 변경 및 버전 관리할 수 있는 코드형 인프라 툴입니다. Terraform에 대한 기본적인 이해를 얻으려면 간단한 소개를 읽어보십시오. OCI Terraform 제공자 설치구성된 API 키 인증, 인스턴스 주체 권한 부여, 리소스 주체 권한 부여 및 보안 토큰 인증이 있는지 확인하십시오.

Global 테이블 배치 단계

아래의 terraform 스크립트는 다음을 수행합니다.

단계:

단계 1: 전역 활성 테이블에 대한 Terraform 구성 파일 생성: 전역 활성 테이블을 생성하려면 다음 구성 파일을 생성해야 합니다.

provider.tf: 이 파일에서는 OCI Terraform 제공자 정의 및 연관된 변수 정의를 제공합니다. OCI Terraform 제공자에는 region 인수만 필요합니다. 그러나 인증 방법을 기반으로 OCI 계정에 대한 인증 인증서를 사용하여 추가 인수를 구성해야 할 수도 있습니다.

OCI Terraform 제공자는 API 키 인증, 인스턴스 주체 권한 부여, 리소스 주체 권한 부여 및 보안 토큰 인증의 네 가지 인증 방법을 지원합니다.

API 키 인증을 사용하는 provider.tf의 예

variable "tenancy_ocid" {
}
variable "user_ocid" {
}
variable "fingerprint" {
}
variable "private_key_path" {
}
variable "region" {
}

provider "oci" {
   region = var.region
   tenancy_ocid = var.tenancy_ocid
   user_ocid = var.user_ocid
   fingerprint = var.fingerprint
   private_key_path = var.private_key_path
}

인스턴스 주체 권한 부여를 사용하는 provider.tf의 예

variable "region" {
}
provider "oci" {
  auth = "InstancePrincipal"
  region = var.region
}

리소스 주체 권한이 있는 provider.tf의 예

variable "region" {
}

provider "oci" {
  auth = "ResourcePrincipal"
  region = var.region
}

보안 토큰 인증을 사용하는 provider.tf의 예

variable "region" {
}
variable "config_file_profile" {
}
provider "oci" {
  auth = "SecurityToken"
  config_file_profile = var.config_file_profile
  region = var.region
}

nosql.tf:리소스는 Terraform 언어에서 가장 중요한 요소입니다. Terraform은 싱글톤 테이블, 인덱스 및 테이블 복제본을 리소스로 만듭니다. 이 파일에서는 Global Active Table 생성을 위한 NoSQL Terraform 구성 리소스 정의를 제공합니다. 아래 예제에서는 이 테이블의 지역 복제본을 추가하여 전역 활성 테이블을 만듭니다.

리소스 블록이 Terraform에서 구성되는 방식을 이해하려면 리소스 구문을 참조하십시오. 리소스 명령 구문에는 테이블 복제본인 리소스 oci_nosql_table_replica의 유형과 리소스 이름(예: replica_montreal)이 포함됩니다. Terraform 스크립트에서 리소스 이름을 정의하는 방법에 대한 자세한 내용은 식별자를 참조하십시오.

주: nosql.tf 스크립트에서 아래의 두 옵션(옵션 1 - 테이블의 OCID 사용 또는 테이블 이름 사용) 중 하나를 사용할 수 있습니다.

#Option 1 of adding a regional replica of the table
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"
}
# Option 2 of adding a regional replica of the table
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]
}

예제 nosql.tf 파일:

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"
}
#Add index resource "idx_age"
resource "oci_nosql_index" "idx_age" {
  table_name_or_id = oci_nosql_table.test_mrtable.id
  name = "idx_age"
  keys {
    column_name = "name"
  }
  keys {
    column_name = "info"
    json_path = "age"
    json_field_type = "anyatomic"
  }
}
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
  }
}
#add a regional replica
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"
}

주: 싱글톤 테이블(CREATE TABLE IF NOT EXISTS mr_test...)의 정의는 소스 테이블이 이미 있는 경우에도 항상 Terraform 스크립트에 포함되어야 합니다. Terraform 스크립트에서 CREATE TABLE 정의를 제거하면 해당 영역에서 테이블이 삭제됩니다.

terraform.tfvars:이 파일에서는 인증 방식을 기반으로 필요한 OCI Terraform 제공자 인수에 대한 값을 제공합니다.

API 키 인증을 사용하는 terraform.tfvars의 예:

tenancy_ocid = "<tenancy_your_ocid>"
user_ocid = "<your_user_ocid">
fingerprint = "your_fingerprint>"
private_key_path = "<path_private_key>"
compartment_ocid = "<your_compartment_ocid>"
region = "<name of your region>"

인스턴스 주체 권한 부여를 사용하는 terraform.tfvars의 예:

compartment_ocid = "<your_compartment_ocid>"
region = "<name of your region>"

리소스 주체 권한 부여를 사용하는 terraform.tfvars의 예:

compartment_ocid = "<your_compartment_ocid>"
region = "<name of your region>"

보안 토큰 인증을 사용하는 terraform.tfvars의 예:

compartment_ocid = "<your_compartment_ocid>"
region = "<name of your region>"
config_file_profile = "PROFILE"

주: 전체 구성 세부 정보를 추가할 수 있는 단일 terraform.tf 파일이 있을 수도 있지만, 명확성과 손쉬운 유지 관리를 위해 위와 같이 별도의 구성 파일을 사용하는 것이 좋습니다.

2단계: Terraform을 호출하고 설정을 초기화합니다.

terraform init

3단계:테라폼 스크립트를 호출하려면 다음 명령을 실행합니다.

terraform apply

Terraform은 적용할 계획을 표시하고 아래와 같이 확인 메시지를 표시합니다.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

확인 시 싱글톤 테이블이 생성되고 인덱스가 추가됩니다. 그런 다음 테이블의 지역 복제본이 만들어지고 싱글톤 테이블이 GAT로 변환됩니다.