1. Home
  2. Knowledge Base
  3. Using Terraform to manage OCI GoldenGate Cloud Service

Using Terraform to manage OCI GoldenGate Cloud Service

Terraform by Hashicorp is an Infrastructure as code (IaC) tool and provides automation to provision and manage resources in any cloud including Oracle Cloud Infrastructure (OCI).

The OCI provider enables usage of Terraform to interact with Oracle Cloud Infrastructure resources including Oracle GoldenGate Cloud Service.

The link below shows the various GoldenGate related Terraform resources available.

We are also provided with an example of how the resource can be used as well. In this case we get information about the resource oci_goldengate_connection.

https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/golden_gate_connection

This note describes the usage of Terraform commands to perform tasks like creation of an Oracle OCI GoldenGate Deployment as well as performing a backup of the GoldenGate Deployment.

Create GoldenGate Cloud Service Deployment

Create the variables.tf file

[opc@hub ~]$ cd tf-deployment/

[opc@hub tf-deployment]$ ls
deployment.tf  provider.tf  terraform.tfstate  variables.tf

[opc@hub tf-deployment]$ cat variables.tf
variable "compartment_id" {
  description = "OCID of the compartment in which the deployment will be created"
  default = "ocid1.compartment.oc1..aaaaaaaa5owqpzgycdfjhlyvreimwx7vm4z3g3k3i3payjd6e6t3"
}

variable "deployment_cpu_core_count" {
  description = "minimum number of OCPUs for this deployment"
  default = "2"
}

variable "deployment_deployment_type" {
  description = "deployment type: DATABASE_ORACLE, DATABASE_MYSQL, DATABASE_POSTGRESQL, DATABASE_MICROSOFT_SQLSERVER, or BIGDATA"
  default = "DATABASE_ORACLE"
}

variable "deployment_display_name" {
  description = "deployment display name"
  default = "OCI GoldenGate Deployment Created By Terraform"
}

variable "deployment_is_auto_scaling_enabled" {
  description = "deployment autoscaling: true or false"
  default = "false"
}

variable "deployment_license_model" {
  description = "deployment license type: LICENSE_INCLUDED or BRING_YOUR_OWN_LICENSE"
  default = "LICENSE_INCLUDED"
}

variable "deployment_subnet_id" {
  description = "OCID of the subnet used by deployment"
  default = "ocid1.subnet.oc1.ap-sydney-1.aaaaaaaao4za624x46t"
}

variable "deployment_is_public" {
  description = "Enable GoldenGate console public access: true or false"
  default = "false"
}

variable "deployment_ogg_data_admin_password" {
  description = "admin password for the deployment"
  default = "oggadminpassw"
  sensitive = true
}

variable "deployment_ogg_data_admin_username" {
  description = "admin username for the deployment"
  default = "oggadmin"
}

variable "deployment_name" {
  description = "name of the deployment"
  default = "Terraform_OGG"
}

Create the provider.tf file

[opc@hub tf-deployment]$ ls
deployment.tf  provider.tf  terraform.tfstate  variables.tf

[opc@hub tf-deployment]$ cat provider.tf
provider "oci" {
  tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaa64twfc56x4q32ylbmjgt3voh5os4ndxphw2qygzn2cmgppow"
  user_ocid = "ocid1.user.oc1..aaaaaaaadn7e4ljvw6kt3k2yb5ynerblkvelsjgkc7grvro4wsv346gk7"
  private_key_path = "/home/opc/.oci/oci_api_key.pem"
  fingerprint = "f5:72:b9:f6:ba:66:b0:d9:72:9b:e8:0f:52:ec:c4:81"
  region = "ap-sydney-1"
}


Create the deployment.tf file

[opc@hub tf-deployment]$ cat deployment.tf
resource "oci_golden_gate_deployment" "ggs_deployment" {
    compartment_id = var.compartment_id
    cpu_core_count = var.deployment_cpu_core_count
    deployment_type = var.deployment_deployment_type
    display_name = var.deployment_display_name
    is_auto_scaling_enabled = var.deployment_is_auto_scaling_enabled
    license_model = var.deployment_license_model
    subnet_id = var.deployment_subnet_id
    is_public = var.deployment_is_public
    ogg_data {
        admin_password = var.deployment_ogg_data_admin_password
        admin_username = var.deployment_ogg_data_admin_username
        deployment_name = var.deployment_name
    }
}

Execute terraform init command

[opc@hub tf-deployment]$ terraform init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/oci from the dependency lock file
- Using previously-installed hashicorp/oci v4.116.0

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
[opc@hub tf-deployment]$ terraform validate
Success! The configuration is valid.

Execute terraform plan command

