Sample Terraform Scripts for Provisioning Resources
Use Terraform scripts to provision resources in Fleet Application Management.
In the following sample package:
- instance_compartment_id: Specifics the compartment , where the Compute instance starts.
- subnet_id: Specifies a subnet in VCN. See VCN and Subnet Management.
- display_name: Specifies a display name of the instance.
- availability_domain: Specifies a domain to place the Compute instance in. To get the specific names of your tenancy's availability domains, run the ListAvailabilityDomains operation or find the Availability domain names when creating an instance using the Console.
variables.tf
This file creates several variables that are used to provision resources. It defines the variables that are used in the Terraform configuration.
variable "compartment_id" {
type = string
description = "OCID of compartment for Compute Instance"
}
variable "subnet_id" {
type = string
description = "OCID of the subnet for Compute Instance"
}
variable "display_name" {
type = string
description = "Display Name Of Compute Instance"
default = "Test Instance"
}
variable "availability_domain" {
type = string
description = "Region based Availability Domain to place the Compute Instance"
}
variable "image_id" {
type = string
description = "Image Id"
}
main.tf
This file contains the Terraform code to provision resources in OCI.
provider "oci" {}
resource "oci_core_instance" "generated_oci_core_instance" {
agent_config {
is_management_disabled = "false"
is_monitoring_disabled = "false"
plugins_config {
desired_state = "DISABLED"
name = "WebLogic Management Service"
}
plugins_config {
desired_state = "DISABLED"
name = "Vulnerability Scanning"
}
plugins_config {
desired_state = "DISABLED"
name = "Oracle Java Management Service"
}
plugins_config {
desired_state = "DISABLED"
name = "OS Management Service Agent"
}
plugins_config {
desired_state = "DISABLED"
name = "OS Management Hub Agent"
}
plugins_config {
desired_state = "DISABLED"
name = "Management Agent"
}
plugins_config {
desired_state = "ENABLED"
name = "Custom Logs Monitoring"
}
plugins_config {
desired_state = "DISABLED"
name = "Compute RDMA GPU Monitoring"
}
plugins_config {
desired_state = "ENABLED"
name = "Compute Instance Run Command"
}
plugins_config {
desired_state = "ENABLED"
name = "Compute Instance Monitoring"
}
plugins_config {
desired_state = "DISABLED"
name = "Compute HPC RDMA Auto-Configuration"
}
plugins_config {
desired_state = "DISABLED"
name = "Compute HPC RDMA Authentication"
}
plugins_config {
desired_state = "ENABLED"
name = "Cloud Guard Workload Protection"
}
plugins_config {
desired_state = "DISABLED"
name = "Block Volume Management"
}
plugins_config {
desired_state = "DISABLED"
name = "Bastion"
}
}
availability_config {
is_live_migration_preferred = "true"
recovery_action = "RESTORE_INSTANCE"
}
availability_domain = "${var.availability_domain}"
compartment_id = "${var.instance_compartment_id}"
create_vnic_details {
assign_ipv6ip = "false"
assign_private_dns_record = "true"
assign_public_ip = "true"
subnet_id = "${var.subnet_id}"
}
display_name = "${var.display_name}"
instance_options {
are_legacy_imds_endpoints_disabled = "false"
}
// Oracle Linux 8 image source
source_details {
source_id = "ocid1.image.oc1..<unique_id>"
source_type = "image"
}
shape = "VM.Standard.A1.Flex"
shape_config {
memory_in_gbs = "6"
ocpus = "1"
}
}
# Get the latest Oracle Linux image
data "oci_core_images" "InstanceImageOCID" {
compartment_id = "${var.compartment_id}"
operating_system = "Oracle Linux"
operating_system_version = "8"
shape = "VM.Standard.A1.Flex"
filter {
name = "display_name"
values = ["^.*Oracle[^G]*$"]
regex = true
}
}
conf.json
This file provides the values for the variables defined in variables.tf
. You can customize this file with your actual OCI credentials, compartment OCID, Availability domain, instance shape, or any freeform tags you want to apply to the resources.
{
"compartment_id": "ocid1.compartment.oc1..{my_compartment}",
"subnet_id": "ocid1.subnet.oc1.iad.{my_subnet}",
"display_name": "Test Instance",
"availability_domain":"cCnw:US-ASHBURN-AD-1",
"image_id": "ami-0c55b159cbfafe1f0"
}