Automating OracleDB@GCP ADB-S with GitHub Actions — Part 2
Share on LinkedIn ↗Provisioning another database should not require copying scripts, editing hard-coded values, and repeating deployment commands manually. As environments grow, that approach makes it harder to keep configurations consistent, review changes, and track who deployed what. We need a reusable configuration and a CI/CD process that validates the code, previews infrastructure changes, and requires approval before applying them.
In Part 1, we used Terraform code to provision Oracle Autonomous Database Serverless on Google Cloud. In Part 2, we will make that code dynamic by using configurable inputs, then use GitHub Actions workflows to provision resources from the same reusable configuration.
We will store the code in GitHub and build a CI/CD pipeline around it. Continuous integration (CI) will check Terraform formatting and validate the configuration. The deployment workflow will use the selected inputs to generate a plan, pause for review, and apply that saved plan only after approval. Shared Terraform state and keyless Google Cloud authentication will let the workflow manage the deployment without relying on a particular Windows computer.
For this example, we will prepare and review a plan for a separate Oracle Database 19c Autonomous Database Serverless environment. The workflow also provides optional deployment and cleanup operations. We will use distinct resource names and a separate Terraform state location to keep the existing 26ai deployment independent.
1. Create a new GitHub repository
Sign in to GitHub and select + → New repository.
- Select your GitHub account under Owner.
- Enter oracledb-gcp-terraform-reusable as the repository name.
- Add the description Reusable Terraform and GitHub Actions for Oracle Database@Google Cloud.
- Select the visibility appropriate for your organization. This example uses public source code; deployment approval features depend on your GitHub plan and repository visibility.
- Enable Add README. Leave the generated ignore file and license options unselected for now.
- Select Create repository.
The repository stores the source files and their history. Creating it does not provision cloud resources. See GitHub's repository creation guide.


2. Clone the repository and open VS Code
Install Git for Windows if needed, then restart VS Code. On GitHub, select Code → HTTPS and copy the clone URL. Open a PowerShell terminal and replace YOUR_GITHUB_OWNER below:
New-Item -ItemType Directory -Force C:\TerraformProjects
Set-Location C:\TerraformProjects
git clone https://github.com/YOUR_GITHUB_OWNER/oracledb-gcp-terraform-reusable.git
Set-Location .\oracledb-gcp-terraform-reusable
code .
VS Code opens the local copy. The Explorer should show the new repository and README.md. Use this new directory throughout the walkthrough.

