Oracle cloud

From j4flmao/agent-skills · View interactive version

Oracle cloud is an AI agent skill from the GitHub repository j4flmao/agent-skills. Use when the user asks about Oracle Cloud Infrastructure (OCI), compartments and IAM policies, VCN, security lists and NSGs, OKE, Autonomous Database, OCI Object Storage, FastConnect, Resource Manager, or the oci Terraform provider. Produces OCI architectures and IaC. Not for AWS (use aws) or IBM Cl

How to use this skill

Skill file

Oracle Cloud Infrastructure (OCI)

Purpose

Manage Oracle Cloud Infrastructure resources: compute, networking, storage, IAM, OKE (Kubernetes), Autonomous Database, and cost governance.

Agent Protocol

Trigger

Exact user phrases: "oracle cloud", "oci", "oke", "oracle kubernetes", "autonomous database", "oci compute", "oci networking", "oci iam".

Input Context

Before activating, verify:

Output Artifact

OCI resource configurations (Terraform or CLI) or architecture documentation.

Response Format

Terraform HCL or OCI CLI commands. No preamble.

Completion Criteria

Max Response Length

400 lines.

Quick Start

Create a compartment → set up VCN with subnets and security lists → provision compute instance (VM.Standard.E4.Flex) → configure IAM policies → deploy OKE cluster → set up object storage for backups. All via oci CLI or Terraform.

Decision Tree: OCI Compute Shapes

| Shape Family | Use Case | vCPUs | Memory | Networking |

|-------------|----------|-------|--------|------------|

| VM.Standard.E4.Flex | General purpose, AMD EPYC | 1-64 | 1-512 GB | Up to 32 Gbps |

| VM.Standard.A1.Flex | ARM Ampere, cost-effective | 1-80 | 1-512 GB | Up to 32 Gbps |

| BM.Optimized3.36 | Bare metal, HPC | 36 | 512 GB | 100 Gbps |

| VM.GPU.A10.1 | ML inference, graphics | 15 | 120 GB | 4 Gbps |

| VM.DenseIO.E4.Flex | NVMe local SSD, databases | 1-64 | 1-512 GB | Up to 32 Gbps |

Core Workflow

Step 1: OCI Networking

# VCN with public and private subnets
resource "oci_core_vcn" "main" {
  compartment_id = var.compartment_ocid
  display_name   = "vcn-main"
  cidr_blocks    = ["10.0.0.0/16"]
  dns_label      = "vcnmain"
}

resource "oci_core_subnet" "public" {
  compartment_id    = var.compartment_ocid
  vcn_id            = oci_core_vcn.main.id
  cidr_block        = "10.0.1.0/24"
  display_name      = "subnet-public"
  security_list_ids = [oci_core_security_list.public.id]
  route_table_id    = oci_core_route_table.public.id
  dns_label         = "public"
}

resource "oci_core_subnet" "private" {
  compartment_id    = var.compartment_ocid
  vcn_id            = oci_core_vcn.main.id
  cidr_block        = "10.0.2.0/24"
  display_name      = "subnet-private"
  security_list_ids = [oci_core_security_list.private.id]
  route_table_id    = oci_core_route_table.private.id
  dns_label         = "private"
}

# Internet Gateway for public subnet
resource "oci_core_internet_gateway" "ig" {
  compartment_id = var.compartment_ocid
  vcn_id         = oci_core_vcn.main.id
  display_name   = "ig-main"
}

# NAT Gateway for private subnet outbound
resource "oci_core_nat_gateway" "nat" {
  compartment_id = var.compartment_ocid
  vcn_id         = oci_core_vcn.main.id
  display_name   = "nat-main"
}

Step 2: Security Lists and NSGs

# Security List (stateless, applies to whole subnet)
resource "oci_core_security_list" "public" {
  compartment_id = var.compartment_ocid
  vcn_id         = oci_core_vcn.main.id
  display_name   = "sl-public"

  egress_security_rules {
    destination = "0.0.0.0/0"
    protocol    = "6"
  }

  ingress_security_rules {
    source   = "0.0.0.0/0"
    protocol = "6"
    tcp_options {
      min = 80
      max = 80
    }
  }
  ingress_security_rules {
    source   = "0.0.0.0/0"
    protocol = "6"
    tcp_options {
      min = 443
      max = 443
    }
  }
}

# Network Security Group (stateful, applies to individual instances)
resource "oci_core_network_security_group" "web" {
  compartment_id = var.compartment_ocid
  vcn_id         = oci_core_vcn.main.id
  display_name   = "nsg-web"
}

