구획 모듈 생성

각 구획을 리소스로 정의하고 필수 변수를 선언합니다.

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