Skip to content

Instantly share code, notes, and snippets.

@scross01
Last active September 27, 2022 20:52
Show Gist options
  • Save scross01/21e5e934c5aca5602be712fac5f9eacb to your computer and use it in GitHub Desktop.
Save scross01/21e5e934c5aca5602be712fac5f9eacb to your computer and use it in GitHub Desktop.
Oracle Cloud Infrastructure Instance with Terraform remote-exec Provisioner
resource "oci_core_instance" "example" {
compartment_id = "${var.compartment_ocid}"
availability_domain = "${var.availability_domain}"
subnet_id = "${var.subnet_ocid}"
display_name = "example"
image = "${lookup(data.oci_core_images.image-list.images[0], "id")}"
shape = "VM.Standard1.1"
metadata = {
ssh_authorized_keys = "${file(var.ssh_public_key_file)}"
}
connection {
type = "ssh"
host = "${self.public_ip}"
user = "opc"
private_key = "${file(var.ssh_private_key_file)}"
}
provisioner "remote-exec" {
inline = [
"echo 'This instance was provisioned by Terraform.' | sudo tee /etc/motd",
]
}
}
@jasperan
Copy link

jasperan commented Dec 7, 2021

@kaustubh77 I set my host this way:

provisioner "remote-exec" {
    connection {
      agent       = false
      timeout     = "30m"
      host        = oci_core_instance.test_instance[count.index % var.num_instances].public_ip
      user        = "opc"
      private_key = var.ssh_private_key
    }

    inline = [
      "hello example"
    ]
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment