17. Terraform Import using Code Editor - CloudDarsh/OracleCloud GitHub Wiki
Create framework in Code Editor
Step1: Open code editor
Step2: Create a Folder in workspace and Create a modular folder
Step3: Create 3 files. main.tf, vars.tf, provider.tf
Step4: Update provider.tf
provider "oci" { region = var.region }
Update vars.tf
variable region { default = "us-ashburn-1"}
Update main.tf for an instance
resource "oci_core_instance" "example" { # }
Initialise terraform
Run "terraform init"
Copy the OCID of the compute resource
Execute the import command
terraform import oci_core_instance.example ocid1.instance.oc1.iad.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Now run , "terraform state list"
Now run "terraform state show oci_core_instance.example"
Update the output into the terraform file
Create the import_block.tf File
import { to = oci_core_instance.demo_inst_1 id = "ocid1.instance.oc1.iad.anuwcljtkbjmbracaynti47g4aij74pcp2fwtsfzbnsvmt42zc5xqyru7y2a" }
Run the terraform plan Command
terraform plan --generate-config-out=compute.tf
compute.tf created by terraform