Manage Resources Using Terraform
Terraform is a third-party tool that you can use to create and manage your IaaS and PaaS resources on Oracle Cloud at Customer. This guide shows you how to install and configure Terraform, and then use it to deploy a sample set of Compute Classic resources.
Scenario Overview
In this example, you create the following Compute Classic resources:
-
A persistent boot disk
-
An IP network
-
A vNICset
-
A VM based on the image in the boot disk and attached to the IP network
-
An SSH public key associated with the VM
-
A data volume attached to the VM
-
A public IP reservation for the VM
-
A security protocol for SSH traffic to the VM
-
A security rule to permit SSH access to the VM, and an ACL for the security rule
Create the Required Resources Using Terraform
Define the resources you need in a Terraform configuration and then apply the configuration.
Add, Update, and Delete Resources Using Terraform
You can manage your IaaS and PaaS resources on Oracle Cloud at Customer by using the Terraform configuration that you used originally to create the resources.
Add Resources
Define the required resources in the configuration, and run terraform apply
.
Update Resources
Edit the attributes of the resources in the configuration, and run terraform apply
.
Delete Resources
-
To delete a specific resource, run the following command:
terraform destroy -target=resource_type.resource_name
For example, to delete just the VM in the configuration that you applied earlier, run this command:
terraform destroy -target=opc_compute_instance.default
At the "Do you really want to destroy" prompt, enter yes.
Terraform displays the status of the operation, as shown in the following example. For each resource, Terraform shows the status and the time taken for the operation.
Note:
In this example, some parts are truncated for brevity.opc_compute_instance.default: Destroying... (ID: 9a3fee81-b742-48f3-be2d-b83b842e3b40) ... ... opc_compute_instance.default: Destruction complete after 41s
Wait for the following message:
Destroy complete! Resources: 1 destroyed
-
To delete all the resources, run
terraform destroy
. -
To delete specific resources permanently, remove the resources from the configuration, and then run
terraform apply
.
Re-create Resources
To re-create any resources that you deleted previously but didn’t remove from the configuration, run terraform apply
.
Learn More
-
For information about the resources and configuration options that Terraform supports for the
opc
provider, see the Terraform documentation at https://www.terraform.io/docs/providers/opc/index.html. -
For help with the Terraform CLI commands, see https://www.terraform.io/docs/commands/index.html.