Terraform Import OCI Resources

Terraform allows you to re-create a state file (terraform.tfstate) with the import command.

For the import, you need to specify a resource type, name, and OCID. So you have to create a .tf file first. In this example we’ll import a compartment:

main.tf:

We now have to find the OCID of the compartment we want to import. You can do this via the online console or via the command line client.

Initialize Terraform:

Now execute the import command and specify the resource type, name, and OCID:

That’s it. You should now see a terraform.tfstate file with the compartment details in it.

 

Leave a Reply

Your email address will not be published. Required fields are marked *