Initial Oracle Deep Data Security lab kit
Some checks failed
Repo Quality / structure (push) Has been cancelled
Terraform Validate / validate (push) Has been cancelled

This commit is contained in:
Rodrigo Pace
2026-05-08 12:08:05 -03:00
commit 5cd8752a90
88 changed files with 2189 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
resource "oci_database_autonomous_database" "this" {
compartment_id = var.compartment_id
db_name = var.db_name
display_name = var.display_name
admin_password = var.admin_password
db_workload = var.db_workload
db_version = var.db_version
compute_model = var.compute_model
compute_count = var.compute_count
data_storage_size_in_tbs = var.data_storage_size_in_tbs
is_auto_scaling_enabled = var.is_auto_scaling_enabled
license_model = var.license_model
subnet_id = var.subnet_id
nsg_ids = var.nsg_ids
private_endpoint_label = var.private_endpoint_label
whitelisted_ips = var.whitelisted_ips
is_mtls_connection_required = var.is_mtls_connection_required
vault_id = var.customer_managed_vault_id
kms_key_id = var.customer_managed_key_id
freeform_tags = var.freeform_tags
}

View File

@@ -0,0 +1,16 @@
output "autonomous_database_id" {
description = "Autonomous Database OCID."
value = oci_database_autonomous_database.this.id
}
output "private_endpoint" {
description = "Private endpoint IP/FQDN reported by OCI."
value = try(oci_database_autonomous_database.this.private_endpoint, null)
}
output "connection_strings" {
description = "Connection strings generated by Autonomous Database."
value = try(oci_database_autonomous_database.this.connection_strings, null)
sensitive = true
}

View File

@@ -0,0 +1,101 @@
variable "compartment_id" {
description = "Compartment OCID."
type = string
}
variable "db_name" {
description = "Autonomous Database DB name."
type = string
}
variable "display_name" {
description = "Autonomous Database display name."
type = string
}
variable "admin_password" {
description = "ADMIN password."
type = string
sensitive = true
}
variable "db_workload" {
description = "Database workload."
type = string
}
variable "db_version" {
description = "Optional database version."
type = string
default = null
}
variable "compute_model" {
description = "Autonomous Database compute model."
type = string
}
variable "compute_count" {
description = "Autonomous Database compute count."
type = number
}
variable "data_storage_size_in_tbs" {
description = "Storage size in TB."
type = number
}
variable "is_auto_scaling_enabled" {
description = "Enable autoscaling."
type = bool
}
variable "license_model" {
description = "License model."
type = string
}
variable "subnet_id" {
description = "Private endpoint subnet OCID."
type = string
}
variable "nsg_ids" {
description = "NSG OCIDs."
type = list(string)
}
variable "private_endpoint_label" {
description = "Private endpoint DNS label."
type = string
}
variable "customer_managed_key_id" {
description = "Optional KMS key OCID."
type = string
default = null
}
variable "customer_managed_vault_id" {
description = "Optional Vault OCID for customer-managed key."
type = string
default = null
}
variable "whitelisted_ips" {
description = "Whitelisted IPs. Empty for private endpoint use."
type = list(string)
default = []
}
variable "is_mtls_connection_required" {
description = "Require mTLS."
type = bool
default = true
}
variable "freeform_tags" {
description = "Freeform tags."
type = map(string)
default = {}
}

View File

@@ -0,0 +1,9 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 6.0.0"
}
}
}

View File

@@ -0,0 +1,30 @@
resource "oci_core_instance" "this" {
availability_domain = var.availability_domain
compartment_id = var.compartment_id
display_name = var.display_name
shape = var.shape
freeform_tags = var.freeform_tags
dynamic "shape_config" {
for_each = length(regexall("Flex$", var.shape)) > 0 ? [1] : []
content {
ocpus = var.ocpus
memory_in_gbs = var.memory_in_gbs
}
}
create_vnic_details {
subnet_id = var.subnet_id
assign_public_ip = var.assign_public_ip
nsg_ids = var.nsg_ids
}
metadata = {
ssh_authorized_keys = var.ssh_public_key
}
source_details {
source_type = "image"
source_id = var.image_ocid
}
}

