Repository navigation
Lab :46 Advance Modular approach to create instance
In this approch instead of writing all your Terraform code in one big file, you break it into reusable, independent modules — just like building with LEGO blocks. Each module does one job, does it well, and can be reused across Dev, UAT, and Prod environments without rewriting code.
Advanced Modular Approach is simply breaking your Terraform code into specialist teams (modules) — just like a construction project where separate contractors handle foundation, electrical, and plumbing — and the root module is the project manager who provides direction to all the team and coordinates with them all.
Folder structure — this is what it looks like on disk:
In Terraform, a map is a core structural unordered collection type that stores data as key-value pairs, where each key is a unique string and maps to a value.
resource "oci_core_instance" "generated_oci_core_instance" {
agent_config {
is_management_disabled = "false"
is_monitoring_disabled = "false"
plugins_config {
desired_state = "DISABLED"
name = "WebLogic Management Service"
}
plugins_config {
desired_state = "DISABLED"
name = "Vulnerability Scanning"
}
plugins_config {
desired_state = "DISABLED"
name = "Oracle Java Management Service"
}
plugins_config {
desired_state = "DISABLED"
name = "OS Management Hub Agent"
}
plugins_config {
desired_state = "DISABLED"
name = "Management Agent"
}
plugins_config {
desired_state = "DISABLED"
name = "Fleet Application Management Service"
}
plugins_config {
desired_state = "ENABLED"
name = "Custom Logs Monitoring"
}
plugins_config {
desired_state = "DISABLED"
name = "Compute RDMA GPU Monitoring"
}
plugins_config {
desired_state = "ENABLED"
name = "Compute Instance Run Command"
}
plugins_config {
desired_state = "ENABLED"
name = "Compute Instance Monitoring"
}
plugins_config {
desired_state = "DISABLED"
name = "Compute HPC RDMA Auto-Configuration"
}
plugins_config {
desired_state = "DISABLED"
name = "Compute HPC RDMA Authentication"
}
plugins_config {
desired_state = "ENABLED"
name = "Cloud Guard Workload Protection"
}
plugins_config {
desired_state = "DISABLED"
name = "Block Volume Management"
}
plugins_config {
desired_state = "DISABLED"
name = "Bastion"
}
}
availability_config {
recovery_action = "RESTORE_INSTANCE"
}
availability_domain = "Xmsk:EU-FRANKFURT-1-AD-1"
compartment_id = "ocid1.compartment.oc1..aaaaaaaapjoxq5den524gduyanx5xlbxtflesp62bdybczm4uckyx62zq3tq"
create_vnic_details {
assign_ipv6ip = "false"
assign_private_dns_record = "true"
assign_public_ip = "true"
subnet_id = "ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaptqmfq35wjfefzta6sy5ndplk5g6tyoatqiipa42hm22zt4p4kca"
}
display_name = var.test_display_name
instance_options {
are_legacy_imds_endpoints_disabled = "true"
}
is_pv_encryption_in_transit_enabled = "true"
metadata = {
"ssh_authorized_keys" = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDaceR5HOtgvHqVAf8inPco21eT/cZMGyz11Xg0JUZSiO+OVitNHbVTVQaE/+nOQ0rSZK9JkHXIfCjwpKfUIVe5Gvzy2RldM3BiiGI+9ffHhpB0+jlDf/6xr78faKz1hVbgr4LPD7oCBxNmyGsoUcOHadTtbIl3yc52EGE7zoyW2ctQCq6Z0sLDnkvWqhsX9KGS4lF8kVP44WSBWtoR0nHYeSyoGMx2uZ73ylAcu9l08RmZO+rlN14QQHwcSVQzJYxLI6W03adrl9aJGvMRU7QRKhTMstofP1jzIvjBGFmufDv03XKgpYA0wiPJZtgpohwVGLthpELSdRsq8Tdunmyj ssh-key-2026-05-09"
}
platform_config {
is_symmetric_multi_threading_enabled = "true"
type = "AMD_VM"
}
shape = "VM.Standard.E5.Flex"
shape_config {
memory_in_gbs = var.test_memory_in_gbs
ocpus = var.test_cpu_in_count
}
source_details {
source_id = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaoiwaatpf6sjtuhyoupgloykq72wydgv2u36q6wqqjxke5vkwmyzq"
source_type = "image"
}
}
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDJMN1WkNkMniE
w4fMNxB1zSrNaROIjTCqeAHdymVS+oFcegx9MBC7osI8Kyy/5v2ToW4j+hQa3pRe
Nu+UKMv0hNZKqvQrOhTn7Q2webteSxja/H18l6NWk45AoLlZICSrwUbFgoPzCDe3
4kmGN8mBA1FIwxRPMi8DSKf7uaC+xQIGhJzl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oJqXx88OCFRx/qDPKOEu+L6QbATrvVg9hC5c8UkNQX3+IV
P/LptVkEDO/3E+gBRyrKFnSwMDhMXq3/xnyiTJkbk/zkMuoIQZRWQ5OchOn/2IWP
Yv4aJY+uhNW2QBSIg62Wq9bFpiQyEBcxy+yy1YhjAoGAKZa03iAJbk5exA4trtrI
oPH0k1pEW1P1FCwHqaU7aMH9wvNt6ynG0n8q6Y2edZOgIddCaVwoqb6yDBhh3CHJ
Ie81j0iGTAFp6EoyBOICWGDa7Btv98XwtqkcgXBGrzSo6Qx6VyxO7G7BmrmcTZ+r
V6R+tTVTs1N/WrU3JoM9HtM=
-----END PRIVATE KEY-----
variable "test_display_name" {
type=string
description="This will display the name of comupte instance in OCI"
}
variable "test_memory_in_gbs"{
type=string
description = "It will explain the req size of processor"
}
variable "test_cpu_in_count" {
type=string
description = "It will explain the req of OCPUS in coumupte instance"
}
/home/Er_ATKhan9/TK/test
module "test_instance" {
source = "/home/Er_ATKhan9/advance_modular_tamplate_instance"
for_each = var.inst_var
test_display_name = each.value.test_display_name
test_memory_in_gbs = each.value.test_memory_in_gbs
test_cpu_in_count = each.value.test_cpu_in_count
}
provider "oci" {
auth = "APIKey"
tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaamfnmv4ola7zjuktdzg6xk3v4jc7aig4qq2t6pzjcrhzlyikiamra"
user_ocid = "ocid1.user.oc1..aaaaaaaavdlimo3e3t7oyngsgpzv73zix4zhp4mooodzkvpv7otese44smuq"
fingerprint = "12:c9:0b:27:84:e3:68:9b:2e:9f:59:8f:d8:3c:7f:8b"
private_key_path = "/home/Er_ATKhan9/advance_modular_tamplate_instance/private_key.pem"
region = "eu-frankfurt-1"
}
instance1 = {
test_display_name = "test_instance"
test_memory_in_gbs = "12"
test_cpu_in_count = "1"
}
instance2 = {
test_display_name = "test2_instance"
test_memory_in_gbs = "24"
test_cpu_in_count = "2"
}
}
variable "inst_var" {
type = map(object({
test_display_name = string
test_memory_in_gbs = string
test_cpu_in_count = string
})
)
}
terraform.init
both the instance has been created:
terraform.destroy