Step Up to Modern Cloud Development

March 26, 2018

Announcing Terraform support for Oracle Cloud Platform Services

By: Stephen Cross

Director, Partner Enablement

Oracle and HashiCorp are pleased to announce the immediate availability of the Oracle Cloud Platform Terraform provider.

The initial release of the Oracle Cloud Platform Terraform provider supports the creation and lifecycle management of Oracle Database Cloud Service and Oracle Java Cloud Service instances.

With the availability of the Oracle Cloud Platform services support, Terraform’s “infrastructure-as-code” configurations can now be defined for deploying standalone Oracle PaaS services, or combined with the Oracle Cloud Infrastructure and Infrastructure Classic services supported by the opc and oci providers for complete infrastructure and application deployment.

Supported PaaS Services

The following Oracle Cloud Platform services are supported by the initial Oracle Cloud Platform (PaaS) Terraform provider. Additional services/resources will be added over time.

  • Oracle Database Cloud Service Instances
  • Oracle Database Cloud Service Access Rules
  • Oracle Java Cloud Service Instances
  • Oracle Java Service Access Rules

Using the Oracle Cloud Platform Terraform provider

To get started using Terraform to provision the Oracle Cloud Platform services lets looks at an example of deploying a single Java Cloud Service instance, along with its dependent Database Cloud Service instance.

First we declare the provider definition, providing the account credentials and the appropriate service REST API endpoints. The Identity Domain name, Identity Service ID and REST endpoint URL can be found in the Service details section from on My Services Dashboard

For IDCS Cloud Accounts use the Identity Service ID for the identity_domain.

provider "oraclepaas" {
  user              = "example@user.com"
  password          = "Pa55_Word"
  identity_domain   = "idcs-5bb188b5460045f3943c57b783db7ffa"  
  database_endpoint = "https://dbaas.oraclecloud.com"
  java_endpoint     = "https://jaas.oraclecloud.com"
}

For Traditional Accounts use the account Identity Domain Name for the identity_domain

provider "oraclepaas" {
  user              = "example@user.com"
  password          = "Pa55_Word"
  identity_domain   = "mydomain"
  database_endpoint = "https://dbaas.oraclecloud.com"
  java_endpoint     = "https://jaas.oraclecloud.com"
}

Database Service Instance configuration

The oraclepaas_database_service_instance resource is used to define the Oracle Database Cloud service instance. A single terraform database service resource definition can represent configurations ranging from a single instance Oracle Database Standard Edition deployment, to a complete multi node Oracle Database Enterprise Edition with RAC and Data Guard for high availability and disaster recovery.

Instances can also be created for backups or snapshots of another Database Service instance. For this example we’ll create a new single instance database for use with the Java Cloud Service configured later further down.

resource "oraclepaas_database_service_instance" "database" {
  name        = "my-terraformed-database"
  description = "Created by Terraform"

  edition           = "EE"
  version           = "12.2.0.1"    
  subscription_type = "HOURLY"
  shape             = "oc1m"

  ssh_public_key = "${file("~/.ssh/id_rsa.pub")}"

  database_configuration {
    admin_password     = "Pa55_Word"
    backup_destination = "BOTH"
    sid                = "ORCL"
    usable_storage     = 25
  }

  backups {
    cloud_storage_container = "Storage-${var.domain}/my-terraformed-database-backup"
    cloud_storage_username  = "${var.user}"
    cloud_storage_password  = "${var.password}"
    create_if_missing       = true
  }
}

Lets take a closer look at the configuration settings. Here we are declaring that this is an Oracle Database 12c Release 2 (12.2.0.1) Enterprise Edition instance with a oc1m (1 OCPU/15Gb RAM) shape and with hourly usage metering.

edition           = "EE"
version           = "12.2.0.1"    
subscription_type = "HOURLY"
shape             = "oc1m"

The ssh_public_key is the public key to be provisioned to the instance to allow SSH access.

The database_configuration block sets the initial configuration for the actual Database instance to be created in the Database Cloud service, including the database SID, the initial password, and the initial usable block volume storage for the database.

database_configuration {
  admin_password     = "Pa55_Word"
  backup_destination = "BOTH"
  sid                = "ORCL"
  usable_storage     = 25
}