[opc@hub tf-deployment]$ terraform plan
oci_golden_gate_deployment.ggs_deployment: Refreshing state... [id=ocid1.goldengatedeployment.oc1.ap-sydney-1.amaaaaaaeetb5tqa3faaw2qi33bhitomwhi4kesaagfhzliweheqduerlcha]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # oci_golden_gate_deployment.ggs_deployment will be created
  + resource "oci_golden_gate_deployment" "ggs_deployment" {
      + compartment_id                        = "ocid1.compartment.oc1..aaaaaaaa5owqpzgycdfjhlyvreimwx7vm4z3g3k3i3payjd6e6t"
      + cpu_core_count                        = 2
      + defined_tags                          = (known after apply)
      + deployment_backup_id                  = (known after apply)
      + deployment_diagnostic_data            = (known after apply)
      + deployment_type                       = "DATABASE_ORACLE"
      + deployment_url                        = (known after apply)
      + description                           = (known after apply)
      + display_name                          = "OCI GoldenGate Deployment Created By Terraform"
      + fqdn                                  = (known after apply)
      + freeform_tags                         = (known after apply)
      + id                                    = (known after apply)
      + is_auto_scaling_enabled               = false
      + is_healthy                            = (known after apply)
      + is_latest_version                     = (known after apply)
      + is_public                             = false
      + is_storage_utilization_limit_exceeded = (known after apply)
      + license_model                         = "LICENSE_INCLUDED"
      + lifecycle_details                     = (known after apply)
      + lifecycle_sub_state                   = (known after apply)
      + next_maintenance_action_type          = (known after apply)
      + next_maintenance_description          = (known after apply)
      + nsg_ids                               = (known after apply)
      + private_ip_address                    = (known after apply)
      + public_ip_address                     = (known after apply)
      + state                                 = (known after apply)
      + storage_utilization_in_bytes          = (known after apply)
      + subnet_id                             = "ocid1.subnet.oc1.ap-sydney-1.aaaaaaaao4za624x46tutjetnnwa3hi7le4nwjbck47tbgapib5sewmnbnnq"
      + system_tags                           = (known after apply)
      + time_created                          = (known after apply)
      + time_of_next_maintenance              = (known after apply)
      + time_updated                          = (known after apply)
      + time_upgrade_required                 = (known after apply)

      + ogg_data {
          + admin_password  = (sensitive value)
          + admin_username  = "oggadmin"
          + certificate     = (known after apply)
          + deployment_name = "Terraform_OGG"
          + key             = (known after apply)
          + ogg_version     = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

Execute the terraform apply command.

[opc@hub tf-deployment]$ terraform apply
oci_golden_gate_deployment.ggs_deployment: Refreshing state... [id=ocid1.goldengatedeployment.oc1.ap-sydney-1.amaaaaaaeetb5tqa3faaw2qi33bhitomwhi4kesaagfhzliweheqduerlcha]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # oci_golden_gate_deployment.ggs_deployment will be created
  + resource "oci_golden_gate_deployment" "ggs_deployment" {
      + compartment_id                        = "ocid1.compartment.oc1..aaaaaaaa5owqpzgycdfjhlyvreimwx7vm4z3g3k3i3payjd6e6t"
      + cpu_core_count                        = 2
      + defined_tags                          = (known after apply)
      + deployment_backup_id                  = (known after apply)
      + deployment_diagnostic_data            = (known after apply)
      + deployment_type                       = "DATABASE_ORACLE"
      + deployment_url                        = (known after apply)
      + description                           = (known after apply)
      + display_name                          = "OCI GoldenGate Deployment Created By Terraform"
      + fqdn                                  = (known after apply)
      + freeform_tags                         = (known after apply)
      + id                                    = (known after apply)
      + is_auto_scaling_enabled               = false
      + is_healthy                            = (known after apply)
      + is_latest_version                     = (known after apply)
      + is_public                             = false
      + is_storage_utilization_limit_exceeded = (known after apply)
      + license_model                         = "LICENSE_INCLUDED"
      + lifecycle_details                     = (known after apply)
      + lifecycle_sub_state                   = (known after apply)
      + next_maintenance_action_type          = (known after apply)
      + next_maintenance_description          = (known after apply)
      + nsg_ids                               = (known after apply)
      + private_ip_address                    = (known after apply)
      + public_ip_address                     = (known after apply)
      + state                                 = (known after apply)
      + storage_utilization_in_bytes          = (known after apply)
      + subnet_id                             = "ocid1.subnet.oc1.ap-sydney-1.aaaaaaaao4za624x46tutje"
      + system_tags                           = (known after apply)
      + time_created                          = (known after apply)
      + time_of_next_maintenance              = (known after apply)
      + time_updated                          = (known after apply)
      + time_upgrade_required                 = (known after apply)

      + ogg_data {
          + admin_password  = (sensitive value)
          + admin_username  = "oggadmin"
          + certificate     = (known after apply)
          + deployment_name = "Terraform_OGG"
          + key             = (known after apply)
          + ogg_version     = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

oci_golden_gate_deployment.ggs_deployment: Creating...
oci_golden_gate_deployment.ggs_deployment: Still creating... [10s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [20s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [30s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [40s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [50s elapsed]
...
...
oci_golden_gate_deployment.ggs_deployment: Still creating... [4m40s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [4m50s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [5m0s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [5m10s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [5m20s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [5m30s elapsed]

...
...
...
oci_golden_gate_deployment.ggs_deployment: Still creating... [11m20s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [11m30s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [11m40s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [11m50s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [12m0s elapsed]
oci_golden_gate_deployment.ggs_deployment: Still creating... [12m10s elapsed]
oci_golden_gate_deployment.ggs_deployment: Creation complete after 12m17s [id=ocid1.goldengatedeployment.oc1.ap-sydney-1.amaaaaaaeetb5tqatflozf5tpd3ccqdribuqlu6oeznfnow4ko6a7l6zo4fa]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
[opc@hub tf-deployment]$

While the terraform apply command is running we can see the State of the Deployment showing as Creating in the OCI console.

When the terraform apply command has completed, we can see that the State has now changed to Active for the GoldenGate Deployment.

Verify the Deployment created via Terraform from the OCI console.

Perform Deployment Backup

  Create variables.tf file

[opc@hub tf-backup]$ vi variables.tf
variable "bucket_name"{
  description = "name of Object Storage bucket to store OGG Deployment backups"
  default = "OCI-GG-backup"
}

variable "namespace_name"{
  description = "OCI Object Storage namespace"
  default = "sdkdqm75kud3"
}



variable "deployment_id" {
  description = "OCID of the OGG Deployment"
  default = "ocid1.goldengatedeployment.oc1.ap-sydney-1.amaaaaaaeetb5tqatflozf5tpd3ccqdribuqlu6oeznfnow4ko6a7l6zo4fa"
}

variable "compartment_id" {
  description = "OCID of the compartment in which the deployment will be created"
  default = "ocid1.compartment.oc1..aaaaaaaa5owqpzgycdfjhlyvreimwx7vm4z3g3k3i3payjd6e6t3ukbpi6cq"
}

variable "deployment_display_name" {
  description = "deployment display name"
  default = "OCI GoldenGate Deployment Created By Terraform"
}

Create backup.tf file

[opc@hub tf-backup]$ vi backup.tf
resource "oci_golden_gate_deployment_backup" "ggs_deployment_backup" {
    bucket = var.bucket_name
    compartment_id = var.compartment_id
    deployment_id = var.deployment_id
    display_name = "${var.deployment_display_name}-${timestamp()}"
    namespace = var.namespace_name
    object = "${var.deployment_display_name}-${timestamp()}.xz"
}

Execute terraform init command

[opc@hub tf-backup]$ terraform init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/oci from the dependency lock file
- Using previously-installed hashicorp/oci v4.116.0

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Execute terraform apply command

[opc@hub tf-backup]$ terraform apply
oci_golden_gate_deployment_backup.ggs_deployment_backup: Refreshing state... [id=ocid1.goldengatedeploymentbackup.oc1.ap-sydney-1.amaaaaaaeetb5tqa6kybzahf5qlebrg622hdyao5lmb6ffjgagifm2ukoeza]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # oci_golden_gate_deployment_backup.ggs_deployment_backup will be created
  + resource "oci_golden_gate_deployment_backup" "ggs_deployment_backup" {
      + backup_type          = (known after apply)
      + bucket               = "OCI-GG-backup"
      + compartment_id       = "ocid1.compartment.oc1..aaaaaaaa5owqpzgycdfjhlyvreimwx7vm4z3g3k3i3payjd6e6t3ukbpi6cq"
      + defined_tags         = (known after apply)
      + deployment_id        = "ocid1.goldengatedeployment.oc1.ap-sydney-1.amaaaaaaeetb5tqaemqagg56cyudqgxvro2fawyulpnbdykrxi3psqfyizlq"
      + display_name         = (known after apply)
      + freeform_tags        = (known after apply)
      + id                   = (known after apply)
      + is_automatic         = (known after apply)
      + lifecycle_details    = (known after apply)
      + namespace            = "sdkdqm75kud3"
      + object               = (known after apply)
      + ogg_version          = (known after apply)
      + size_in_bytes        = (known after apply)
      + state                = (known after apply)
      + system_tags          = (known after apply)
      + time_backup_finished = (known after apply)
      + time_created         = (known after apply)
      + time_of_backup       = (known after apply)
      + time_updated         = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

oci_golden_gate_deployment_backup.ggs_deployment_backup: Creating...
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [10s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [20s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [30s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [40s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [50s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [1m0s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [1m10s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Still creating... [1m20s elapsed]
oci_golden_gate_deployment_backup.ggs_deployment_backup: Creation complete after 1m23s [id=ocid1.goldengatedeploymentbackup.oc1.ap-sydney-1.amaaaaaaeetb5tqakfxhuadvhwhft6faggtovpxca4obveuvgkgtsi2lyeza]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Verify the backup creation via the OCI console

Updated on January 15, 2024

Was this article helpful?

Leave a Comment