resource "oci_core_network_security_group_security_rule" "web_http" {
  network_security_group_id = oci_core_network_security_group.web.id
  direction                 = "INGRESS"
  protocol                  = "6"
  source                    = "0.0.0.0/0"
  source_type               = "CIDR_BLOCK"
  tcp_options {
    destination_port_range {
      min = 80
      max = 80
    }
  }
}

Step 3: Compute Instance

resource "oci_core_instance" "app" {
  availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
  compartment_id      = var.compartment_ocid
  shape               = "VM.Standard.E4.Flex"
  shape_config {
    ocpus         = 4
    memory_in_gbs = 32
  }
  display_name = "app-server"

  source_details {
    source_type = "image"
    source_id   = data.oci_core_images.ol8.images[0].id
  }

  create_vnic_details {
    subnet_id        = oci_core_subnet.private.id
    assign_public_ip = false
    nsg_ids          = [oci_core_network_security_group.web.id]
  }

  metadata = {
    ssh_authorized_keys = file(var.ssh_public_key_path)
    user_data           = base64encode(file("${path.module}/cloud-init.yaml"))
  }
}

Step 4: OCI IAM

# Compartments
resource "oci_identity_compartment" "team" {
  compartment_id = var.root_compartment_ocid
  description    = "Team workload compartment"
  name           = "team-compartment"
}

# Groups and Policies
resource "oci_identity_group" "ops" {
  compartment_id = var.root_compartment_ocid
  name           = "DevOpsTeam"
  description    = "DevOps engineering team"
}

resource "oci_identity_policy" "ops_policy" {
  compartment_id = var.root_compartment_ocid
  name           = "devops-policy"
  description    = "Policy for DevOps team"
  statements = [
    "Allow group DevOpsTeam to manage all-resources in compartment team-compartment",
    "Allow group DevOpsTeam to read audit-events in tenancy",
    "Allow group DevOpsTeam to use tag-namespaces in tenancy"
  ]
}

# Dynamic Group for compute instances
resource "oci_identity_dynamic_group" "compute" {
  compartment_id = var.root_compartment_ocid
  name           = "ComputeInstances"
  description    = "All compute instances in prod"
  matching_rule = "ALL {instance.compartment.id = '${oci_identity_compartment.team.id}'}"
}

Step 5: OKE (Oracle Kubernetes Engine)

resource "oci_containerengine_cluster" "oke" {
  compartment_id     = var.compartment_ocid
  kubernetes_version = "v1.28.2"
  name               = "oke-prod"
  vcn_id             = oci_core_vcn.main.id

  options {
    service_lb_subnet_ids = [oci_core_subnet.public.id]

    add_ons {
      is_kubernetes_dashboard_enabled = false
      is_tiller_enabled               = false
    }

    admission_controller_options {
      is_pod_security_policy_enabled = false
    }
  }
}

resource "oci_containerengine_node_pool" "pool" {
  cluster_id         = oci_containerengine_cluster.oke.id
  compartment_id     = var.compartment_ocid
  kubernetes_version = "v1.28.2"
  name               = "pool-general"
  node_shape         = "VM.Standard.E4.Flex"
  node_shape_config {
    ocpus         = 4
    memory_in_gbs = 32
  }
  node_source_details {
    source_type = "image"
    image_id    = data.oci_core_images.oke.images[0].id
  }
  subnet_ids           = [oci_core_subnet.private.id]
  quantity_per_subnet  = 3
  ssh_public_key       = file(var.ssh_public_key_path)

  initial_node_labels {
    key   = "pool"
    value = "general"
  }
}

Step 6: Autonomous Database

resource "oci_database_autonomous_database" "adb" {
  compartment_id = var.compartment_ocid
  db_name        = "mydb"
  display_name   = "my-autonomous-db"
  db_workload    = "OLTP"
  is_free_tier   = false
  db_version     = "19c"

  admin_password = var.db_admin_password
  cpu_core_count = 4
  data_storage_size_in_tbs = 1

  whitelisted_ips = ["10.0.0.0/16"]
  license_model   = "BRING_YOUR_OWN_LICENSE"

  # Enable auto-scaling
  is_auto_scaling_enabled = true

  # Database backups
  is_backup_retention_enabled = true
  backup_retention_period_in_days = 7
}

Step 7: Object Storage

resource "oci_objectstorage_bucket" "backup" {
  compartment_id = var.compartment_ocid
  name           = "app-backups"
  namespace      = data.oci_objectstorage_namespace.ns.namespace
  access_type    = "NoPublicAccess"
  storage_tier   = "Standard"
  object_events_enabled = true

  # Lifecycle rules
  retention_rules {
    display_name = "7-year-retention"
    duration {
      time_amount = 7
      time_unit   = "YEARS"
    }
  }
}

