1. Introduction

A Gradle plugin for the Oracle Cloud Infrastructure Java SDK.

Currently supported OCI Java SDK version is 1.5.2.

2. Usage

There are two choices for applying any of the plugins described in this document

Option #1

buildscript {
    repositories {
        jcenter()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'org.kordamp.gradle:oci-gradle-plugin:0.1.0'
    }
}
apply plugin: 'org.kordamp.gradle.oci'

Option #2

plugins {
    id 'org.kordamp.gradle.oci' version '0.1.0'
}

2.1. Requirements

Java 8 and Gradle 5 are the minimum requirements to use this plugin.

2.1.1. Example

Provisioning an Instance with brand new Vcn, Subnets, InternetGateway, and InstanceConsoleConnection, making sure that OpenJDK is installed and port 8080 is open

gradle setupInstance \
  --compartment-id=ocid1.compartment.oc1... \
  --verbose \
  --instance-name=myInstance \
  --image=Oracle-Linux-7.6-2019.04.18-0 \
  --shape=VM.Standard2.1 \
  --public-key-file=/home/myuser/.oci/oci-key.pub \
  --user-data-file=/home/myuser/oci/cloud-init.sh
cloud-init.sh
#!/bin/bash

# install Java
yum install -y yum java-1.8.0-openjdk

# amend firewall rules to allow port 8080
firewall-cmd --permanent --zone=public --add-port=8080/tcp
firewall-cmd --reload

2.2. Configuration

You can configure tasks in two ways:

  1. Using the standard ~/.oci/config file.

  2. Defining an ociConfig block on a task.

2.2.1. Standard Config File

The format of the configuration file is specified at this page, it looks something similar to

[DEFAULT]
user=ocid1.user.oc1...
fingerprint=f9:14:d0:...
key_file=~/.oci/oci_api_key.pem
tenancy=ocid1.tenancy.oc1...
region=eu-frankfurt-1
pass_phrase=<secret>

2.2.2. OciConfig Extension Block

Alternatively you may define an ociConfig block in a task. This block defines properties that match settings found on the config file

build.gradle
listInstances {
    ociConfig {
        userId.set('ocid1.user.oc1...'
        tenantId.set('ocid1.tenancy.oc1...')
        fingerprint.set('f9:14:d0:...')
        region.set('eu-frankfurt-1')
        keyfile.set(project.file('/.oci/oci_api_key.pem'))
        passphrase.set('<secret>')
    }
}

2.2.3. Common Properties

All tasks share the following properties

profile

The profile to use. Defaults to DEFAULT (OPTIONAL).

region

The region to use (OPTIONAL).

2.3. Tasks

Invoke gradle help --task <taskname> to learn more about the properties that can be set for a particular task.

2.3.1. OCI Create

createCompartment

Creates a Compartment.

createInstance

Creates an Instance.

createInstanceConsoleConnection

Creates an InstanceConsoleConnection.

createInternetGateway

Creates a InternetGateway.

createSubnet

Creates a Subnet.

createVcn

Creates a Vcn.

OCI Delete
deleteCompartment

Deletes a Compartment.

deleteInstanceConsoleConnection

Deletes an InstanceConsoleConnection.

deleteInternetGateway

Deletes a InternetGateway.

deleteSubnet

Deletes a Subnet.

deleteVcn

Deletes a Vcn.

2.3.2. OCI Get

getCompartment

Displays information for an specific Compartment.

getInstance

Displays information for an specific Instance.

getInstanceConsoleConnection

Displays information for an specific InstanceConsoleConnection.

getInstancePublicIp

Displays public Ip addresses for a particular Instance.

getInternetGateway

Displays information for an specific InternetGateway.

getRouteTable

Displays information for an specific RouteTable.

getSecurityList

Displays information for an specific SecurityList.

getSubnet

Displays information for an specific Subnet.

getVcn

Displays information for an specific Vcn.

2.3.3. OCI Instance

addIngressSecurityRule

Adds IngressSecurityRules to a SecurityList.

instanceAction

Performs a given action on an Instance.

setupInstance

Setups an Instance with Vcn, InternetGateway, Subnets, InstanceConsoleConnection, and Volume.

terminateInstance

Terminates an Instance.

2.3.4. OCI List

listAvailabilityDomains

Lists AvailabilityDomains available on a Compartment.

listCompartments

Lists available Compartments.

listImages

Lists Images available on a Compartment.

listInstanceConsoleConnections

Lists available InstanceConsoleConnection on an Instance.

listInstances

Lists available Instances.

listInternetGateways

Lists InternetGateways available on a Vcn.

listRegions

Lists available Regions.

listRouteTables

Lists RouteTables available on a Vcn.

listSecurityLists

Lists SecurityLists available on a Vcn.

listShapes

Lists Shapes available on a Compartment.

listSubnets

Lists Subnets available on a Vcn.

listUsers

Lists available Users.

listVcns

Lists Vcns available on a Compartment.

2.3.5. OCI Query

searchResources

Lists information on resource types.