创建划分模块

将每个划分定义为资源,并声明所需变量。

完成 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}"
    }