Skip to the content.

Terraform Infrastructure Provisioning for Oracle Toolkit for GCP Deployments

You can automate the deployment of Google Cloud infrastructure by using Terraform, an open-source Infrastructure as Code (IaC) tool from Hashicorp, in combination with Ansible for configuration management. This approach allows for a consistent, repeatable, and scalable deployment processes.

This guide provides a comprehensive overview of deploying and configuring infrastructure on Google Cloud using pre-defined Terraform modules integrated with the Oracle Toolkit for GCP Ansible playbooks.


Supported Use Cases

This setup supports the deployment of the following configurations:

This approach is particularly suitable for deploying and configuring:


What the Terraform Configuration Deploys

The Terraform module deploys the following elements:

This infrastructure is modular and customizable, allowing you to tailor it to specific application needs or organizational requirements.


Instance naming convention

For single-instance deployments, the VM will be named using the pattern: “-1". Example: If instance_name = "oracle-db", the resulting VM will be oracle-db-1.

For multi-node Oracle Data Guard deployments:

Example: If instance_name = “oracle-db”, the primary VM will be oracle-db-1 and the standby VM will be oracle-db-2.


Pre-requisites

To use this Terraform and Ansible integration, ensure you have the following tools installed:

1. Service Account for the Control Node VM

Grant the service account attached to the control node VM the following IAM roles:

2. Service Account for the database VM

2. Firewall Rule for Internal IP Access

Create a VPC firewall rule that allows ingress on TCP port 22 (or your custom SSH port) from the control node VM to the target VM.
Since both VMs reside in the same VPC, a rule permitting traffic on port 22 between their subnets or network tags is sufficient.

3. Terraform State Bucket

Create a Cloud Storage bucket to store Terraform state files. Authorize the control node service account with read and write access to this bucket.

4. Toolkit Source Bucket

Create a Cloud Storage bucket to store the oracle-toolkit ZIP file.

Clone the toolkit repository and prepare the ZIP archive:

git clone https://github.com/google/oracle-toolkit.git
cd oracle-toolkit
zip -r /tmp/oracle-toolkit.zip . -x "terraform/*" -x ".git/*"

Upload the ZIP file to your GCS bucket:

gsutil cp /tmp/oracle-toolkit.zip gs://your-bucket-name/

Project Directory Structure

The project directory structure is as follows:

repo-root/
├── install-oracle.sh               # Main deployment script for Ansible
├── check-instance.yml
├── prep-host.yml
├── install-sw.yml
├── config-db.yml
├── config-rac-db.yml
└── terraform/
    ├── backend.tf                  # Backend confguration, from example
    ├── terraform.tfvars            # Variables to set, from example
    ├── main.tf                     # Main Terraform code
    ├── variables.tf                # Variable definition
    └── versions.tf                 # Version dependencies

Setup and Deployment Steps

  1. Google Cloud Authentication Authenticate using the Google Cloud SDK:
gcloud auth login
gcloud auth application-default login

Set your project ID:

gcloud config set project PROJECT_ID
  1. Review and Edit Terraform Backend Configuration

    Copy terraform/backend.tf.example to terraform/backend.tf and define your backend settings for your state file prefix and storage bucket.

  2. Review and Edit Terraform Module Configuration

    Copy terraform/terraform.tfvars.example to terraform/terraform.tfvars and define your deployment settings.

NOTE There is no need to supply the toolkit script parameters --instance-ip-addr, --instance-ssh-user, and --instance-ssh-key - these are automatically added by the Terraform commands.

  1. Initialize and Apply Terraform

    Navigate to the terraform directory and initialize Terraform:

cd terraform
terraform init

Review the execution plan:

terraform plan

Deploy the infrastructure:

terraform apply

This process will perform the following steps:

  1. View startup execution logs To view logs from startup script execution on the control node VM, fetch the Terraform output variable control_node_log_url and paste into a browser to open Logs Explorer, filtered to control node output only.
terraform output control_node_log_url
  1. Verify Ansible Execution

    Once deployment is complete, review the Ansible output to verify that the playbooks ran successfully:

PLAY [dbasm] *******************************************************************

TASK [Verify that Ansible on control node meets the version requirements] ******
ok: [VM_PUBLIC_IP] => {
    "changed": false,
    "msg": "Ansible version is 2.9.27, continuing"
}

TASK [Test connectivity to target instance via ping] ***************************
ok: [VM_PUBLIC_IP]
  1. Clean Up Resources

    To destroy all the resources created by Terraform:

terraform destroy

Ansible Cloud Logging callback plugin

This callback plugin sends Ansible playbook logs to Google Cloud Logging in structured JSON format.

Setup

To enable the plugin, add the following to your ansible.cfg:

[defaults]
callback_plugins = ./tools/callback_plugins

Configuration (ansible.cfg)

Under the [cloud_logging] section, you can configure:

[cloud_logging]
project = your-project                   # Required: GCP project ID
log_name = ansible_cloud_logging         # Optional: defaults to 'ansible_cloud_logging'
ignore_gcp_api_errors = false            # Optional: if true (default), GCP API errors are ignored and do not cause Ansible to fail
print_uuid = true                        # Optional: print UUID for each playbook execution
enable_async_logging = true              # Optional:  If true (default), log messages are queued and sent by a background thread to avoid blocking Ansible execution

When enable_async_logging is enabled, logs are queued and sent by a background thread to avoid blocking Ansible execution. Otherwise, logs are sent synchronously.

Troubleshooting

Common Issues

  1. No Such File or Directory