Skip to content

Instantly share code, notes, and snippets.

@lucassrg
Created October 19, 2017 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lucassrg/40989d20034134356d586108064e93ff to your computer and use it in GitHub Desktop.
Save lucassrg/40989d20034134356d586108064e93ff to your computer and use it in GitHub Desktop.
Terraform Instance count for OCI provider
#OCI Environment variables
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "compartment_ocid" {}
variable "region" {}
variable "ssh_public_key_path" {}
variable "ssh_private_key_path" {}
variable "availability_domain" {}
variable "instance_shape" {}
variable "number_of_instances" {}
provider "oci" {
tenancy_ocid = "${var.tenancy_ocid}"
user_ocid = "${var.user_ocid}"
fingerprint = "${var.fingerprint}"
private_key_path = "${var.ssh_private_key_path}"
region = "${var.region}"
}
data "oci_identity_availability_domains" "ads" {
compartment_id = "${var.tenancy_ocid}"
}
data "oci_core_images" "base-image" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Oracle Linux"
operating_system_version = "7.3"
}
resource "oci_core_instance" "my-instances" {
count = "${var.number_of_instances}"
availability_domain = "${lookup(data.oci_identity_availability_domains.ads.availability_domains[var.availability_domain - 1],"name")}"
compartment_id = "${var.compartment_ocid}"
display_name = "${format("TFInstanceName%03d", count.index + 1)}"
image = "${lookup(data.oci_core_images.base-image.images[0], "id")}"
shape = "VM.Standard1.8"
}
$ terraform plan
var.number_of_instances
Enter a value: 2
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
data.oci_core_images.base-image: Refreshing state...
data.oci_identity_availability_domains.ads: Refreshing state...
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ oci_core_instance.my-instances[0]
id: <computed>
availability_domain: "floz:PHX-AD-1"
compartment_id: "ocid1.tenancy.oc1..aaaaaaxx77jssur2tpaic3jjubsvxhwpmrl2jtry4gl5jax2ecdtr4fxxxx"
create_vnic_details.#: <computed>
display_name: "TFInstanceName001"
hostname_label: <computed>
image: "ocid1.image.oc1.phx.aaaaaaaa7jvfm572d4ehcgh3ijapvhrt52voel33ispumnygi3kl7mph55ha"
private_ip: <computed>
public_ip: <computed>
region: <computed>
shape: "VM.Standard1.8"
state: <computed>
time_created: <computed>
+ oci_core_instance.my-instances[1]
id: <computed>
availability_domain: "floz:PHX-AD-1"
compartment_id: "ocid1.tenancy.oc1..aaaaaaxx77jssur2tpaic3jjubsvxhwpmrl2jtry4gl5jax2ecdtr4fxxxx"
create_vnic_details.#: <computed>
display_name: "TFInstanceName002"
hostname_label: <computed>
image: "ocid1.image.oc1.phx.aaaaaaaa7jvfm572d4ehcgh3ijapvhrt52voel33ispumnygi3kl7mph55ha"
private_ip: <computed>
public_ip: <computed>
region: <computed>
shape: "VM.Standard1.8"
state: <computed>
time_created: <computed>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment