I’m using terraform to deploy infrastructure in Oracle Cloud (OCI) and I have some resources such as virtual machines that were deployed manually.
I created the below terraform script to import a VM
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
variable "region" {}
variable "compartment_ocid" {
type = string
default = "ocid1.compartment.oc1..aaaaaaaa....."
}
variable "availability_domain" {
type = string
default = "phiX:US-ASHBURN-AD-1"
}
variable "subnet_ocid" {
type = string
default = "ocid1.subnet.oc1.iad.aaaaaaaa......"
}
variable "ssh_public_key_file"{
type = string
default = "/Users/cgperalt/.ssh/id_rsa.pub"
}
provider "oci" {
tenancy_ocid = var.tenancy_ocid
user_ocid = var.user_ocid
fingerprint = var.fingerprint
private_key_path = var.private_key_path
region = var.region
version = "~> 3.17"
}
# get latest Oracle Linux 7.7 image
data "oci_core_images" "oraclelinux-7-7" {
compartment_id = var.compartment_ocid
operating_system = "Oracle Linux"
operating_system_version = "7.7"
filter {
name = "display_name"
values = ["^([a-zA-z]+)-([a-zA-z]+)-([\\.0-9]+)-([\\.0-9-]+)$"]
regex = true
}
}
resource "oci_core_instance" "example" {
count = 2
compartment_id = var.compartment_ocid
availability_domain = var.availability_domain
subnet_id = var.subnet_ocid
display_name = "example_TF-1${count.index}"
image = lookup(data.oci_core_images.oraclelinux-7-7.images[0], "id")
shape = "VM.Standard1.1"
metadata = {
ssh_authorized_keys = "${file(var.ssh_public_key_file)}"
}
}
then I ran
terraform import oci_core_instance.example <vm_id>
and then if I do
terraform plan
terraform marks the imported machine to be destroyed.
Does anybody know why this is happening ?
Thanks so much