resource "oci_objectstorage_bucket" "cold_storage" {
  compartment_id = var.compartment_ocid
  name           = "archived-logs"
  namespace      = data.oci_objectstorage_namespace.ns.namespace
  access_type    = "NoPublicAccess"
  storage_tier   = "Archive"
  auto_tiering   = "INFREQUENT_ACCESS"
}

Step 8: FastConnect (Dedicated Private Connectivity)

resource "oci_core_fast_connect_provider_service" "provider" {
  provider_service_name = "Megaport"
}

resource "oci_core_virtual_circuit" "fc_primary" {
  compartment_id = var.compartment_ocid
  type           = "PRIVATE"
  display_name   = "fastconnect-primary"
  bandwidth      = 1000  # 1 Gbps
  customer_bgp_asn = 65550
  provider_service_id  = data.oci_core_fast_connect_provider_services.provider.fast_connect_provider_services[0].id
  provider_service_key_name = "megaport-key-primary"
  gateway_id = oci_core_drg.main.id

  cross_connect_mappings {
    customer_bgp_peering_ip  = "10.200.0.1/30"
    oracle_bgp_peering_ip    = "10.200.0.2/30"
  }
}

Step 9: Resource Manager (Terraform Automation)

resource "oci_resourcemanager_stack" "infra" {
  compartment_id = var.compartment_ocid
  display_name   = "infrastructure-stack"
  description    = "Base infrastructure deployment"
  config_source {
    config_source_type = "GIT_CONFIG_SOURCE"
    configuration_source_provider_id = oci_resourcemanager_configuration_source_provider.github.id
    branch_name = "main"
  }
}

resource "oci_resourcemanager_job" "apply" {
  stack_id          = oci_resourcemanager_stack.infra.id
  job_operation_details {
    operation = "APPLY"
    apply_job_plan_resolution {
      resolution_strategy = "ALWAYS_USE_LATEST_PLAN"
    }
  }
}

Step 10: Monitoring and Alerts

resource "oci_monitoring_alarm" "cpu_high" {
  compartment_id     = var.compartment_ocid
  alarm_summary      = "High CPU utilization"
  display_name       = "cpu-utilization-high"
  metric_compartment_id = var.compartment_ocid
  namespace          = "oci_computeagent"
  query              = "CpuUtilization[1m].mean() > 90"
  severity           = "WARNING"
  body               = "CPU > 90% for >1 minute on {resource.display_name}"
  destinations       = [oci_ons_topic.alarms.id]
  is_enabled         = true
  repeat_duration    = "PT15M"
}

Rules

Production Considerations

Anti-Patterns

References

Handoff

Architecture Decision Trees

OCI IAM vs Federation

| Decision | OCI Native IAM | Federated (SSO/OIDC) |

|---|---|---|

| User management | OCI console, manual | Central IdP (Okta, Azure AD) |

| MFA | OCI built-in MFA | IdP-managed MFA |

| Group sync | Manual or API | SCIM provisioning |

| Audit trail | OCI Audit logs | IdP audit + OCI Audit |

| Complexity | Lower (in-platform) | Higher (IdP setup + mapping) |

| Best for | Small teams, isolated OCI | Enterprise with SSO requirement |

Compute Shapes: AMD vs ARM (Ampere)

| Aspect | AMD (Standard) | ARM / Ampere A1 |

|---|---|---|

| vCPU ratio | 1:2 per core | 1:1 per core |

| Price-performance | Baseline | 20-40% better for scale-out |

| Software compat | Universal | Requires ARM64 builds |

| GPU support | Available | Not available |

| Best for | General workloads, legacy | Containerized, web, K8s nodes |

Implementation Patterns

Terraform: OCI VCN with Public and Private Subnets

resource "oci_identity_compartment" "prod" {
  name        = "production"
  description = "Production compartment"
}

resource "oci_core_vcn" "main" {
  compartment_id = oci_identity_compartment.prod.id
  display_name   = "production-vcn"
  cidr_block     = "10.0.0.0/16"
  dns_label      = "prod"

  defined_tags = {
    "Operations.CostCenter" = "12345"
  }
}

resource "oci_core_subnet" "public" {
  compartment_id    = oci_identity_compartment.prod.id
  vcn_id            = oci_core_vcn.main.id
  cidr_block        = "10.0.1.0/24"
  display_name      = "public-lb"
  security_list_ids = [oci_core_security_list.lb.id]
  route_table_id    = oci_core_route_table.public.id
  dhcp_options_id   = oci_core_dhcp_options.main.id
  dns_label         = "public"
  prohibit_public_ip_on_vnic = false
}