View File

@@ -0,0 +1,10 @@
output "instance_id" {
description = "Bastion instance OCID."
value = oci_core_instance.this.id
}
output "public_ip" {
description = "Bastion public IP."
value = oci_core_instance.this.public_ip
}

View File

@@ -0,0 +1,63 @@
variable "compartment_id" {
description = "Compartment OCID."
type = string
}
variable "availability_domain" {
description = "Availability domain."
type = string
}
variable "display_name" {
description = "Instance display name."
type = string
}
variable "shape" {
description = "Compute shape."
type = string
}
variable "ocpus" {
description = "OCPUs for flexible shapes."
type = number
default = 1
}
variable "memory_in_gbs" {
description = "Memory in GB for flexible shapes."
type = number
default = 8
}
variable "image_ocid" {
description = "Image OCID."
type = string
}
variable "subnet_id" {
description = "Subnet OCID."
type = string
}
variable "nsg_ids" {
description = "NSG OCIDs."
type = list(string)
}
variable "ssh_public_key" {
description = "SSH public key."
type = string
sensitive = true
}
variable "assign_public_ip" {
description = "Assign public IP to bastion."
type = bool
}
variable "freeform_tags" {
description = "Freeform tags."
type = map(string)
default = {}
}

View File

@@ -0,0 +1,9 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 6.0.0"
}
}
}

View File

@@ -0,0 +1,182 @@
data "oci_core_services" "oracle_services" {
filter {
name = "name"
values = ["All .* Services In Oracle Services Network"]
regex = true
}
}
resource "oci_core_vcn" "this" {
compartment_id = var.compartment_id
cidr_block = var.vcn_cidr
display_name = "${var.name_prefix}-vcn"
dns_label = replace(var.name_prefix, "-", "")
freeform_tags = var.freeform_tags
}
resource "oci_core_nat_gateway" "this" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-nat"
freeform_tags = var.freeform_tags
}
resource "oci_core_service_gateway" "this" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-service-gateway"
freeform_tags = var.freeform_tags
services {
service_id = data.oci_core_services.oracle_services.services[0].id
}
}
resource "oci_core_internet_gateway" "this" {
count = var.create_public_subnet ? 1 : 0
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-igw"
enabled = true
freeform_tags = var.freeform_tags
}
resource "oci_core_route_table" "private" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-private-rt"
freeform_tags = var.freeform_tags
route_rules {
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
network_entity_id = oci_core_nat_gateway.this.id
}
route_rules {
destination = data.oci_core_services.oracle_services.services[0].cidr_block
destination_type = "SERVICE_CIDR_BLOCK"
network_entity_id = oci_core_service_gateway.this.id
}
}
resource "oci_core_route_table" "public" {
count = var.create_public_subnet ? 1 : 0
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-public-rt"
freeform_tags = var.freeform_tags
route_rules {
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
network_entity_id = oci_core_internet_gateway.this[0].id
}
}
resource "oci_core_security_list" "private" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-private-sl"
freeform_tags = var.freeform_tags
egress_security_rules {
destination = "0.0.0.0/0"
protocol = "6"
}
}
resource "oci_core_security_list" "public" {
count = var.create_public_subnet ? 1 : 0
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-public-sl"
freeform_tags = var.freeform_tags
egress_security_rules {
destination = "0.0.0.0/0"
protocol = "6"
}
}
resource "oci_core_subnet" "private" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
cidr_block = var.private_subnet_cidr
display_name = "${var.name_prefix}-private-subnet"
dns_label = "private"
prohibit_public_ip_on_vnic = true
route_table_id = oci_core_route_table.private.id
security_list_ids = [oci_core_security_list.private.id]
freeform_tags = var.freeform_tags
}
resource "oci_core_subnet" "public" {
count = var.create_public_subnet ? 1 : 0
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
cidr_block = var.public_subnet_cidr
display_name = "${var.name_prefix}-public-subnet"
dns_label = "public"
prohibit_public_ip_on_vnic = false
route_table_id = oci_core_route_table.public[0].id
security_list_ids = [oci_core_security_list.public[0].id]
freeform_tags = var.freeform_tags
}
resource "oci_core_network_security_group" "app" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-app-nsg"
freeform_tags = var.freeform_tags
}
resource "oci_core_network_security_group" "database" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
display_name = "${var.name_prefix}-database-nsg"
freeform_tags = var.freeform_tags
}
resource "oci_core_network_security_group_security_rule" "app_to_database" {
network_security_group_id = oci_core_network_security_group.database.id
direction = "INGRESS"
protocol = "6"
source = oci_core_network_security_group.app.id
source_type = "NETWORK_SECURITY_GROUP"
tcp_options {
destination_port_range {
min = var.adb_port
max = var.adb_port
}
}
}
resource "oci_core_network_security_group_security_rule" "database_egress_oracle_services" {
network_security_group_id = oci_core_network_security_group.database.id
direction = "EGRESS"
protocol = "6"
destination = data.oci_core_services.oracle_services.services[0].cidr_block
destination_type = "SERVICE_CIDR_BLOCK"
}
resource "oci_core_network_security_group_security_rule" "app_egress_https" {
network_security_group_id = oci_core_network_security_group.app.id
direction = "EGRESS"
protocol = "6"
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
tcp_options {
destination_port_range {
min = 443
max = 443
}
}
}