The backup_destination configure if backup are on the Object Storage Servive (OSS), both object storage and local storage (BOTH), or disabled (NONE). A backup destination of OSS or BOTH is required for database instances that as used in combination with Java Cloud service instances

The Object Storage Service location and access credentials are configured in the backups block

backups {
  cloud_storage_container = "Storage-${var.domain}/my-terraformed-database-backup"
  cloud_storage_username  = "${var.user}"
  cloud_storage_password  = "${var.password}"
  create_if_missing       = true
}

Java Cloud Service Instance

The oraclepaas_java_service_instance resource is used to define the Oracle Java Cloud service instance. A single Terraform resource definition can represent configurations ranging from a single instance Oracle WebLogic Server deployment, to a complete multi-node Oracle WebLogic cluster with a Oracle Coherence data grid cluster and an Oracle Traffic Director load balancer.

Instances can also be created from snapshots of another Java Cloud Service instance. For this example we’ll create a new two node Weblogic cluster with a load balancer, and associated to the Database Cloud Service instance defined above.

resource "oraclepaas_java_service_instance" "jcs" {
  name        = "my-terraformed-java-service"
  description = "Created by Terraform"

  edition              = "EE"
  service_version      = "12cRelease212"
  metering_frequency   = "HOURLY"
  enable_admin_console = true

  ssh_public_key = "${file("~/.ssh/id_rsa.pub")}"

  weblogic_server {
    shape = "oc1m"

    managed_servers {
      server_count = 2
    }    

    admin {
      username = "weblogic"
      password = "Weblogic_1"
    }

    database {
      name     = "${oraclepaas_database_service_instance.database.name}"
      username = "sys"
      password = "${oraclepaas_database_service_instance.database.database_configuration.0.admin_password}"
    }
  }

  oracle_traffic_director {
    shape = "oc1m"
    listener {
      port         = 8080
      secured_port = 8081
    }
  }

  backups {
    cloud_storage_container = "Storage-${var.domain}/my-terraformed-java-service-backup"
    auto_generate           = true
  }
}

Let break this down. Here we are declaring that this is a 12c Release 2 (12.2.1.2) Enterprise Edition Java Cloud Service instance with hourly usage metering.

  edition              = "EE"
  service_version      = "12cRelease212"
  metering_frequency   = "HOURLY"

Again the ssh_public_key is the public key to be provisioned to the instance to allow SSH access.

The weblogic_server block provides the configuration details for the WebLogic Service instances deployed for this Java Cloud Service instance. The weblogic_server definition sets the instance shape, in this case a oc1m (1 OCPU/15Gb RAM).

The admin block sets the WebLogic server admin user and initial password.

  admin {
    username = "weblogic"
    password = "Weblogic_1"
  }

The database block connects the WebLogic server to the Database Service instance already defined above. In this example we are assuming the database and java service instances are declared in the same configuration, so we can fetch the database configuration values.

  database {
    name     = "${oraclepaas_database_service_instance.database.name}"
    username = "sys"
    password = "${oraclepaas_database_service_instance.database.database_configuration.0.admin_password}"
  }

The oracle_traffic_director block configures the load balancer that directs traffic to the managed WebLogic server instances.

  oracle_traffic_director {
    shape = "oc1m"
    listener {
      port         = 8080
      secured_port = 8081
    }
  }

By default the load balancer will be configured with the same admin credentials defined in the weblogic_server block, different credentials can also be configured if required.  If the insecure port is not set then only the secured_port is enabled

Finally, similar to the Database Cloud service instance configuration, the backups block sets the Object Storage Service location for the Java Service instance backups.

  backups {
    cloud_storage_container = "Storage-${var.domain}/-backup"
    auto_generate           = true
  }

Provisioning

With the provider and resource definitions configured in a terraform project (e.g all in a main.tf file), deploying the above configuration is a simple as:

$ terraform init
$ terraform apply

The terraform init command will automatically fetch the latest version of the oraclepaas provider. terraform apply will start the provisioning. The complete provisioning of the Database and Java Cloud Instances can be a long running operation. To remove the provisioning instance run terraform destroy

Related Content

Terraform Provider for Oracle Cloud Platform

Terraform Provider for Oracle Cloud Infrastructure

Terraform Provider for Oracle Cloud Infrastructure Classic

Join the discussion

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha

Recent Content

Oracle

Integrated Cloud Applications & Platform Services