3. Add the Terraform source and organize the files
In VS Code Explorer, select New Folder and create terraform. Create .github, then workflows inside it. Bring the source configuration from Part 1 into terraform, then apply the configurable input changes described below. Copy source files individually; leave caches, existing state, saved plans, populated personal inputs, wallets, and private keys behind.
oracledb-gcp-terraform-reusable/
├─ README.md
├─ .gitignore
├─ .github/workflows/
│ ├─ terraform-checks.yml
│ └─ terraform-19c.yml
└─ terraform/
├─ versions.tf
├─ providers.tf
├─ variables.tf
├─ main.tf
├─ client.tf
├─ outputs.tf
├─ backend.tf
├─ .terraform.lock.hcl
└─ environments/
├─ 19c.tfvars.example
└─ 19c.tfvars
| File | Purpose |
|---|---|
versions.tf |
Terraform and Google provider version requirements |
providers.tf |
Project and region references |
variables.tf |
Configurable inputs |
main.tf |
VPC, subnets, ODB network, and database |
client.tf |
Client VM, IAP SSH firewall, router, and NAT |
outputs.tf |
Resource IDs and VM information |
backend.tf |
Remote-state backend |
19c.tfvars |
Non-secret inputs explicitly selected by the workflow |
Create .gitignore at the repository root and paste:
**/.terraform/
**/*.tfstate
**/*.tfstate.*
**/*.tfplan
**/plan-review.txt
**/terraform.tfvars
**/*.auto.tfvars
**/backend.hcl
**/gha-creds-*.json
**/crash.log
**/*[Ww]allet*
**/*.ppk
**/*.pem
The selected environments/19c.tfvars file is intentionally versioned because it contains only non-secret settings. Inspect staged files before pushing.

Make the Terraform code reusable
We will supply the database name, version, network ranges, and sizing as inputs so the same Terraform code can provision a separate 19c environment. This example uses its own resource names and Terraform state prefix.
| Setting | 19c example |
|---|---|
| Database version | 19c |
| Region | us-east4 |
| GCP Oracle zone | us-east4-b-r1 |
| Database ECPUs | 2 |
| Configured storage | 1 TB |
| Resource prefix | adbs-19c |
| State prefix | adbs/19c-example |
The new example follows the same network design, using different subnet ranges and resource names. A new state must own only the new example's resources. Project-wide API enablement must remain managed by one configuration rather than being owned by both states.
We queried the service in us-east4 and confirmed that 19c is listed for the OLTP workload:
gcloud oracle-database autonomous-db-versions list --location=us-east4 --project=YOUR_PROJECT_ID --format=json
Create a deployment input file in VS Code
Use variables to supply the database names and sizing. Select 19c or 26ai in the workflow's Database version field. For this example, we will select 19c.
In the VS Code Explorer, right-click terraform, select New Folder, and name it environments. Right-click that folder, select New File, and enter 19c.tfvars.example. Add the following contents and save with Ctrl+S.

# Separate 19c example: use only with its dedicated state prefix adbs/19c-example.
# Do not apply these values against the Part 1 state.
project_id = "YOUR_PROJECT_ID"
region = "us-east4"
gcp_oracle_zone = "us-east4-b-r1"
name_prefix = "adbs-19c"
database_resource_id = "adbs-19c-database"
database_name = "ADBS19C"
database_display_name = "ADBS-19c"
private_endpoint_label = "adbs19c"
database_version = "19c"
create_database = true
compute_count = 2
storage_tb = 1
# Example ranges: verify they do not overlap connected networks.
client_cidr = "10.30.0.0/24"
database_cidr = "10.31.0.0/24"
client_vm_zone = "us-east4-b"
client_vm_machine_type = "e2-small"
deletion_protection = true
# Supply contact_email and admin_password securely through the workflow.
# Workflow/state isolation and shared API ownership must be configured before use.
project_id selects the deployment project. region and gcp_oracle_zone select the service location. name_prefix names the new network resources; the next four inputs name the database resource, Oracle database, display name, and private endpoint. database_version selects 19c, while compute_count and storage_tb set its capacity.
The two CIDR values are example address ranges for the application and ODB client subnets. Check them against your connected networks before use. client_vm_zone and client_vm_machine_type configure the client VM. Keep deletion protection enabled during creation; we will disable it through a reviewed change before cleanup.
The .example suffix makes this a template. Terraform does not automatically load it. The workflow will select the example's configuration explicitly and supply the project, notification address, and password separately. Do not run it against another deployment's state.
Save the configuration selected by the workflow

Create terraform/environments/19c.tfvars with these non-secret settings. Leave project_id out because the workflow supplies it from a repository variable; a file assignment would take precedence over that environment value.
# Separate 19c example: use only with its dedicated state prefix adbs/19c-example.
# Workflow selects only the dedicated 19c state.
region = "us-east4"
gcp_oracle_zone = "us-east4-b-r1"
name_prefix = "adbs-19c"
database_resource_id = "adbs-19c-database"
database_name = "ADBS19C"
database_display_name = "ADBS-19c"
private_endpoint_label = "adbs19c"
database_version = "19c"
create_database = true
compute_count = 2
storage_tb = 1
# Example ranges: verify they do not overlap connected networks.
client_cidr = "10.30.0.0/24"
database_cidr = "10.31.0.0/24"
client_vm_zone = "us-east4-b"
client_vm_machine_type = "e2-small"
deletion_protection = true
# Supply contact_email and admin_password securely through the workflow.
# Existing project APIs remain owned by their original state.
manage_project_apis = false
Connect the inputs to the database resource
Open terraform/main.tf and locate google_oracle_database_autonomous_database. Replace the fixed database names with variable references. Terraform uses the values supplied for this deployment when it builds the plan.

autonomous_database_id = coalesce(var.database_resource_id, "${var.name_prefix}-26ai")
database = var.database_name
display_name = var.database_display_name
The coalesce expression uses database_resource_id when it is supplied. The 19c template sets that value to adbs-19c-database. The fallback preserves compatibility with the original configuration; it does not select the database version.
Inside the resource's properties block, keep these references:
db_version = var.database_version
compute_count = var.compute_count
data_storage_size_tb = var.storage_tb
private_endpoint_label = var.private_endpoint_label
db_version receives 19c from the input file. The network references continue to use the ODB network and client subnet created by the same configuration. Terraform builds their dependency order from these references.
Declare each new naming input in variables.tf before using it. The next step shows those declarations. These snippets explain the changes within the existing resource; they are not a replacement for the complete main.tf file.
Declare the configurable database names
Open terraform/variables.tf, add these declarations, and save the file. Each declaration gives Terraform an input name and a type. The defaults retain compatibility with the original code; the 19c input file explicitly overrides them for this example.

# CUSTOMIZE before creating a separate deployment. Existing defaults preserve Part 1.
variable "database_resource_id" {
type = string
default = null
description = "Google Cloud database resource ID; null preserves the Part 1 name."
}
variable "database_name" {
type = string
default = "ADBS26AI"
description = "Oracle database name, distinct for each database."
}
variable "database_display_name" {
type = string
default = "ADBS-26ai"
}
variable "private_endpoint_label" {
type = string
default = "adbs26ai"
}
database_resource_id defaults to null, allowing the resource expression to use its fallback only when no ID is supplied. The other three inputs are strings. Supplying the 19c values in the selected input file overrides these defaults without editing the resource block for each database.
Configure private remote state
Terraform state records the resources managed by this configuration. GitHub runners are temporary, so we will store state in a private Cloud Storage bucket. Create a globally unique bucket with uniform bucket-level access and public access prevention, then enable versioning. If an authorized private state bucket already exists, use it instead of creating another:
gcloud storage buckets create gs://YOUR_UNIQUE_STATE_BUCKET --project=YOUR_PROJECT_ID --location=us-east4 --uniform-bucket-level-access --public-access-prevention
gcloud storage buckets update gs://YOUR_UNIQUE_STATE_BUCKET --versioning
In Google Cloud Console, open Cloud Storage → Buckets and select the bucket. Confirm Not public and Object versioning. The screenshot below shows the bucket settings to check. State can contain sensitive values, so do not upload it to GitHub or display its contents in screenshots.

Configure remote state for the new deployment
Create terraform/backend.tf:
terraform {
backend "gcs" {}
}

The workflow supplies the bucket and the dedicated adbs/19c-example prefix when it initializes Terraform:
terraform init -input=false -lockfile=readonly -backend-config="bucket=$STATE_BUCKET" -backend-config="prefix=adbs/19c-example"
This is a new deployment, so there is no existing state to migrate. Its first apply writes resource records to adbs/19c-example/default.tfstate. Creation, updates, and destruction must use that same location. See the GCS backend documentation.
Validate the configuration in GitHub Actions
Create .github/workflows/terraform-checks.yml in the repository. This workflow checks formatting and validates the Terraform configuration without accessing cloud state or deploying resources.
name: Terraform checks
# Runs checks only; this workflow cannot deploy resources.
on:
push:
branches: [main]
paths: ['terraform/**', '.github/workflows/terraform-checks.yml']
pull_request:
paths: ['terraform/**', '.github/workflows/terraform-checks.yml']
workflow_dispatch:
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-24.04
timeout-minutes: 10
defaults:
run:
working-directory: terraform
steps:
- name: Check out source
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
- name: Install Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
with:
terraform_version: 1.16.6
terraform_wrapper: false
- name: Check formatting
run: terraform fmt -check
- name: Initialize provider without connecting to state
run: terraform init -backend=false -input=false -lockfile=readonly
- name: Validate configuration
run: terraform validate
Before committing the dependency lock file, record the provider checksums for both the Windows workstation and Linux runner:
terraform providers lock -platform=windows_amd64 -platform=linux_amd64
Commit .terraform.lock.hcl with the configuration. After pushing the files, open Actions and inspect the formatting, initialization, and validation steps. A successful checks run confirms configuration validation, not resource creation.

Why GitHub Actions needs a service account
When we run Terraform on our computer, we sign in with our own Google account. GitHub Actions runs Terraform on a separate runner, so it needs an identity that Google Cloud can recognize and authorize. We use a service account as the workflow's deployment identity.
The service account's IAM roles determine which actions the workflow can perform, such as creating an ODB network, provisioning a database, or managing the client VM. Creating the account alone does not grant those permissions; we assign the required roles separately.
We will use Workload Identity Federation to let the trusted GitHub workflow act as this service account with short-lived credentials. We do not download a service account JSON key or save our personal Google password in GitHub. There are two separate settings: federation controls which workflow may use the identity, while IAM roles control what that identity may do in Google Cloud.
Create the service account in Google Cloud Console
- Select the Google Cloud project where you will provision the resources.
- Open IAM & Admin → Service Accounts.
- Select Create service account at the top of the page.
- Enter ADBS Reusable GitHub Actions as the service account name.
- Set the service account ID to adbs-reusable-deployer. Google forms its email as
adbs-reusable-deployer@YOUR_PROJECT_ID.iam.gserviceaccount.com. - Enter a description such as Deployment identity for the reusable Terraform GitHub repository.
- Select Create and continue. Assign the deployment roles described below, or finish creating the identity and grant them from the project's IAM page afterward.
- Leave optional user access grants empty for now and select Done. We will configure workflow impersonation through federation in the next step.
The captured screen below shows the completed account. Its Enabled status means the identity is active. No keys means no user-managed service account key is present; this is expected for our federation setup. The other accounts shown on the page belong to separate uses. Select only adbs-reusable-deployer for this workflow.

Grant the deployment permissions
Open IAM & Admin → IAM → Grant access, enter the new service account email, and add these roles. Select Add another role for each additional role, then save.
| Role | Why the workflow needs it |
|---|---|
| Oracle Database@Google Cloud admin | Manage the ODB network, ODB subnet, and Autonomous Database |
| Compute Network Admin | Manage the VPC, application subnet, Cloud Router, and NAT |
| Compute Security Admin | Create the IAP SSH firewall rule |
| Compute Instance Admin (v1) | Create and remove the private client VM |
| Service Usage Viewer | Check that the required project APIs are enabled |
These predefined roles apply across the project. They are convenient for this example; an organization can evaluate custom roles with narrower permissions.

Next, open Cloud Storage → Buckets → the private Terraform state bucket → Permissions → Grant access. Enter the same service account email and grant Storage Object Admin on this bucket. This allows the workflow to read and update state, manage the lock object, and store the private saved plan. Do not grant storage access across all project buckets for this example.
The deployment service account does not need a JSON key. Do not select Keys → Add key → Create new key for this setup.
Allow the new repository to use the service account
Open IAM & Admin → Workload Identity Federation. Create pool adbs-reusable-github, then add an OpenID Connect provider named github, using issuer https://token.actions.githubusercontent.com.


Add these attribute mappings:
google.subject = assertion.sub
attribute.repository_id = assertion.repository_id
attribute.repository_owner_id = assertion.repository_owner_id
attribute.ref = assertion.ref
Read the new repository's numeric id and owner.id from https://api.github.com/repos/YOUR_GITHUB_OWNER/oracledb-gcp-terraform-reusable. Use those values in the provider condition:
assertion.repository_id == 'YOUR_REPOSITORY_ID' &&
assertion.repository_owner_id == 'YOUR_OWNER_ID' &&
assertion.ref == 'refs/heads/main' &&
(assertion.sub == 'repo:YOUR_GITHUB_OWNER/oracledb-gcp-terraform-reusable:environment:terraform-plan' ||
assertion.sub == 'repo:YOUR_GITHUB_OWNER/oracledb-gcp-terraform-reusable:environment:terraform-apply')
On the pool's Grant access action, select the new service account and restrict access using the mapped repository_id attribute. Verify that the resulting Workload Identity User binding permits this repository to impersonate the service account. A provider restricted to another repository will not authenticate this new repository.
Screenshot to add: new service account, provider condition, and connected account. The new repository requires its own trust configuration.
Configure GitHub variables and the password secret
Open the repository in GitHub, select Settings → Secrets and variables → Actions, and select the Variables tab. Click New repository variable, enter each name and its value, and save it.
| Variable | Value to supply |
|---|---|
GCP_PROJECT_ID |
The Google Cloud project ID |
TF_SERVICE_ACCOUNT |
The deployment service account email |
WIF_PROVIDER |
The full workload identity provider resource name |
TF_STATE_BUCKET |
The private state bucket name, without gs:// |
These identify the deployment target; they are not service account keys.

Open Settings → Environments → New environment and create terraform-plan. Limit its deployment branches to main. Under Environment secrets, add ADB19C_ADMIN_PASSWORD. Enter the new database creation password privately and save it. Do not put the password in source files or screenshots.


Create a second environment named terraform-apply. Select Required reviewers, add the intended reviewer, restrict deployment branches to main, and save the rules. Disable administrator bypass if approvals must apply to administrators too. Our single-owner example permits self-review; a team can require a different reviewer.

GitHub environment protection availability depends on the repository visibility and GitHub plan. Check GitHub's environment documentation if these controls are unavailable.
Create a reusable workflow for 19c or 26ai
In VS Code, expand .github/workflows and create terraform-19c.yml. Despite its example filename, this workflow supports 19c or 26ai through the Database version dropdown in Run workflow. Select the version you want to provision; the workflow passes that choice to Terraform's database_version variable, overriding the version in the input file. The Terraform resource definitions remain the same.
For this walkthrough, we select 19c and use environments/19c.tfvars with the dedicated state prefix adbs/19c-example. To use this example for a new 26ai deployment instead, choose 26ai before the first deployment. The example's resource names still come from the input file; choosing a version does not rename resources or create a separate state automatically.
To keep both databases as independent deployments, give the second deployment its own resource names, input file, password secret, and state prefix, and configure the workflow to use that deployment's inputs and backend prefix in both plan and apply. Do not switch the version of an already deployed environment expecting another database to be added. Keep the original version selected when updating or cleaning up that environment.

Paste the complete workflow below into terraform-19c.yml and save it:
Choose new or existing networks
In Run workflow, choose Network mode before starting the plan:
| Choice | What Terraform manages |
|---|---|
create |
A new VPC, application subnet, ODB network and Client ODB subnet, plus the database and client VM infrastructure. |
existing |
A new database and client VM with its IAP SSH firewall rule, using the network IDs you provide. Existing networks, subnets, router and NAT remain outside this deployment's state. |
For create, leave the four existing-network fields blank. For existing, provide full resource IDs:
existing_vpc_id: projects/YOUR_PROJECT_ID/global/networks/YOUR_VPC
existing_application_subnet_id: projects/YOUR_PROJECT_ID/regions/us-east4/subnetworks/YOUR_APP_SUBNET
existing_odb_network_id: projects/YOUR_PROJECT_ID/locations/us-east4/odbNetworks/YOUR_ODB_NETWORK
existing_odb_subnet_id: projects/YOUR_PROJECT_ID/locations/us-east4/odbNetworks/YOUR_ODB_NETWORK/odbSubnets/YOUR_CLIENT_ODB_SUBNET
Select resources in the same project and deployment region. The application subnet must belong to the supplied VPC, and the ODB network must be associated with that VPC. The ODB subnet must be a Client subnet in that ODB network. Confirm available address capacity, private connectivity and DNS before applying. If the new VM needs internet access for packages, the existing application subnet needs suitable outbound access; existing mode does not create a router or Cloud NAT.
The workflow passes these values to network-selection.tf. Conditional resource counts create networks only in create mode; local values select either their generated IDs or your existing IDs. The existing resources are referenced, not imported into this state. Destroying this example removes its database, VM and firewall rule while retaining the supplied networks.
Keep the selected network mode and IDs unchanged for later runs and cleanup. Changing modes after deployment can propose deletion of managed networks or database replacement. Review the plan; use a separate state prefix and unique resource names for another independent deployment. The current workflow still targets one example at adbs/19c-example.
For this walkthrough, select create and database version 19c. Leave confirmation blank for deploy; it is required only for prepare-destroy and destroy. Deployment does not schedule automatic cleanup.
name: Terraform 19c create and destroy
# Manual only. The environment approval must be configured in GitHub settings.
on:
workflow_dispatch:
inputs:
network_mode:
description: Create new networks or use existing networks (keep unchanged for cleanup)
required: true
type: choice
options: [create, existing]
default: create
client_cidr:
description: New application subnet IPv4 CIDR (create mode; keep unchanged for cleanup)
type: string
default: '10.30.0.0/24'
database_cidr:
description: New ODB client subnet IPv4 CIDR (create mode; keep unchanged for cleanup)
type: string
default: '10.31.0.0/24'
existing_vpc_id:
description: Existing VPC full resource ID (existing mode only)
type: string
existing_application_subnet_id:
description: Existing application subnet full resource ID for the new VM
type: string
existing_odb_network_id:
description: Existing ODB network full resource ID
type: string
existing_odb_subnet_id:
description: Existing Client ODB subnet full resource ID
type: string
database_version:
description: Database version for this deployment (keep unchanged for cleanup)
required: true
type: choice
options: ['19c', '26ai']
default: '19c'
operation:
description: Create/update, disable deletion protection, or destroy the 19c example
required: true
type: choice
options: [deploy, prepare-destroy, destroy]
default: deploy
cleanup_scope:
description: Cleanup scope; keep the same choice for prepare-destroy and destroy
required: true
type: choice
options: [all, database-only, client-only, odb-network-and-database]
default: all
confirmation:
description: For prepare-destroy or destroy, type adbs-19c
required: false
type: string
contact_email:
description: Notification email for the separate 19c example
required: true
type: string
permissions:
contents: read
concurrency:
group: adbs-19c-example
cancel-in-progress: false
env:
TF_IN_AUTOMATION: 'true'
TF_INPUT: 'false'
STATE_BUCKET: ${{ vars.TF_STATE_BUCKET }}
jobs:
plan:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
timeout-minutes: 20
environment: terraform-plan
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: terraform
shell: bash
outputs:
plan_sha256: ${{ steps.plan.outputs.sha256 }}
env:
TF_VAR_project_id: ${{ vars.GCP_PROJECT_ID }}
TF_VAR_contact_email: ${{ inputs.contact_email }}
TF_VAR_admin_password: ${{ secrets.ADB19C_ADMIN_PASSWORD }}
NETWORK_MODE: ${{ inputs.network_mode }}
CLIENT_CIDR: ${{ inputs.client_cidr }}
DATABASE_CIDR: ${{ inputs.database_cidr }}
EXISTING_VPC: ${{ inputs.existing_vpc_id }}
EXISTING_APP_SUBNET: ${{ inputs.existing_application_subnet_id }}
EXISTING_ODB_NETWORK: ${{ inputs.existing_odb_network_id }}
EXISTING_ODB_SUBNET: ${{ inputs.existing_odb_subnet_id }}
SELECTED_DATABASE_VERSION: ${{ inputs.database_version }}
REQUESTED_OPERATION: ${{ inputs.operation }}
CLEANUP_SCOPE: ${{ inputs.cleanup_scope }}
CONFIRMATION: ${{ inputs.confirmation }}
steps:
- name: Check out the selected commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
- name: Install Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
with:
terraform_version: 1.16.6
terraform_wrapper: false
- name: Check non-secret workflow identity claims
run: |
python3 - <<'PY'
import os, json, base64, urllib.request
request = urllib.request.Request(os.environ['ACTIONS_ID_TOKEN_REQUEST_URL'] + '&audience=identity-diagnostics', headers={'Authorization': 'Bearer ' + os.environ['ACTIONS_ID_TOKEN_REQUEST_TOKEN']})
token = json.load(urllib.request.urlopen(request))['value']
claims = json.loads(base64.urlsafe_b64decode(token.split('.')[1] + '=='))
for key in ['sub', 'ref', 'repository_id', 'repository_owner_id']:
print(key + ': ' + str(claims.get(key)))
PY
- name: Authenticate through Workload Identity Federation
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
project_id: ${{ vars.GCP_PROJECT_ID }}
workload_identity_provider: ${{ vars.WIF_PROVIDER }}
service_account: ${{ vars.TF_SERVICE_ACCOUNT }}
- name: Install Google Cloud CLI
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3
- name: Check required configuration
run: |
test -n "$STATE_BUCKET"
test -n "$TF_VAR_project_id"
test -n "$TF_VAR_admin_password"
test -n "$TF_VAR_contact_email"
case "$NETWORK_MODE" in
create) python3 ../scripts/check-network-inputs.py "$CLIENT_CIDR" "$DATABASE_CIDR" ;;
existing)
test -n "$EXISTING_VPC"
test -n "$EXISTING_APP_SUBNET"
test -n "$EXISTING_ODB_NETWORK"
test -n "$EXISTING_ODB_SUBNET"
;;
*) exit 1 ;;
esac
case "$CLEANUP_SCOPE" in
all|database-only|client-only) ;;
odb-network-and-database)
test "$NETWORK_MODE" = create || { echo 'Reused ODB networks cannot be deleted by this deployment'; exit 1; }
;;
*) exit 1 ;;
esac
case "$SELECTED_DATABASE_VERSION" in
19c|26ai) ;;
*) echo 'Unsupported database version'; exit 1 ;;
esac
case "$REQUESTED_OPERATION" in
deploy) ;;
prepare-destroy|destroy) test "$CONFIRMATION" = "adbs-19c" ;;
*) exit 1 ;;
esac
# These project-wide APIs are prerequisites, not owned by this example state.
for api in compute.googleapis.com oracledatabase.googleapis.com iap.googleapis.com; do
gcloud services list --enabled --project="$TF_VAR_project_id" --format="value(config.name)" | grep -Fx "$api" > /dev/null
done
- name: Initialize shared state and validate
run: |
terraform fmt -check
terraform init -input=false -lockfile=readonly -backend-config="bucket=$STATE_BUCKET" -backend-config="prefix=adbs/19c-example"
terraform validate
- name: Create and display the plan
id: plan
run: |
# Explicit CLI input overrides the sample file's version assignment.
args=(-var-file=environments/19c.tfvars "-var=database_version=$SELECTED_DATABASE_VERSION")
args+=("-var=network_mode=$NETWORK_MODE" "-var=existing_vpc_id=$EXISTING_VPC" "-var=existing_application_subnet_id=$EXISTING_APP_SUBNET" "-var=existing_odb_network_id=$EXISTING_ODB_NETWORK" "-var=existing_odb_subnet_id=$EXISTING_ODB_SUBNET")
if [ "$NETWORK_MODE" = create ]; then
args+=("-var=client_cidr=$CLIENT_CIDR" "-var=database_cidr=$DATABASE_CIDR")
fi
case "$REQUESTED_OPERATION" in
deploy) ;;
prepare-destroy) args+=(-var=deletion_protection=false) ;;
destroy)
args+=(-var=deletion_protection=false)
case "$CLEANUP_SCOPE" in
all) args+=(-destroy) ;;
database-only) args+=(-var=retain_database=false) ;;
client-only) args+=(-var=retain_client=false) ;;
odb-network-and-database) args+=(-var=retain_database=false -var=retain_odb_network=false) ;;
esac
;;
esac
terraform plan -input=false -lock-timeout=5m "${args[@]}" -out=deployment.tfplan
if [ "$REQUESTED_OPERATION" = destroy ] && [ "$CLEANUP_SCOPE" != all ]; then
terraform show -json deployment.tfplan > cleanup-plan.json
python3 ../scripts/check-cleanup-plan.py "$CLEANUP_SCOPE" cleanup-plan.json
rm -f cleanup-plan.json
fi
terraform show -no-color deployment.tfplan
echo "sha256=$(sha256sum deployment.tfplan | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
echo 'Review the Terraform plan in this job before approving terraform-apply.' >> "$GITHUB_STEP_SUMMARY"
- name: Store the saved plan privately
# Binary plans can contain secrets. Never upload them as public-repo artifacts.
run: |
gcloud storage cp deployment.tfplan "gs://$STATE_BUCKET/private-plans/$GITHUB_RUN_ID/$GITHUB_RUN_ATTEMPT/deployment.tfplan" --if-generation-match=0
apply:
needs: plan
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
timeout-minutes: 90
# GitHub pauses here for the configured required reviewer.
environment: terraform-apply
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: terraform
shell: bash
env:
EXPECTED_PLAN_SHA256: ${{ needs.plan.outputs.plan_sha256 }}
steps:
- name: Check out the same commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Install Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
with:
terraform_version: 1.16.6
terraform_wrapper: false
- name: Authenticate through Workload Identity Federation
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
project_id: ${{ vars.GCP_PROJECT_ID }}
workload_identity_provider: ${{ vars.WIF_PROVIDER }}
service_account: ${{ vars.TF_SERVICE_ACCOUNT }}
- name: Install Google Cloud CLI
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3
- name: Download and verify the reviewed plan
run: |
gcloud storage cp "gs://$STATE_BUCKET/private-plans/$GITHUB_RUN_ID/$GITHUB_RUN_ATTEMPT/deployment.tfplan" deployment.tfplan
echo "$EXPECTED_PLAN_SHA256 deployment.tfplan" | sha256sum --check
- name: Apply the saved plan
run: |
terraform init -input=false -lockfile=readonly -backend-config="bucket=$STATE_BUCKET" -backend-config="prefix=adbs/19c-example"
terraform apply -input=false -lock-timeout=5m deployment.tfplan
- name: Remove the temporary private plan
if: always()
run: |
rm -f deployment.tfplan
gcloud storage rm "gs://$STATE_BUCKET/private-plans/$GITHUB_RUN_ID/$GITHUB_RUN_ATTEMPT/deployment.tfplan"
The workflow's Database version choice supplies the Terraform database_version variable. Choose 19c or 26ai when starting the run. The workflow passes the selected value explicitly on the Terraform command line, overriding the sample input file's version. This ensures that the user's choice is used.
terraform plan -var-file=environments/19c.tfvars "-var=database_version=$SELECTED_DATABASE_VERSION" -out=deployment.tfplan
Keep the version unchanged when updating or destroying that deployment. Choosing a different version against the same state is a change to the existing deployment, not a request to create another independent database. The sample filename and names identify the example; they do not force the database engine version.
The workflow's manual trigger offers three operations:
| Operation | Purpose |
|---|---|
deploy |
Plan creation or updates for this example, then apply after review |
prepare-destroy |
Plan and apply disabling deletion protection before cleanup |
destroy |
Create a destroy plan for the example's dedicated state, then apply after review |
The last two choices require typing adbs-19c in the confirmation field. All three operations still pass through the deployment approval. The concurrency group serializes this example's runs, while the GCS backend provides state locking.
The plan job reads ADB19C_ADMIN_PASSWORD from the terraform-plan environment. Add this as a new secret; keep any existing database password secret unchanged. Open Settings → Environments → terraform-plan → Add environment secret, enter that name, and supply the new database creation password privately. Capture only the saved secret name after the value is hidden.
How the database password is supplied
When running Terraform locally in PowerShell, we can ask the user to enter a password with masked input using Read-Host -AsSecureString. GitHub Actions runs on a remote runner and cannot stop to display an interactive masked password prompt.
For this workflow, enter the password privately once as the GitHub environment secret ADB19C_ADMIN_PASSWORD. The plan job passes that secret to Terraform through an environment variable:
TF_VAR_admin_password: ${{ secrets.ADB19C_ADMIN_PASSWORD }}
Terraform maps TF_VAR_admin_password to its sensitive input variable admin_password. Do not enter the password in the Run workflow form: workflow dispatch text fields are not secret fields. Do not add it to the input template, source code, logs, or screenshots. For the screenshot, show only the saved secret's name after closing the entry form.
The secret is reused on later runs, so the workflow does not ask for the password each time. A separate database can use a separate secret. Updating this secret alone does not rotate an existing database password: this configuration uses it for creation and ignores later changes to that resource attribute.
Marking an input sensitive hides it from normal Terraform output; it does not remove it from state or saved binary plans. Keep those files in private storage.
The workflow checks that the project APIs are already enabled. The new input file sets manage_project_apis = false so its state does not take ownership of shared project-wide API enablement. Its cleanup covers only resources belonging to the new example.
Commit the files and run the workflow
Review VS Code's Source Control file list before staging. State, saved plans, private keys, and wallets must be absent. From the repository root, run:
git status --short
git add scripts/check-network-inputs.py scripts/check-cleanup-plan.py README.md .gitignore .github/workflows/terraform-checks.yml .github/workflows/terraform-19c.yml terraform/*.tf terraform/.terraform.lock.hcl terraform/environments/19c.tfvars terraform/environments/19c.tfvars.example
git diff --cached --stat
git commit -m "Add reusable Terraform and reviewed 19c deployment"
git push origin main
Complete GitHub sign-in if prompted. On the repository's Code page, confirm the folder structure and both workflow files. Open Actions → Terraform checks and review its result.


Review the plan for a new 19c environment
Open Actions → Terraform 19c create and destroy → Run workflow. Select main, choose 19c under Database version for this example, choose deploy, leave confirmation empty, and supply the notification email. Select Run workflow.

The Database version dropdown offers 19c and 26ai. For new networks, select create, enter the application and ODB client subnet CIDRs, and leave the four existing-network fields blank. The example uses 10.30.0.0/24 and 10.31.0.0/24. The cleanup_scope choice applies only to cleanup operations; it does not delete resources when deploy is selected.
Open plan → Create and display the plan. Review database version, names, sizing, region, and proposed resource actions.
Successful plan: review the proposed resources
The updated workflow's plan job completed successfully in 25 seconds. The CIDR check accepted the supplied private IPv4 ranges and confirmed they do not overlap each other. Authentication, Terraform initialization, configuration validation, and plan generation passed. To view the proposed changes, open plan → Create and display the plan and scroll to the resource summary.
Plan: 9 to add, 0 to change, 0 to destroy.
This means Terraform proposes nine new resources, with no updates or deletions. It is a successful planning result; deployment has not run.
Our run produced Plan: 9 to add, 0 to change, 0 to destroy. The nine proposed resources are the VPC, application subnet, ODB network, ODB client subnet, ADB-S database, client VM, IAP SSH firewall, Cloud Router, and Cloud NAT.

Deployment approval checkpoint
The workflow then pauses at the deployment approval gate. We stop here for this walkthrough; the proposed resources have not been created. The successful plan shows the proposed changes for review before deployment.

To provision the environment yourself, return to Summary → Review deployments, select terraform-apply, and choose Approve and deploy after checking the plan. Approval allows the workflow to apply the saved plan and begin creating chargeable resources. If you only want to preview provisioning, leave apply unapproved and cancel the workflow when finished.
Customize the configuration for your environment
Review terraform/environments/19c.tfvars for resource names, region, and database sizing. When creating new networks, enter your application and ODB client subnet CIDRs in Run workflow. Choose ranges that do not overlap each other or your connected networks, and reuse those values for later runs and cleanup.
The complete Terraform configuration and GitHub Actions workflows are available in the OracleDB@GCP reusable Terraform repository.
Share on LinkedIn ↗Keep your Oracle notebook growing
Get new Oracle walkthroughs in your inbox, or follow the blog in your favorite RSS reader.
Free email delivery through Blogtrottr. Enter and confirm your email on their site; unsubscribe from any email. The free service may include ads. Your email address is not collected by this blog.
Join the discussion
Ask a question, share a result, or add a useful tip.
Leave a comment
Your name and comment will be public. Keep passwords, email addresses, IP addresses, and other private details out of your comment. Cloudflare Turnstile checks submissions to help prevent spam.