Skip to content

Commit

Permalink
fixing module
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelpanaitescu committed Aug 1, 2023
1 parent 106b51e commit 4f79b1e
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright © 2023, Oracle and/or its affiliates.
# All rights reserved. Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl.

data "oci_identity_availability_domains" "ADs" {
compartment_id = var.tenancy_ocid
}


resource "oci_core_instance" "instance" {

for_each = var.instance_params

availability_domain = data.oci_identity_availability_domains.ADs.availability_domains[each.value.availability_domain - 1].name
compartment_id = each.value.compartment_id
display_name = each.value.display_name
shape = each.value.shape

defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags

create_vnic_details {
subnet_id = each.value.subnet_id
display_name = each.value.vnic_display_name
assign_public_ip = each.value.assign_public_ip
hostname_label = each.value.hostname_label
}

shape_config {
#Optional
ocpus = each.value.ocpus
memory_in_gbs = each.value.memory_in_gbs
}

source_details {
source_type = each.value.source_type
source_id = each.value.source_id
}

metadata = each.value.metadata

fault_domain = each.value.fault_domain

timeouts {
create = "${each.value.provisioning_timeout_mins}m"
}

#prevent any metadata changes to destroy instance
# lifecycle {
# ignore_changes = [metadata, shape, shape_config]
# }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright © 2023, Oracle and/or its affiliates.
# All rights reserved. Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl.

# Output the private and public IPs of the instance

output "InstancePrivateIPs" {
value = [ for b in oci_core_instance.instance : b.private_ip]
}

output "InstancePublicIPs" {
value = [ for b in oci_core_instance.instance : b.public_ip]
}

output "InstanceOcids" {
value = [ for b in oci_core_instance.instance : b.id]
}

output "display_names" {
value = [ for b in oci_core_instance.instance : b.display_name]
}

output "InstanceShapes" {
value = [ for b in oci_core_instance.instance : b.shape]
}

output "AvailabilityDomains" {
value = [ for b in oci_core_instance.instance : b.availability_domain]
}

locals {
linux_instances = {
for instance in oci_core_instance.instance :
instance.display_name => { "id" : instance.id, "ip" : instance.public_ip != "" ? instance.public_ip : instance.private_ip }
}

linux_ids = {
for instance in oci_core_instance.instance :
instance.display_name => instance.id
}

linux_private_ips = {
for instance in oci_core_instance.instance :
instance.display_name => instance.private_ip
}

linux_public_ips = {
for instance in oci_core_instance.instance :
instance.display_name => instance.public_ip
}

all_instances = local.linux_ids
all_private_ips = local.linux_private_ips
all_public_ips = local.linux_public_ips
}

output "linux_instances" {
value = local.linux_instances
}

output "all_instances" {
value = local.all_instances
}

output "all_private_ips" {
value = local.all_private_ips
}

output "all_public_ips" {
value = local.all_public_ips
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright © 2023, Oracle and/or its affiliates.
# All rights reserved. Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl.

variable "tenancy_ocid" {
type = string
}

variable "instance_params" {

type = map(object({

availability_domain = number
compartment_id = string
display_name = string
shape = string

defined_tags = map(string)
freeform_tags = map(string)

subnet_id = string
vnic_display_name = string
assign_public_ip = string
hostname_label = string

ocpus = number
memory_in_gbs = number

source_type = string
source_id = string

metadata = map(string)

fault_domain = string

provisioning_timeout_mins = string

}))

}

0 comments on commit 4f79b1e

Please sign in to comment.