View File

@@ -0,0 +1,25 @@
output "vcn_id" {
description = "VCN OCID."
value = oci_core_vcn.this.id
}
output "private_subnet_id" {
description = "Private subnet OCID."
value = oci_core_subnet.private.id
}
output "public_subnet_id" {
description = "Public subnet OCID, when created."
value = try(oci_core_subnet.public[0].id, null)
}
output "app_nsg_id" {
description = "Application NSG OCID."
value = oci_core_network_security_group.app.id
}
output "database_nsg_id" {
description = "Database NSG OCID."
value = oci_core_network_security_group.database.id
}

View File

@@ -0,0 +1,42 @@
variable "compartment_id" {
description = "Compartment OCID."
type = string
}
variable "name_prefix" {
description = "Resource name prefix."
type = string
}
variable "vcn_cidr" {
description = "VCN CIDR."
type = string
}
variable "private_subnet_cidr" {
description = "Private subnet CIDR."
type = string
}
variable "public_subnet_cidr" {
description = "Public subnet CIDR."
type = string
}
variable "create_public_subnet" {
description = "Create public subnet and internet gateway."
type = bool
default = false
}
variable "adb_port" {
description = "Autonomous Database listener port."
type = number
}
variable "freeform_tags" {
description = "Freeform tags."
type = map(string)
default = {}
}

View File

@@ -0,0 +1,9 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 6.0.0"
}
}
}

View File

@@ -0,0 +1,19 @@
resource "oci_kms_vault" "this" {
compartment_id = var.compartment_id
display_name = "${var.name_prefix}-vault"
vault_type = "DEFAULT"
freeform_tags = var.freeform_tags
}
resource "oci_kms_key" "adb" {
compartment_id = var.compartment_id
display_name = "${var.name_prefix}-adb-key"
management_endpoint = oci_kms_vault.this.management_endpoint
freeform_tags = var.freeform_tags
key_shape {
algorithm = "AES"
length = 32
}
}

View File

@@ -0,0 +1,10 @@
output "vault_id" {
description = "Vault OCID."
value = oci_kms_vault.this.id
}
output "key_id" {
description = "KMS key OCID."
value = oci_kms_key.adb.id
}

View File

@@ -0,0 +1,16 @@
variable "compartment_id" {
description = "Compartment OCID."
type = string
}
variable "name_prefix" {
description = "Resource name prefix."
type = string
}
variable "freeform_tags" {
description = "Freeform tags."
type = map(string)
default = {}
}

View File

@@ -0,0 +1,9 @@
terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 6.0.0"
}
}
}