建立區間模組

將每個區間定義為資源,並宣告必要的變數。

完成 compartments 子目錄中的下列步驟:
  1. 建立名為 variables.tf 的文字檔,然後將下列程式碼貼到檔案中。
    此代碼會宣告此模組中使用的變數。
    variable "tenancy_ocid" {}
    variable "app_tag" {}
    variable "environment" {}
  2. 建立名為 compartments.tf 的文字檔,然後將下列程式碼貼到檔案中。
    resource "oci_identity_compartment" "networks" {
      description = "The networks compartment"
      name        = "${var.app_tag}_${var.environment}_networks"
    }
    
    resource "oci_identity_compartment" "admin" {
      description = "The admin compartment"
      name        = "${var.app_tag}_${var.environment}_admin"
    }
    
    resource "oci_identity_compartment" "shared_services" {
      description = "The shared_services compartment"
      name        = "${var.app_tag}_${var.environment}_shared_services"
    }
    
    resource "oci_identity_compartment" "business_logic" {
      description = "The business_logic compartment"
      name        = "${var.app_tag}_${var.environment}_business_logic"
    }
    
    resource "oci_identity_compartment" "database" {
      description = "The database compartment"
      name        = "${var.app_tag}_${var.environment}_database"
    }
    
  3. 建立名為 compartments_output.tf 的文字檔,然後將下列程式碼貼到檔案中。
    此代碼會造成 Terraform 在建立區間之後顯示區間的 ID。
    output "networks_id" {
      value = "${oci_identity_compartment.networks.id}"
    }
    
    output "admin_id" {
      value = "${oci_identity_compartment.admin.id}"
    }
    
    output "shared_services_id" {
      value = "${oci_identity_compartment.shared_services.id}"
    }
    
    output "business_logic_id" {
      value = "${oci_identity_compartment.business_logic.id}"
    }
    
    output "database_id" {
      value = "${oci_identity_compartment.database.id}"
    }