Create Scripts and State Files with Resource Discovery

Generate Terraform files for existing resources in your compartment.

Use the OCI resource discovery feature to:

  • Create state files for existing resources in the Console, and then add those resources to a Terraform setup.
  • Duplicate your existing infrastructure in a new tenancy or region.
  • Detect state drift for updated resources.

In this tutorial, you create scripts and state files for resources in your account through the resource discovery feature. Then you use Terraform to manage the resources.

Key tasks include how to:

  • Create a resource through the Console.
  • Create scripts and a state file for the resource through the resource discovery feature.
  • Update the resource with Terraform.
  • Confirm that the resource has been updated in the Console.
A diagram of a user connected from a local environment to an Oracle Cloud Infrastructure tenancy. The local environment is Linux and has Terraform OCI Provider binaries installed. There is an arrow from the local environment connected to Terraform Registry in the cloud. There is a second arrow from the local environment sending a message to the user's Oracle Cloud Infrastructure tenancy labeled Authenticate?. The third arrow is from the tenancy to the local environment labeled Fetch Data, Create Scripts, and Create a State File. These arrows suggest that the user has set up their OCI provider variables to be authenticated by their tenancy. The user can then fetch information from the tenancy, and create scripts and state files, by using Terraform OCI provider commands and Terraform Registry. The tenancy contains a bucket with the name rd-bucket, in a compartment called rd-compartment. Resource Discovery is fetching information about this bucket, to create Terraform scripts and a state file in the user's environment.

For more information, see:

Before You Begin

To successfully perform this tutorial, you must have the following:

1. Create a Resource

Create a bucket in your tenancy through the Console. This bucket doesn't have a Terraform script. Later, use resource discovery to create a Terraform script and a state file for the bucket.

2. Discover the Resource

Discover the bucket that you created in your compartment.

3. Update the Resource

Update the name of your bucket in the object_storage.tf file and then run your Terraform scripts. Your account authenticates the scripts and then Terraform updates the bucket name. Confirm the new bucket name through the Console.