Deploy and Manage Apps on Oracle Application Container Cloud Service using Terraform

This article covers how to get started using the Terraform Providers for Oracle Cloud to deploy and manage application deployments to the Oracle Application Container Cloud Service

Oracle Application Container Cloud Service provides a rapid and scalable platform for application deployment on a choice of runtime platforms including Java EE, Java SE, Node.js, PHP, Python, Ruby, Go, and .NET

To use the Application Container Cloud Service with the oraclepaas provider set the application_endpoint to the REST API Endpoint provided on the Service Details page of the Oracle Cloud My Services dashboard.

provider "oraclepaas" {
version = "~> 1.3"
user = "${var.user}"
password = "${var.password}"
identity_domain = "${var.domain}"
application_endpoint = "https://apaas.us.oraclecloud.com"
}

Creating a new application deployment using the oraclepaas_application_container resource is as simple as declaring the required runtime, providing the location of the application package, and settings some basic deployment characteristics

Lets take a look at using the example EmployeeWebApp Java application from the Getting Started with Oracle Application Container Cloud tutorial. Download the sample employees-web-app.zip application and upload it to a suitable location in Oracle Storage Cloud Classic (e.g. my-accs-apps/employees-web-app.zip)

resource "oraclepaas_application_container" "java-app" {
name = "EmployeeWebApp"
runtime = "java"
archive_url = "my-accs-apps/employees-web-app.zip"
notes = "Sample Tomcat application"
subscription_type = "HOURLY"
  deployment_attributes {
memory = "1G"
instances = 1
}
}
output "web_url" {
value = "${oraclepaas_application_container.java-app.web_url}"
}

After applying the configuration the deployed application will be available at the URL provided by the web_url address.

Example EmployeeWebApp deployment on Application Container Cloud Service

Automating the application upload to Object Storage

Terraform can also automate the upload of the local the application package to the Object Storage container using the opc provider opc_storage_object resource.

resource "opc_storage_object" "example-app" {
name = "employees-web-app.zip"
container = "my-accs-apps"
file = "./employees-web-app.zip"
etag = "${md5(file("./employees-web-app.zip"))}"
content_type = "application/zip;charset=UTF-8"
}
resource "oraclepaas_application_container" "java-app" {
name = "EmployeeWebApp"
archive_url = "my-accs-apps/${opc_storage_object.example-app.name}"
...
}

Scaling Applications

Scaling an application deployment is as simple as modifying the deployment attributes:

resource "oraclepaas_application_container" "java-app" {
name = "EmployeeWebApp"
...
  deployment_attributes {
memory = "1G"
instances = 2
}
}

Then re-apply the terraform configuration:

$ terraform apply
Terraform will perform the following actions:
~ oraclepaas_application_container.java-app deployment_attributes.0.instances: "1" => "2"
Plan: 0 to add, 1 to change, 0 to destroy.

When adding or removing instances the other existing instances will keep running. Changing the memory size will cause all instances to be unavailable for a short period of time as the application is restarted with the new value.

Deploying Applications from a Git Repository

Application Container Cloud can also deploy an application directly from a source git repository. Instead of uploading the pre-packaged application to object storage we just set the source git_respository URL. When deploying from a git repository a manifest configuration (or manifest_file) must be provided.

resource "oraclepaas_application_container" "example-node-app" {
name = "nodeWebApp"
runtime = "node"
git_repository = "https://github.com/scross01/employee-app"
subscription_type = "HOURLY"
  manifest {
runtime {
major_version = "8"
}
command = "node server.js"
type = "web",
home = "/employees"
}
  deployment {
memory = "1G"
instances = 1
}
}

Setting the manifest or manifest_file can also be used to override the default manifest.json settings included in an application packages zip file.

More Examples

For more examples of deploying applications to Application Container Cloud examples take a look at

Related Articles