Skip to content

Latest commit

 

History

History
99 lines (64 loc) · 5.26 KB

Deploy-DG-with-TF-Azure-CLI.md

File metadata and controls

99 lines (64 loc) · 5.26 KB

Introduction

The code is intended as an example for deployment of two Azure Virtual Machines with Oracle Database Enterprise Edition 19c in a Data Guard configuration. The code is intended to be used as a starting point for your own deployment. The module for this deployment is located in the terraform/bootstrap/data_guard directory.

Data Guard configuration

Preparations

  • To use Terraform commands against your Azure subscription, you must first authenticate Terraform to that subscription. This doc describes how to authenticate Terraform to your Azure subscription.

SSH Key

Before using this module, you have to create your own ssh key to deploy and connect the virtual machine you will create. To do this follow these steps on your compute source:

ssh-keygen -f ~/.ssh/lza-oracle-data-guard

Verify that the key has been created:

ls -lha ~/.ssh/

The above command should result in output similar to the following:

-rw-------   1 yourname  staff   2.6K  8 17  2023 lza-oracle-data-guard
-rw-r--r--   1 yourname  staff   589B  8 17  2023 lza-oracle-data-guard.pub

Run the following commands to include the public key in the fixtures.tfvars file where it will be used when deploying the virtual machine:

pubkey="$HOME/.ssh/lza-oracle-data-guard.pub"
key_content=$(awk -F= '{print $1 FS}' "$pubkey")
fixtures="ssh_key = \"$key_content\""
echo $fixtures > terraform/bootstrap/data_guard/fixtures.tfvars

The fixtures.tfvars file should now contain the public key, see below for an example:

fixtures

Oracle binaries download

To allow for Oracle software binaries download you will need to update information on the following parameters as well:

  • Resource Id of the user assigned managed identity you have created as described here, should be gathered and added to the /terraform/bootstrap/data_guard/fixtures.tfvars file. To get the resource id , run the following command, replacing the values for $umi and $rg with the name of the user managed identity and the resource group it is in respectively:
umi="<User managed identity name>"
rg="<Resource group where user managed identity is placed>"
mi_id=$(az identity show --name $umi --resource-group $rg --query id --output tsv)
miid_mod=$(echo "$mi_id" | sed 's/resourcegroups/resourceGroups/g')
fixtures="vm_user_assigned_identity_id = \"$miid_mod\""
echo $fixtures >> terraform/bootstrap/data_guard/fixtures.tfvars

To further ensure that the Ansible workflow will run successfully, open the file ansible/bootstrap/oracle/group_vars/all/vars.yml and update the following parameters:

  • The value for storage_account should be updated with the name of the storage account where the Oracle binaries are stored.
  • The value for storage_container should be updated with the name of the container on the storage account where the Oracle binaries are stored.

There are a number of optional settings which the module enables. Overall if you wish to modify one or more variables in the module, you can do so by modifying the terraform/bootstrap/data_guard/variables_global.tf or the terraform/bootstrap/data_guard/variables_local.tf file. Be mindful that the Oracle installation through Ansible does require a disk setup similar to the one specified, i.e. three disks, so changes to this may cause the Ansible playbook to fail.

Deploy the virtual machine

Perform the following steps to deploy the virtual machine:

  • Verify that you are in the terraform/bootstrap/data_guard directory.
  • Run the following commands to initialize Terraform state and deploy the virtual machine:

To avoid registering unnecessary providers, you have to export the environment variable ARM_SKIP_PROVIDER_REGISTRATION as true.

export ARM_SKIP_PROVIDER_REGISTRATION=true
terraform init
terraform plan -var-file=fixtures.tfvars
terraform apply -var-file=fixtures.tfvars

Connect to the virtual machine

Finally, you can connect to the virtual machine with the ssh private key. While deploying resources, a public ip address is generated and attached to the virtual machine, so that you can connect to the virtual machine with this IP address. The username is oracle, which is hardcoded in terraform/bootstrap/data_guard/module.tf.

As the deployment enables Just-in-Time VM access, you will need to request access to the VM before you can connect to it as described here.

Once the VM is accessible, you can connect to it with the following command:

ssh -i ~/.ssh/lza-oracle-data-guard  oracle@<PUBLIC_IP_ADDRESS>

Next step is to proceed with Ansible configuration to get the Oracle database operational. See the Ansible Data Guard documentation for more details.

Optional Settings

There are a number of optional settings which the module enables. Overall if you wish to modify one or more variables in the module, you can do so by modifying the terraform/bootstrap/data_guard/variables_global.tf or the terraform/bootstrap/data_guard/variables_local.tf file.