Skip to content

Repository files navigation

OCI Infrastructure Setup

This repository contains Infrastructure as Code (IaC) for deploying and managing a web infrastructure on Oracle Cloud Infrastructure (OCI) using Terraform and Ansible.

Infrastructure Overview

The infrastructure consists of:

  • Virtual Cloud Network (VCN) with public subnet
  • Two web servers (web-01 and web-02) running on VM.Standard.E2.1.Micro instances
  • MySQL database instance configured for WordPress
  • Ansible configuration for automated instance provisioning

Architecture

graph TB
   Internet --> IG[Internet Gateway]
   IG --> PublicSubnet
   subgraph VCN[Virtual Cloud Network]
      PublicSubnet --> web1[Web Server 1]
      PublicSubnet --> web2[Web Server 2]
      PublicSubnet --> MySQL[MySQL Database]
   end
Loading

Prerequisites

  1. OCI Setup

    • An Oracle Cloud Infrastructure account
    • OCI CLI configured with required credentials
    • User with appropriate permissions
    • API signing key and fingerprint
  2. Required Software

    • Terraform (>= 1.0.0)
    • Ansible (>= 2.9)
    • Git

Resource Components

Network Resources

  • VCN with customizable CIDR
  • Internet Gateway for public access
  • Public subnet for web servers
  • Security lists for network traffic control

Compute Instances

  • Two VM.Standard.E2.1.Micro instances
  • Ubuntu-based OS
  • Public IP addresses
  • Configured with monitoring and management plugins

Database

  • MySQL DB System (Free Tier)
  • 50GB storage
  • Automated backup enabled
  • Delete protection enabled
  • Secure connections with system-generated certificates

Configuration Management

  • Ansible playbooks for automated provisioning
  • Common role for basic system setup
  • Package installation and updates
  • User management and SSH key setup
  • Secure credential management using Ansible Vault

Ansible Vault Setup

  1. Create a vault password file:

    echo "your-secure-password" > ansible/.vault_pass
    chmod 600 ansible/.vault_pass
  2. Store sensitive data:

    • SSH keys
    • Database credentials
    • User passwords

    All sensitive data is managed in ansible/group_vars/all/vault.yml

  3. Encrypt the vault file:

    cd ansible
    ansible-vault encrypt group_vars/all/vault.yml
  4. To edit vault contents:

    ansible-vault edit group_vars/all/vault.yml

Note: Never commit .vault_pass to version control. Add it to .gitignore.

Getting Started

  1. Clone the Repository

    git clone <repository-url>
    cd oci-tf
  2. Configure Variables

    cp terraform.tfvars.example terraform.tfvars
    # Edit terraform.tfvars with your OCI credentials and preferences
  3. Initialize Terraform

    terraform init
  4. Deploy Infrastructure

    terraform plan    # Review the changes
    terraform apply   # Deploy the infrastructure
  5. Configure Ansible

    cd ansible
    # Update hosts file with instance IP addresses
    ansible-playbook -i hosts provision.yml

Configuration Files

  • provider.tf: OCI provider configuration
  • vcn.tf: Network configuration
  • compute.tf: Web server instances configuration
  • mysql.tf: Database configuration
  • ansible/: Configuration management files
    • provision.yml: Main playbook
    • roles/: Task definitions for server setup

Security Features

  • Encrypted transit for instance communication
  • Security lists controlling inbound/outbound traffic
  • Secure database connections
  • SSH key-based authentication
  • Regular system updates via Ansible

Maintenance

  • Use terraform plan to review infrastructure changes
  • Regular terraform apply for infrastructure updates
  • Ansible playbooks for system configuration updates
  • Monitor instances through OCI Console

Clean Up

To remove all resources:

terraform destroy

Note: This will permanently delete all resources. Ensure data is backed up if needed.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages