使用 Terraform 和 OCI 資源管理程式部署 Oracle NoSQL 表格
使用 Terraform 和資源管理程式的堆疊在 OCI (Oracle Cloud Infrastructure) 上輕鬆部署 NDCS 表格。我們將使用 OCI 資源管理程式 CLI 在 Oracle Cloud 上部署 NDCS 表格。在繼續本文之前,假設您瞭解 NoSQL Cloud Service 並瞭解其基本知識以及 Terraform。
Terraform 使用提供者連接 Terraform 引擎與支援的雲端平台。Oracle Cloud Infrastructure (OCI) Terraform 提供者是一個元件,可將 Terraform 連線至您要管理的 OCI 服務。您可以使用 OCI Terraform 提供者,包括 Terraform Cloud 和 OCI 資源管理程式。
OCI 資源管理程式是以 Terraform 為基礎的 Oracle 管理服務,使用 Terraform 組態檔將 OCI Terraform 提供者支援的 OCI 資源部署和作業自動化。資源管理程式可讓您跨多個團隊和平台共用及管理基礎架構組態和狀態檔案。
- 若要在 OCI 中建立資源,我們需要設定 terraform。建立 terraform 提供者定義、NoSQL 資源定義、認證以及輸入變數的基本 terraform 組態檔。
- 決定地形配置檔的儲存位置。您可以將這些檔案儲存在不同的來源,例如本機資料夾或壓縮檔、物件儲存的儲存桶,以及來源控制系統,例如 GitHub 或 GitLab。
- 執行「資源管理程式 CLI」命令以執行下列作業:
- 建立堆疊。
- 產生並複查執行計畫。
- 執行「套用」工作以啟動設定 NoSQL 資源。
- 視需要檢視日誌檔。
附註:
我們將使用 Oracle Cloud Infrastructure (OCI) 資源管理程式命令行介面 (CLI),並使用主控台在 Cloud Shell 中執行這些命令。這表示您需要一些關於雲端租用戶和其他項目的相關資訊,例如公鑰或私鑰對。若要在您的本機機器上設定 OCI CLI,請參閱此文件。本文包含下列主題:
子步驟 1.1:建立 OCI Terraform 提供者組態
建立一個名為 "provider.tf
" 的新檔案,其中包含 OCI Terraform 提供者定義以及關聯的變數定義。OCI Terraform 提供者只需要 region
引數。
- API 金鑰認證
- 執行處理主體授權
- 安全權杖認證
region
引數指定在其中建立提供者資源的地理區域。若要以單一組態鎖定多個區域,您只需為每個區域建立提供者定義,然後使用提供者別名來區分,如下列範例所示。請注意,僅定義一個名為 "oci
" 的提供者,但針對 us-phoenix-1
區域 (別名為 "phx
") 輸入兩次 oci 提供者定義,並為區域 us-ashburn-1
輸入一次 (別名為 "iad
")。provider "oci" {
region = "us-phoenix-1"
alias = "phx"
}
provider "oci" {
region = "us-ashburn-1"
alias = "iad"
}
region
引數。API 金鑰認證需要 tenancy_ocid
、user_ocid
、private_key_path
和 fingerprint
引數。您可以提供 region
和 API 金鑰認證金鑰 (tenancy_ocid
、user_ocid
、private_key_path
和 fingerprint
) 的值作為環境變數,或在 Terraform 組態變數內 (如子步驟 1.3:載入 Terraform 組態變數中所述)。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
}
tenancy_ocid
、user_ocid
、private_key_path
及 fingerprint
屬性。
附註:
執行處理主要授權僅適用於在 Oracle Cloud Infrastructure 中執行的執行處理。region
引數,而執行處理主體授權需要 auth
引數。您可以提供 region
引數的值作為「環境變數」或 Terraform 組態變數 (如子步驟 1.3:載入 Terraform 組態變數中所述)。variable "region" {
}
provider "oci" {
auth = "InstancePrincipal"
region = var.region
}
附註:
此權杖會在 1 小時後到期。佈建資源的時間超過 1 小時,請勿使用此認證方法。如需詳細資訊,請參閱重新整理記號。region
是 OCI Terraform 提供者的必要引數。Security Token 認證需要 auth
和 config_file_profile
引數。
variable "region" {
}
variable "config_file_profile" {
}
provider "oci" {
auth = "SecurityToken"
config_file_profile = var.config_file_profile
region = var.region
}
子步驟 1.2:建立 NoSQL Terraform 組態
建立一個名為 "nosql.tf
" 的新檔案,其中包含用於建立 NoSQL Database Cloud Service 表格或索引的 NoSQL terraform 組態資源。如需有關 NoSQL 資料庫資源和資料來源的詳細資訊,請參閱 oci_nosql_table 。
compartment_ocid
引數。您可以提供 compartment_ocid
的值作為環境變數或 Terraform 組態變數 (如子步驟 1.3:載入 Terraform 組態變數中所述)。variable "compartment_ocid" {
}
resource "oci_nosql_table" "nosql_demo" {
compartment_id = var.compartment_ocid
ddl_statement = "CREATE TABLE if not exists demo (ticketNo INTEGER, fullName STRING, contactPhone STRING, confNo STRING, gender STRING, bagInfo JSON, PRIMARY KEY (ticketNo))"
name = "demo"
table_limits {
max_read_units = var.table_table_limits_max_read_units
max_storage_in_gbs = var.table_table_limits_max_storage_in_gbs
max_write_units = var.table_table_limits_max_write_units
}
}
resource "oci_nosql_table" "nosql_demoKeyVal" {
compartment_id = var.compartment_ocid
ddl_statement = "CREATE TABLE if not exists demoKeyVal (key INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 NO CYCLE), value JSON, PRIMARY KEY (key))"
name = "demoKeyVal"
table_limits {
max_read_units = var.table_table_limits_max_read_units
max_storage_in_gbs = var.table_table_limits_max_storage_in_gbs
max_write_units = var.table_table_limits_max_write_units
}
}
子步驟 1.3:載入 Terraform 組態變數
下一步是建立名為 "terraform.tfvars
" 的檔案,並根據認證方法提供必要的 OCI Terraform 提供者引數值。
提供 IAM 存取和秘密金鑰 (tenancy_ocid
、user_ocid
、private_key_path
和 fingerprint
)、region
和 compartment_ocid
引數的值。您應該已經有具備加密密碼和存取金鑰的 OCI IAM 使用者具備 NoSQL Database Cloud Service 的足夠權限。取得這些金鑰並將它們儲存到檔案中 。
tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaaqljdu37xcfoqvyj47pf5dqutpxu4twoqc7hukwgpbavpdwkqxc6q"
user_ocid = "ocid1.user.oc1..aaaaaaaafxz473ypsc6oqiespihan6yi6obse3o4e4t5zmpm6rdln6fnkurq"
fingerprint = "2c:9b:ed:12:81:8d:e6:18:fe:1f:0d:c7:66:cc:03:3c"
private_key_path = "~/NoSQLLabPrivateKey.pem"
compartment_ocid = "ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya"
region = "us-phoenix-1"
提供 region
和 compartment_ocid
引數的值。
region = "us-phoenix-1"
compartment_ocid = "ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya"
提供 region
、compartment_ocid
和 config_file_profile
引數的值。
region = "us-phoenix-1"
compartment_ocid = "ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya"
config_file_profile = "PROFILE"
子步驟 1.4:宣告輸入變數
variables.tf
",並將值指派給其中的輸入變數。按一下此處以參閱 Terraform 文件,檢查 NoSQL 資料庫可用的有效引數或特性。在此範例中,NoSQL 表格的讀取、寫入和儲存單位預設值分別設為 10
、10
和 1
。variable "table_table_limits_max_read_units" {
default = 10
}
variable "table_table_limits_max_write_units" {
default = 10
}
variable "table_table_limits_max_storage_in_gbs" {
default = 1
}
我們使用主控台的 Cloud Shell 建立了提供者定義、NoSQL 資料庫資源、認證值及輸入變數的所有必要 terraform 組態檔。
步驟 2:儲存 Terraform 組態的位置
使用「資源管理程式」建立堆疊時,您可以從下列來源選取 Terraform 組態。
- 本機 .zip 檔案
- 本機資料夾
- Object Storage 貯體
在關聯堆疊上執行的任何工作都會自動使用儲存桶的最新內容。
- 原始程式碼控制系統,例如 GitHub 和 GitLab
在關聯堆疊上執行的任何工作都會自動使用最新版本的組態。
- 樣板 (Oracle 或專用樣板的預先建立 Terraform 組態)
- 現有區間 ( 資源探索 )
子步驟 2.1:建立遠端 Terraform 組態的組態來源提供者
若要使用由來源控制系統代管的遠端地形組態,例如 GitHub 和 GitLab,您必須建立來源組態提供者。
如需如何為遠端 Terraform 組態建立組態來源提供者的詳細資訊,請參閱管理組態來源提供者。
步驟 3:從檔案建立堆疊
使用與檔案位置相關的指令。如需「資源管理程式」支援的 Terraform 組態來源,請參閱儲存 Terraform 組態的位置。
terraform.zip
中的執行處理主體認證方法建立堆疊。terraform.zip
檔案包含下列檔案:
provider.tf
nosql.tf
terraform.tfvars
variables.tf
附註:
在本教學課程中,我們使用 OCI Resource Manager CLI 命令來建立堆疊。您可以使用「OCI 資源管理程式主控台」執行相同作業。oci resource-manager stack create-from-git-provider
--compartment-id ocid1.tenancy.oc1..uniqueid
--config-source-configuration-source-provider-id ocid.ormconfigsourceprovider.oc1..uniqueid
--config-source-repository-url https://github.com/user/repo.git
--config-source-branch-name mybranch
--display-name "My Stack from Git"
--description "Create NoSQL Table"
--variables file://variables.json
--working-directory ""
oci resource-manager stack create-from-object-storage
--compartment-id ocid1.tenancy.oc1..uniqueid
--config-source-namespace MyNamespace
--config-source-bucket-name MyBucket
--config-source-region PHX
--display-name "My Stack from Object Storage"
--description "Create NoSQL Table"
--variables file://variables.json
oci resource-manager stack create
--compartment-id ocid1.tenancy.oc1..uniqueid
--config-source vcn.zip
--variables file://variables.json
--display-name "My Example Stack"
--description "Create NoSQL Table"
--working-directory ""
--compartment-id
是您要建立堆疊之區間的 OCID。--config-source
是包含一或多個 Terraform 組態檔的 .zip 檔案名稱。- (選擇性)
--variables
是指定資源輸入變數的檔案路徑。Oracle Cloud Infrastructure Terraform 提供者在本機執行 Terraform 時需要額外的參數 (除非您使用執行處理主體)。如需在 Terraform 中使用變數的詳細資訊,請參閱輸入變數。另請參閱輸入變數組態。
- (選擇性)
--display-name
是新堆疊的易記名稱。 - (選擇性)
--description
是新堆疊的描述。 - (可選擇)
--working-directory
是目錄中的根配置檔案。如果未指定,或在此範例中為空值,則服務會假設目錄中的最上層檔案是根組態檔。
oci resource-manager stack create
--compartment-id ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya
--config-source terraform.zip
{
"data": {
"compartment-id": "ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya",
"config-source": {
"config-source-type": "ZIP_UPLOAD",
"working-directory": null
},
"defined-tags": {},
"description": null,
"display-name": "ormstack20220117104810",
"freeform-tags": {},
"id": "ocid1.ormstack.oc1.phx.aaaaaaaa7jrci2s5iav5tdxpl6ucwo2dwazzrdkfhs6bxiohgcpkscmr57bq",
"lifecycle-state": "ACTIVE",
"stack-drift-status": "NOT_CHECKED",
"terraform-version": "1.0.x",
"time-created": "2022-01-17T10:48:10.878000+00:00",
"time-drift-last-checked": null,
"variables": {}
},
"etag": "dd62ace0b9e9d825d825c05d4588b73fede061e55b75de6436b84fb2bb794185"
}
"id": "ocid1.ormstack.oc1.phx.aaaaaaaa7jrci2s5iav5tdxpl6ucwo2dwazzrdkfhs6bxiohgcpkscmr57bq"
步驟 4:產生執行計畫
附註:
在本教學課程中,我們使用 OCI Resource Manager CLI 命令來產生執行計畫。您可以使用「OCI 資源管理程式主控台」執行相同作業。oci resource-manager job create-plan-job
–-stack-id <stack_OCID>
--display-name "<friendly_name>"
oci resource-manager job create-plan-job
--stack-id ocid1.ormstack.oc1.phx.aaaaaaaa7jrci2s5iav5tdxpl6ucwo2dwazzrdkfhs6bxiohgcpkscmr57bq
{
"data": {
"apply-job-plan-resolution": null,
"cancellation-details": {
"is-forced": false
},
"compartment-id": "ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya",
"config-source": {
"config-source-record-type": "ZIP_UPLOAD"
},
"defined-tags": {},
"display-name": "ormjob20220117104856",
"failure-details": null,
"freeform-tags": {},
"id": "ocid1.ormjob.oc1.phx.aaaaaaaacrylnpglae4yvwo4q2r2tk5z5x5v6bwjsoxgn26moyg3eqwnt2aq",
"job-operation-details": {
"operation": "PLAN",
"terraform-advanced-options": {
"detailed-log-level": null,
"is-refresh-required": true,
"parallelism": 10
}
},
"lifecycle-state": "ACCEPTED",
"operation": "PLAN",
"resolved-plan-job-id": null,
"stack-id": "ocid1.ormstack.oc1.phx.aaaaaaaa7jrci2s5iav5tdxpl6ucwo2dwazzrdkfhs6bxiohgcpkscmr57bq",
"time-created": "2022-01-17T10:48:56.324000+00:00",
"time-finished": null,
"variables": {},
"working-directory": null
},
"etag": "a6f75ec1e205cd9105705fd7c8d65bf262159a7e733b27148049e70ce6fc14fe"
}
"id": "ocid1.ormjob.oc1.phx.aaaaaaaacrylnpglae4yvwo4q2r2tk5z5x5v6bwjsoxgn26moyg3eqwnt2aq",
"job-operation-details": {
"operation": "PLAN"
...
}
子步驟 4.1:複查執行計畫
oci resource-manager job get-job-logs
--job-id <plan_job_OCID>
oci resource-manager job get-job-logs
--job-id ocid1.ormjob.oc1.phx.aaaaaaaacrylnpglae4yvwo4q2r2tk5z5x5v6bwjsoxgn26moyg3eqwnt2aq
...
{
"level": "INFO",
"message": "Terraform used the selected providers to generate the following execution",
"timestamp": "2022-01-17T10:49:21.634000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "plan. Resource actions are indicated with the following symbols:",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + create",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "Terraform will perform the following actions:",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " # oci_nosql_table.nosql_demo will be created",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + resource \"oci_nosql_table\" \"nosql_demo\" {",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + compartment_id = \"ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya\"",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + ddl_statement = \"CREATE TABLE if not exists demo (ticketNo INTEGER, fullName STRING, contactPhone STRING, confNo STRING, gender STRING, bagInfo JSON, PRIMARY KEY (ticketNo))\"",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + is_auto_reclaimable = true",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + name = \"demo\"",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + table_limits {",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_read_units = 10",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_storage_in_gbs = 1",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_write_units = 10",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " # oci_nosql_table.nosql_demoKeyVal will be created",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + resource \"oci_nosql_table\" \"nosql_demoKeyVal\" {",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + compartment_id = \"ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya\"",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + ddl_statement = \"CREATE TABLE if not exists demoKeyVal (key INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 NO CYCLE), value JSON, PRIMARY KEY (key))\"",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + is_auto_reclaimable = true",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + name = \"demoKeyVal\"",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + table_limits {",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_read_units = 10",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_storage_in_gbs = 1",
"timestamp": "2022-01-17T10:49:21.635000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_write_units = 10",
"timestamp": "2022-01-17T10:49:21.636000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "Plan: 2 to add, 0 to change, 0 to destroy.",
"timestamp": "2022-01-17T10:49:21.636000+00:00",
"type": "TERRAFORM_CONSOLE"
},
...
demo
和 demoKeyVal
。{
...
"message": "Plan: 2 to add, 0 to change, 0 to destroy.",
...
}
步驟 5:執行套用工作
- 若要指定計畫工作 (套用執行計畫),請使用
FROM_PLAN_JOB_ID
:oci resource-manager job create-apply-job --stack-id <stack_OCID> --execution-plan-strategy FROM_PLAN_JOB_ID --execution-plan-job-id <plan_job_OCID> --display-name "Example Apply Job"
- 若要自動核准套用工作 (未指定計畫工作),請使用
AUTO_APPROVED
:oci resource-manager job create-apply-job --stack-id <stack_OCID> --execution-plan-strategy AUTO_APPROVED --display-name "Example Apply Job"
oci resource-manager job create-apply-job
--stack-id ocid1.ormstack.oc1.phx.aaaaaaaa7jrci2s5iav5tdxpl6ucwo2dwazzrdkfhs6bxiohgcpkscmr57bq
--execution-plan-strategy AUTO_APPROVED
--display-name "Create NoSQL Tables Using Terraform"
{
"data": {
"apply-job-plan-resolution": {
"is-auto-approved": true,
"is-use-latest-job-id": null,
"plan-job-id": null
},
"cancellation-details": {
"is-forced": false
},
"compartment-id": "ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya",
"config-source": {
"config-source-record-type": "ZIP_UPLOAD"
},
"defined-tags": {},
"display-name": "Create NoSQL Tables Using Terraform",
"failure-details": null,
"freeform-tags": {},
"id": "ocid1.ormjob.oc1.phx.aaaaaaaaqn4nsnfgi3th4rxolwqn3kftzzdpsw52pnfeyphi5dsxd6fhescq",
"job-operation-details": {
"execution-plan-job-id": null,
"execution-plan-strategy": "AUTO_APPROVED",
"operation": "APPLY",
"terraform-advanced-options": {
"detailed-log-level": null,
"is-refresh-required": true,
"parallelism": 10
}
},
"lifecycle-state": "ACCEPTED",
"operation": "APPLY",
"resolved-plan-job-id": null,
"stack-id": "ocid1.ormstack.oc1.phx.aaaaaaaa7jrci2s5iav5tdxpl6ucwo2dwazzrdkfhs6bxiohgcpkscmr57bq",
"time-created": "2022-01-17T10:54:46.346000+00:00",
"time-finished": null,
"variables": {},
"working-directory": null
},
"etag": "4042a300e8f678dd6da0f49ffeccefed66902b51331ebfbb559da8077a728126"
}
"id": "ocid1.ormjob.oc1.phx.aaaaaaaaqn4nsnfgi3th4rxolwqn3kftzzdpsw52pnfeyphi5dsxd6fhescq",
"job-operation-details": {
"operation": "APPLY"
...
}
附註:
如果您使用專用主機環境,請先設定環境變數 CLIENT_HOST_OVERRIDES 以指定自訂端點,再執行工作。範例:export CLIENT_HOST_OVERRIDES=<oci_nosql.NosqlClient=https://ndcs.us-ashburn-1.oci.oc-test.com>
子步驟 5.1:驗證工作狀態
oci resource-manager job get
--job-id <job_OCID>
oci resource-manager job get
--job-id ocid1.ormjob.oc1.phx.aaaaaaaaqn4nsnfgi3th4rxolwqn3kftzzdpsw52pnfeyphi5dsxd6fhescq
{
"data": {
"apply-job-plan-resolution": {
"is-auto-approved": true,
"is-use-latest-job-id": null,
"plan-job-id": null
},
"cancellation-details": {
"is-forced": false
},
"compartment-id": "ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya",
"config-source": {
"config-source-record-type": "ZIP_UPLOAD"
},
"defined-tags": {},
"display-name": "Create NoSQL Tables Using Terraform",
"failure-details": null,
"freeform-tags": {},
"id": "ocid1.ormjob.oc1.phx.aaaaaaaaqn4nsnfgi3th4rxolwqn3kftzzdpsw52pnfeyphi5dsxd6fhescq",
"job-operation-details": {
"execution-plan-job-id": null,
"execution-plan-strategy": "AUTO_APPROVED",
"operation": "APPLY",
"terraform-advanced-options": {
"detailed-log-level": null,
"is-refresh-required": true,
"parallelism": 10
}
},
"lifecycle-state": "SUCCEEDED",
"operation": "APPLY",
"resolved-plan-job-id": null,
"stack-id": "ocid1.ormstack.oc1.phx.aaaaaaaa7jrci2s5iav5tdxpl6ucwo2dwazzrdkfhs6bxiohgcpkscmr57bq",
"time-created": "2022-01-17T10:54:46.346000+00:00",
"time-finished": "2022-01-17T10:55:28.853000+00:00",
"variables": {},
"working-directory": null
},
"etag": "9e9f524b87e3c47b3f3ea3bbb4c1f956172a48e4c2311a44840c8b96e318bcaf--gzip"
}
{
...
"lifecycle-state": "SUCCEEDED",
...
}
子步驟 5.2:檢視工作的日誌
oci resource-manager job get-job-logs-content
--job-id <job_OCID>
oci resource-manager job get-job-logs-content
--job-id ocid1.ormjob.oc1.phx.aaaaaaaaqn4nsnfgi3th4rxolwqn3kftzzdpsw52pnfeyphi5dsxd6fhescq
...
{
"level": "INFO",
"message": "Terraform will perform the following actions:",
"timestamp": "2022-01-17T10:55:05.580000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "",
"timestamp": "2022-01-17T10:55:05.580000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " # oci_nosql_table.nosql_demo will be created",
"timestamp": "2022-01-17T10:55:05.580000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + resource \"oci_nosql_table\" \"nosql_demo\" {",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + compartment_id = \"ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya\"",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + ddl_statement = \"CREATE TABLE if not exists demo (ticketNo INTEGER, fullName STRING, contactPhone STRING, confNo STRING, gender STRING, bagInfo JSON, PRIMARY KEY (ticketNo))\"",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + is_auto_reclaimable = true",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + name = \"demo\"",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + table_limits {",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_read_units = 10",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_storage_in_gbs = 1",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_write_units = 10",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " # oci_nosql_table.nosql_demoKeyVal will be created",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + resource \"oci_nosql_table\" \"nosql_demoKeyVal\" {",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + compartment_id = \"ocid1.compartment.oc1..aaaaaaaawrmvqjzoegxbsixp5k3b5554vlv2kxukobw3drjho3f7nf5ca3ya\"",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + ddl_statement = \"CREATE TABLE if not exists demoKeyVal (key INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 NO CYCLE), value JSON, PRIMARY KEY (key))\"",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + is_auto_reclaimable = true",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + name = \"demoKeyVal\"",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + table_limits {",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_read_units = 10",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_storage_in_gbs = 1",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": " + max_write_units = 10",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "Plan: 2 to add, 0 to change, 0 to destroy.",
"timestamp": "2022-01-17T10:55:05.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "oci_nosql_table.nosql_demoKeyVal: Creating...",
"timestamp": "2022-01-17T10:55:06.581000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "oci_nosql_table.nosql_demo: Creating...",
"timestamp": "2022-01-17T10:55:06.582000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "oci_nosql_table.nosql_demoKeyVal: Creation complete after 6s [id=ocid1.nosqltable.oc1.phx.amaaaaaau7x7rfyaqgpbjucp3s6jjzpnar4lg5yudxhwlqrlbd54l3wdo7hq]",
"timestamp": "2022-01-17T10:55:12.582000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "oci_nosql_table.nosql_demo: Creation complete after 9s [id=ocid1.nosqltable.oc1.phx.amaaaaaau7x7rfyasvdkoclhgryulgzox3nvlxb2bqtlxxsrvrc4zxr6lo4a]",
"timestamp": "2022-01-17T10:55:15.583000+00:00",
"type": "TERRAFORM_CONSOLE"
},
{
"level": "INFO",
"message": "Apply complete! Resources: 2 added, 0 changed, 0 destroyed.",
"timestamp": "2022-01-17T10:55:15.583000+00:00",
"type": "TERRAFORM_CONSOLE"
},
...
demo
和 demoKeyVal
。{
...
"message": "Apply complete! Resources: 2 added, 0 changed, 0 destroyed.",
...
}
本教學課程提供許多詳細資訊。我們建立了在 OCI 雲端部署 NoSQL 資料庫表格所需的 terraform 組態檔,然後設定這些檔案的來源位置。接著,我們使用 OCI Resource Manager CLI 建立堆疊、產生執行計畫,以及在執行計畫上執行套用工作。