### Post-Provisioning Block Device Setup Source: https://github.com/oracle/terraform-oci-cf-install/blob/master/README.md These commands are executed on the bastion instance after deployment to set up a persistent block device (`/dev/sdb`). It involves installing dependencies, formatting the device with ext4, and mounting it. The `bosh` folder in the home directory will then point to this mounted device for storing releases, stemcells, and deployments. ```bash ./install_deps.sh sudo mkfs.ext4 /dev/sdb sudo mount -a ``` -------------------------------- ### Bastion Access and Post-Provisioning Setup (Bash) Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt This snippet outlines the steps to access the bastion instance via SSH, format and mount persistent block storage, install the BOSH CLI, and verify the installation and configuration. It assumes the necessary keys and IP addresses are available from the Terraform apply output. ```bash # SSH to bastion using generated key (replace IP with output from terraform apply) ssh -i keys/bosh-ssh ubuntu@129.213.x.x # On bastion: Install BOSH CLI and dependencies ./install_deps.sh # Format block device (only on first boot) sudo mkfs.ext4 /dev/sdb # Mount all filesystems (persistent volume now available) sudo mount -a # Verify mount df -h /mnt/bosh # Output: /dev/sdb 251G 61M 238G 1% /mnt/bosh # Check BOSH directory symlink ls -la ~/bosh # Output: lrwxrwxrwx 1 ubuntu ubuntu 9 Dec 18 20:37 /home/ubuntu/bosh -> /mnt/bosh # Verify BOSH CLI bosh --version # Output: version 2.0.39-... # Review generated environment files cat ~/my-env-vars.yml cat ~/director-env-vars.yml # These contain all OCI resource IDs and configuration for BOSH deployment ``` -------------------------------- ### Terraform Initialization and Deployment (Bash) Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt This section outlines the bash commands for initializing Terraform, setting up OCI provider credentials, and provisioning the infrastructure. It includes copying an example environment file, exporting Terraform variables, sourcing the environment variables, and running 'terraform init', 'terraform plan', and 'terraform apply'. ```bash # Copy example environment file cp env-vars.example env-vars # Edit env-vars with your OCI credentials # Get these values from OCI Console > User Settings export TF_VAR_oci_tenancy_ocid="ocid1.tenancy.oc1..aaaaaa..." export TF_VAR_oci_user_ocid="ocid1.user.oc1..aaaaaa..." export TF_VAR_oci_fingerprint="12:34:56:78:90:ab:cd:ef..." export TF_VAR_oci_private_key_path="~/.oci/oci_api_key.pem" # Source environment variables source env-vars # Generate all required keys ./bosh-key-gen.sh # Enter passphrase for SSL certificate when prompted # Keys created in ./keys/ directory # Initialize Terraform and download OCI provider terraform init # Review execution plan terraform plan # Apply configuration (takes 5-10 minutes) terraform apply # Type 'yes' when prompted # Expected output: # CompartmentOCID = ["ocid1.compartment.oc1..aaaaaa..."] # InstancePrivateIP = ["10.0.2.4"] # InstancePublicIP = ["129.213.x.x"] # Verify resources in OCI Console: # - Compartment "bosh" created # - VCN "cloudfoundry_vcn" with 7 subnets ``` -------------------------------- ### Install BOSH CLI and Dependencies (Bash) Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt This bash script installs the BOSH CLI v2.0.39 and necessary dependencies (make, ruby) on the bastion instance. It first waits for any active package manager locks before updating packages and installing the BOSH CLI using a direct download. The script is intended to be run on the bastion after its first boot. ```bash #!/usr/bin/env bash # bootstrap/install_deps.sh - Run on bastion after first boot set -e # Wait for package manager lock while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; sleep 0.5 done # Install dependencies sudo apt-get update -y sudo apt-get install -y make ruby # Install BOSH CLI v2.0.39 sudo curl -o /usr/local/bin/bosh https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-2.0.39-linux-amd64 sudo chmod +x /usr/local/bin/bosh # Usage on bastion: # ./install_deps.sh # Verify: bosh --version ``` -------------------------------- ### Deploy BOSH Bastion with Terraform Source: https://github.com/oracle/terraform-oci-cf-install/blob/master/README.md This command applies the Terraform configuration to deploy the BOSH bastion instance and associated OCI infrastructure. It requires prior setup of OCI API keys and SSH key pairs. The output will include the bastion instance's IP address. ```bash terraform apply ``` -------------------------------- ### Initialize Terraform OCI Provider Source: https://github.com/oracle/terraform-oci-cf-install/blob/master/README.md This command initializes a Terraform project, downloading the necessary OCI provider. Ensure Terraform v0.11.10 or later is installed. This is a prerequisite for managing OCI resources with Terraform. ```bash terraform init ``` -------------------------------- ### Source Environment Variables Source: https://github.com/oracle/terraform-oci-cf-install/blob/master/README.md This command sources environment variables from a file, typically used to configure project-specific settings and credentials. It's essential for setting up the environment before running Terraform commands. ```bash . env-var ``` -------------------------------- ### Provision OCI Bastion Instance for BOSH CLI Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt Provisions an Ubuntu 16.04 bastion instance in OCI with specified shape and image. It configures SSH key authentication, iSCSI for persistent storage, and deploys the BOSH CLI. ```hcl # variables.tf - Bastion configuration variable "bastion_ad" { default = "1" } variable "bastion_instance_shape" { default = "VM.Standard1.1" } variable "bastion_image_id" { default = "ocid1.image.oc1.phx.aaaaaaaaxsufrpzn72dvhry5swbuwnuldcn3eko3cx6g7z4tw4qfwkq2zkra" } variable "bastion_instance_os" { default = "Ubuntu" } variable "bastion_instance_os_version" { default = "16.04" } ``` -------------------------------- ### SSH Login to BOSH Bastion Source: https://github.com/oracle/terraform-oci-cf-install/blob/master/README.md This command establishes an SSH connection to the deployed BOSH bastion instance. It uses a specific SSH private key and the instance's IP address. Replace `` with the actual IP obtained after `terraform apply`. ```bash ssh -i keys/bosh-ssh ubuntu@ ``` -------------------------------- ### Generate SSH, OCI API, and SSL Keys (Bash) Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt This bash script automates the generation of SSH keypairs for bastion access, OCI API keys for BOSH user authentication, and SSL certificates for load balancers. It saves the generated keys and certificates in the './keys/' directory. Ensure to enter a passphrase when prompted for SSL certificate generation. ```bash #!/usr/bin/env bash #bosh-key-gen.sh - Run before terraform init # Generate SSH keypair for bastion access ssh-keygen -f keys/bosh-ssh # Generate OCI API Key for BOSH user openssl genrsa -out ./keys/bosh-api-private-key.pem 2048 chmod go-r ./keys/bosh-api-private-key.pem openssl rsa -pubout -in ./keys/bosh-api-private-key.pem -out ./keys/bosh-api-public-key.pem openssl rsa -pubout -outform DER -in ./keys/bosh-api-private-key.pem | openssl md5 -c > ./keys/bosh-api-fingerprint # Generate SSL certificates for load balancers openssl genrsa -des3 -out ./keys/lb-ssl.key 2048 openssl rsa -in ./keys/lb-ssl.key -out ./keys/lb-ssl.key openssl req -new -key ./keys/lb-ssl.key -out ./keys/lb-ssl.csr openssl x509 -req -days 365 -in ./keys/lb-ssl.csr -signkey ./keys/lb-ssl.key -out ./keys/lb-ssl.crt # Usage: # chmod +x bosh-key-gen.sh # ./bosh-key-gen.sh # Enter passphrase when prompted for SSL certificate generation ``` -------------------------------- ### Set Up BOSH Identity and Access Management in OCI Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt Configures OCI Identity and Access Management for BOSH, including creating a compartment, user, group, API key, and policies. This grants necessary permissions for managing OCI resources. ```hcl # variables.tf - Identity configuration variable "bosh_compartment_name" { default = "bosh" } variable "bosh_user_name" { default = "bosh" } variable "bosh_api_public_key" { default = "./keys/bosh-api-public-key.pem" } # identity.tf - Complete IAM setup resource "oci_identity_compartment" "bosh_compartment" { name = var.bosh_compartment_name description = var.bosh_compartment_name } resource "oci_identity_group" "bosh_group" { name = var.bosh_group_name description = var.bosh_group_name } resource "oci_identity_user" "bosh_user" { name = var.bosh_user_name description = var.bosh_user_name } resource "oci_identity_user_group_membership" "bosh_user_group_membership" { compartment_id = oci_identity_compartment.bosh_compartment.id user_id = oci_identity_user.bosh_user.id group_id = oci_identity_group.bosh_group.id } resource "oci_identity_api_key" "bosh_api_key" { user_id = oci_identity_user.bosh_user.id key_value = file(var.bosh_api_public_key) } resource "oci_identity_policy" "bosh_policy" { compartment_id = var.oci_tenancy_ocid name = "${oci_identity_group.bosh_group.name}-policy" description = "bosh policies" statements = [ "allow group ${oci_identity_group.bosh_group.name} to manage instance-family in tenancy", "allow group ${oci_identity_group.bosh_group.name} to manage volume-family in tenancy", "allow group ${oci_identity_group.bosh_group.name} to manage object-family in tenancy", "allow group ${oci_identity_group.bosh_group.name} to manage virtual-network-family in tenancy", "allow group ${oci_identity_group.bosh_group.name} to manage load-balancers in tenancy" ] } ``` -------------------------------- ### Provision Bastion Instance and Attach Block Volume (Terraform) Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt This snippet defines an OCI compute instance to act as a bastion host and attaches an iSCSI block volume for persistent storage. It includes provisioning the instance with specified image, shape, and network details, and attaching a pre-created volume. The volume is intended for BOSH-related data. ```hcl resource "oci_core_instance" "bosh_cli" { availability_domain = lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.bastion_ad - 1], "name") compartment_id = oci_identity_compartment.bosh_compartment.id display_name = "bosh_cli" hostname_label = "bosh-cli" image = var.bastion_image_id shape = var.bastion_instance_shape subnet_id = oci_core_subnet.bastion_subnet_ad1.id metadata { ssh_authorized_keys = file(var.bosh_ssh_public_key) } } resource "null_resource" "remote-exec" { depends_on = ["oci_core_instance.bosh_cli", "oci_core_volume_attachment.bosh_cli_vol_attach"] provisioner "file" { connection { host = data.oci_core_vnic.InstanceVnic.public_ip_address user = "ubuntu" private_key = file(var.bosh_ssh_private_key) } source = "./bootstrap/install_deps.sh" destination = "~/install_deps.sh" } provisioner "remote-exec" { connection { host = data.oci_core_vnic.InstanceVnic.public_ip_address user = "ubuntu" private_key = file(var.bosh_ssh_private_key) } inline = [ "sudo iscsiadm -m node -o new -T ${oci_core_volume_attachment.bosh_cli_vol_attach.iqn} -p ${oci_core_volume_attachment.bosh_cli_vol_attach.ipv4}:${oci_core_volume_attachment.bosh_cli_vol_attach.port}", "sudo iscsiadm -m node -o update -T ${oci_core_volume_attachment.bosh_cli_vol_attach.iqn} -n node.startup -v automatic", "sudo mkdir /mnt/bosh", "sudo chown -R ubuntu:ubuntu /mnt/bosh", "sudo ln -s /mnt/bosh /home/ubuntu/bosh", "echo '/dev/sdb /mnt/bosh ext4 defaults,noatime,_netdev 0 2' | sudo tee --append /etc/fstab > /dev/null", "chmod +x ~/install_deps.sh" ] } } # variables.tf - Volume size variable "256GB" { default = "256" } # block.tf - Volume and attachment resource "oci_core_volume" "bosh_cli_vol" { availability_domain = lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.bastion_ad - 1], "name") compartment_id = oci_identity_compartment.bosh_compartment.id display_name = "bosh_cli_vol" size_in_gbs = var.256GB } resource "oci_core_volume_attachment" "bosh_cli_vol_attach" { attachment_type = "iscsi" compartment_id = oci_identity_compartment.bosh_compartment.id instance_id = oci_core_instance.bosh_cli.id volume_id = oci_core_volume.bosh_cli_vol.id } ``` -------------------------------- ### Configure OCI Security List for Bastion Subnet Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt Defines ingress and egress rules for a security list associated with a bastion subnet in OCI. It allows all egress traffic and specific ingress traffic for SSH, VCN communication, BOSH registry, and ICMP. ```hcl resource "oci_core_security_list" "bastion_subnet" { compartment_id = oci_identity_compartment.bosh_compartment.id display_name = "bastion_all" vcn_id = oci_core_virtual_network.cloudfoundry_vcn.id egress_security_rules = [{ protocol = "all" destination = "0.0.0.0/0" }] ingress_security_rules = [{ # SSH access from internet tcp_options { "max" = 22 "min" = 22 } protocol = "6" source = "0.0.0.0/0" }, { # All TCP from VCN protocol = "6" source = var.vpc_cidr }, { # BOSH registry port from director subnet tcp_options { "max" = 6901 "min" = 6901 } protocol = "6" source = var.director_subnet_ad1_cidr }, { # ICMP from VCN protocol = "1" source = var.vpc_cidr }] } ``` -------------------------------- ### Configure OCI VCN and Internet Gateway with Terraform Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt This snippet defines the Virtual Cloud Network (VCN) and an Internet Gateway for public access in OCI using Terraform. It allows customization of the VCN CIDR block. The created VCN ID and display name are exported for further configuration. ```hcl # variables.tf - Configure the VCN CIDR variable "vpc_cidr" { default = "10.0.0.0/16" } # network.tf - VCN and Internet Gateway resource "oci_core_virtual_network" "cloudfoundry_vcn" { cidr_block = var.vpc_cidr compartment_id = oci_identity_compartment.bosh_compartment.id display_name = "cloudfoundry_vcn" dns_label = "cfvcn" } resource "oci_core_internet_gateway" "cloudfoundry_ig" { compartment_id = oci_identity_compartment.bosh_compartment.id display_name = "cloudfoundry_ig" vcn_id = oci_core_virtual_network.cloudfoundry_vcn.id } # Output usage terraform apply # Creates VCN with DNS label "cfvcn" and internet gateway # VCN ID and display name exported to my-env-vars.yml for BOSH configuration ``` -------------------------------- ### Generate BOSH Director Environment Variables (Terraform) Source: https://context7.com/oracle/terraform-oci-cf-install/llms.txt This Terraform resource creates a YAML file for BOSH Director environment variables. It includes tenancy, user, region, availability domain, subnet, and network configurations necessary for the BOSH Director deployment. The file is saved as './bootstrap/director-env-vars.yml'. ```Terraform resource "local_file" "bosh_cli_director_env_vars" { filename = "./bootstrap/director-env-vars.yml" content = <