resource "oci_core_subnet" "private" {
  compartment_id    = oci_identity_compartment.prod.id
  vcn_id            = oci_core_vcn.main.id
  cidr_block        = "10.0.2.0/24"
  display_name      = "private-app"
  security_list_ids = [oci_core_security_list.app.id]
  route_table_id    = oci_core_route_table.private.id
  dhcp_options_id   = oci_core_dhcp_options.main.id
  dns_label         = "private"
  prohibit_public_ip_on_vnic = true
}

resource "oci_core_instance" "app" {
  compartment_id  = oci_identity_compartment.prod.id
  display_name    = "app-server-01"
  shape           = "VM.Standard.A1.Flex"
  shape_config {
    ocpus         = 4
    memory_in_gbs = 24
  }
  source_details {
    source_type = "image"
    source_id   = var.ol8_image_id
  }
  create_vnic_details {
    subnet_id = oci_core_subnet.private.id
    assign_public_ip = false
  }
  metadata = {
    ssh_authorized_keys = var.ssh_public_key
  }
}

Bash: OCI CLI Automation for OKE

#!/usr/bin/env bash
oci_login() {
  oci session authenticate --region us-ashburn-1
}

oke_kubeconfig() {
  local cluster_id=$1
  oci ce cluster create-kubeconfig \
    --cluster-id "$cluster_id" \
    --file "${HOME}/.kube/oke-config" \
    --region us-ashburn-1 \
    --token-version 2.0.0
  export KUBECONFIG="${HOME}/.kube/oke-config"
}

list_compartments() {
  oci iam compartment list \
    --compartment-id-in-subtree true \
    --all \
    --query 'data[*].{Name:name, Id:id, State:"lifecycle-state"}' \
    --output table
}

Production Considerations

Anti-Patterns

Performance Optimization

Security Considerations

Implementation Patterns

Observer Pattern for Event Handling

`

interface EventObserver<T> {

onEvent(event: T): Promise<void>;

}

class EventBus<T> {

private observers: Set<EventObserver<T>> = new Set();

subscribe(observer: EventObserver<T>): void {

this.observers.add(observer);

}

unsubscribe(observer: EventObserver<T>): void {

this.observers.delete(observer);

}

async emit(event: T): Promise<void> {

const results = Array.from(this.observers).map(o => o.onEvent(event));

await Promise.allSettled(results);

}

}

`

Configuration-Driven Approach

`

config:

defaults:

timeout: 30s

retryCount: 3

overrides:

production:

timeout: 60s

retryCount: 5

development:

timeout: 300s

retryCount: 1

`

Production Considerations

Deployment Checklist

Monitoring and Alerting

| Metric | Threshold | Severity | Action |

|--------|-----------|----------|--------|

| Error rate | > 1% over 5min | Critical | Page on-call |

| p99 latency | > 2s over 5min | Warning | Investigate |

| Throughput drop | > 50% over 1min | Critical | Check upstream |

| Queue depth | > 1000 over 1min | Warning | Scale consumers |

| Disk usage | > 85% | Warning | Clean or expand |

| Memory usage | > 90% heap | Critical | Restart or scale |

Anti-Patterns

| Anti-Pattern | Symptom | Root Cause | Solution |

|-------------|---------|------------|----------|

| Premature optimization | Complex code for no measured benefit | Guessing instead of profiling | Measure first, optimize based on data |

| Copy-paste reuse | Duplicate code across codebase | Lack of abstraction | Extract shared logic into libraries |

| Gold-plating | Features with no current requirement | Over-engineering | YAGNI — build what's needed now |

| Magical thinking | Assumptions without validation | Skipping error handling | Handle all failure modes explicitly |

Performance Optimization

Caching Strategy

Cache hierarchy: L1 (in-memory local) → L2 (distributed Redis/Memcached) → L3 (CDN/Edge).

Cache invalidation: TTL-based (simple, stale), event-based (complex, fresh), write-through (consistent, higher write latency), write-behind (fast writes, eventual consistency).

Resource Pooling

Profiling Methodology

  1. Establish baseline with production traffic profile
  2. Profile CPU with sampling profiler (pprof, perf, async-profiler)
  3. Profile memory with heap dumps and allocation tracking
  4. Profile I/O with strace/perf trace for syscall analysis
  5. Profile latency with distributed tracing (OpenTelemetry)
  6. Identify bottleneck, formulate hypothesis, implement fix
  7. Re-profile to verify improvement, repeat

Security Considerations

Threat Modeling (STRIDE)

Supply Chain Security

Secrets Management

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.