区分モジュールの作成

各コンパートメントをリソースとして定義し、必要な変数を宣言します。

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