X

Oracle Management Cloud Blog covers the latest releases, customer stories, how-to guides and more.

  • March 20, 2019

Manage Dynamic Oracle Cloud Infrastructure using Terraform

Contributing Author: Akanksha Sheoran Kaler, Consulting Product Manager, Oracle

Oracle Management Cloud is a suite of management services that eliminate the human effort associated with traditional solutions for monitoring, managing and securing applications and infrastructure. Oracle Management Cloud leverages machine learning and big data techniques against the full breadth of the operational data set to help customers drive innovation while removing cost and risk from operational processes.

Oracle Management Cloud is a heterogeneous, hybrid Cloud solution that receives and analyzes data from any, or combination of sources, whether on-premises, or in Oracle Cloud Infrastructure, or other 3rd party Cloud platforms such as, Amazon Web Services (AWS) or Microsoft Azure or Google Cloud Platform.

To get started with Oracle Management Cloud, you don’t need any additional setup, you just need to deploy agents on your instances or host.

Oracle Cloud Infrastructure combines the elasticity and utility of public cloud with the granular control, security, and predictability of on-premises infrastructure to deliver high-performance, highly available, and cost-effective infrastructure services. If you need to quickly create a secure multi-tenant, multi-tier network on Oracle Cloud Infrastructure and apply best practices repeatedly, you need to script it using a tool called Terraform.

Terraform is a powerful tool that you can use to efficiently build, change, and version your infrastructure. Instead of setting up a cloud environment from scratch every time you need one, you can use Terraform to quickly provision the infrastructure. Using this approach saves you time by creating a basic structure that you can tune for your business requirements. It gives you agility and fine-grained control over all your infrastructure resources. You can create configuration files to describe your resources in a human-readable format.

In this blog, I will cover how you can script the agent install using Terraform and spinoff cloud agents along with the dynamic Oracle Cloud Infrastructure instance creation and/or deletion.

Oracle Management Cloud Agent

As the administrator of an Oracle Management Cloud, you can deploy agents on any infrastructure and it will then collect log and metric data from entities that you want to monitor and upload the data to Oracle Management Cloud. To learn more about getting started with Oracle Management Cloud, take a look at the documentation and resources available to you.

Cloud Agent Support for Terraform

Before you begin you need to keep a few things in mind for deploying your Cloud Agents.

  1. Plan: Install and deploy agent

  2. Uninstall: De-install agent

  3. Manage: Check existence of agent on the instance

Automate Deploying Cloud Agents on Oracle Cloud Infrastructure using Terraform

Terraform provisions specific, reproducible environments, such as test environments, or an environment as part of a larger deployment where you need to create several cloud instances.

Since Terraform scripts are code, you can use the scripts as a method of source control and enhance them to deploy cloud agents while creating cloud instances.

Any change including addition or deletion in the topology is codified in the Terraform scripts, which will allow you to deploy and remove cloud agents along with the cloud instances created using these scripts. This will allow Oracle Cloud Infrastructure instances to be immediately monitored by Oracle Management Cloud.

Instructions for Deploying Cloud Agents with Terraform Scripts

Enhancing the Terraform scripts to deploy cloud agents along with cloud instance creation is a 3 steps process and one-time activity.

Step 1: Create a setup.sh file that will create install user and agent base directory.

Step 2: Open the MAIN.TF and punch in the variables for the cloud agent install. There are 4 variables required for the cloud agent install:

  • TENANT_NAME - Name of the tenant where Oracle Management Cloud is running.

  • AGENT_REGISTRATION_KEY - Key to validate the identity of the tenant and the authenticity of the installation.

  • Oracle Management Cloud_URL - The absolute URL including the protocol that is required to connect to Oracle Management Cloud for uploading data for the specific TENANT_NAME.

  • AGENT_REP_URL- This is the absolute location of latest cloud agent binaries.

To learn more about these mandatory variables, please refer to the following documentation.

Step 3: Create a omc_entity.json to discover the Oracle Cloud Infrastructure instance in Oracle Management Cloud.

Step 4: Execute the command $ terraform apply. This will kick start the Oracle Cloud Infrastructure instance creation and then deploying the agent.

Oracle Cloud Infrastructure instances appears on the Oracle Management Cloud console.

Instructions for Deleting Cloud Agents with Terraform Scripts

Enhancing the Terraform scripts to delete cloud agents along with deletion of cloud instance is a 3 steps process and one-time activity:

Step 1: Open the Main.tf and inject a delete module as below that will invoke the cloud agent delete.

If the Oracle Cloud Infrastructure instances are deleted due to any anomaly deletion by Terraform then the cloud agents will also be deleted, and the Oracle Management Cloud UI will no longer show the instances as monitored.

Alerting the Terraform Plan and Cloud Agent Lifecyle

There could be times when you need to alter the Terraform plan based on the infrastructure expansion or reduction. The modified Terraform script with cloud agent (install and delete) will work along with Terraform plan alteration.

Let’s look at an example. A senior DBA created a plan for 10 instances with database entities on each. Another user deletes four instances. Terraform will detect this drift and recreate instances with the cloud agent deployed on it.

Conclusion

Monitoring your Cloud infrastructure is an important part of keeping your IT infrastructure running smoothly. To monitor your infrastructure, you must install and discover agents on each component. This process can be time-consuming and prone to errors. Terraform is a tool that allows you to programmatically manage, version, and persist your IT infrastructure as "infrastructure as code". Its primary purpose is to create defined hardware resources in code and to run that code to create or provision the hardware. During this process, it can also add software to the hardware being operated upon.

If you want to bootstrap multiple Oracle Cloud Infrastructure compute instances with Oracle Management Cloud, you can use the customizable Terraform modules that deploys Oracle Cloud Infrastructure compute instances along with required infrastructure resources, installs Oracle Management Cloud Agents for each deployment, and adds the instances to Oracle Management Cloud for immediate monitoring.

Additional Resources: