Créer le module de catégories

Définissez chaque compartiment en tant que ressource et déclarez les variables obligatoires.

Exécutez les étapes suivantes dans le sous-répertoire compartments :
  1. Créez un fichier texte nommé variables.tf et collez le code suivant dans le fichier.
    Ce code déclare les variables utilisées dans ce module.
    variable "tenancy_ocid" {}
    variable "app_tag" {}
    variable "environment" {}
  2. Créez un fichier texte nommé compartments.tf et collez le code suivant dans le fichier.
    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. Créez un fichier texte nommé compartments_output.tf et collez le code suivant dans le fichier.
    Ce code entraîne l'affichage des ID des catégories après leur création.
    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}"
    }