Skip to content

Commit e77c6ec

Browse files
authored
Merge pull request #83 from oracle-devrel/iopanait-develop20
fixing module
2 parents d2793af + 4f79b1e commit e77c6ec

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright © 2023, Oracle and/or its affiliates.
2+
# All rights reserved. Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
data "oci_identity_availability_domains" "ADs" {
5+
compartment_id = var.tenancy_ocid
6+
}
7+
8+
9+
resource "oci_core_instance" "instance" {
10+
11+
for_each = var.instance_params
12+
13+
availability_domain = data.oci_identity_availability_domains.ADs.availability_domains[each.value.availability_domain - 1].name
14+
compartment_id = each.value.compartment_id
15+
display_name = each.value.display_name
16+
shape = each.value.shape
17+
18+
defined_tags = each.value.defined_tags
19+
freeform_tags = each.value.freeform_tags
20+
21+
create_vnic_details {
22+
subnet_id = each.value.subnet_id
23+
display_name = each.value.vnic_display_name
24+
assign_public_ip = each.value.assign_public_ip
25+
hostname_label = each.value.hostname_label
26+
}
27+
28+
shape_config {
29+
#Optional
30+
ocpus = each.value.ocpus
31+
memory_in_gbs = each.value.memory_in_gbs
32+
}
33+
34+
source_details {
35+
source_type = each.value.source_type
36+
source_id = each.value.source_id
37+
}
38+
39+
metadata = each.value.metadata
40+
41+
fault_domain = each.value.fault_domain
42+
43+
timeouts {
44+
create = "${each.value.provisioning_timeout_mins}m"
45+
}
46+
47+
#prevent any metadata changes to destroy instance
48+
# lifecycle {
49+
# ignore_changes = [metadata, shape, shape_config]
50+
# }
51+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright © 2023, Oracle and/or its affiliates.
2+
# All rights reserved. Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
# Output the private and public IPs of the instance
5+
6+
output "InstancePrivateIPs" {
7+
value = [ for b in oci_core_instance.instance : b.private_ip]
8+
}
9+
10+
output "InstancePublicIPs" {
11+
value = [ for b in oci_core_instance.instance : b.public_ip]
12+
}
13+
14+
output "InstanceOcids" {
15+
value = [ for b in oci_core_instance.instance : b.id]
16+
}
17+
18+
output "display_names" {
19+
value = [ for b in oci_core_instance.instance : b.display_name]
20+
}
21+
22+
output "InstanceShapes" {
23+
value = [ for b in oci_core_instance.instance : b.shape]
24+
}
25+
26+
output "AvailabilityDomains" {
27+
value = [ for b in oci_core_instance.instance : b.availability_domain]
28+
}
29+
30+
locals {
31+
linux_instances = {
32+
for instance in oci_core_instance.instance :
33+
instance.display_name => { "id" : instance.id, "ip" : instance.public_ip != "" ? instance.public_ip : instance.private_ip }
34+
}
35+
36+
linux_ids = {
37+
for instance in oci_core_instance.instance :
38+
instance.display_name => instance.id
39+
}
40+
41+
linux_private_ips = {
42+
for instance in oci_core_instance.instance :
43+
instance.display_name => instance.private_ip
44+
}
45+
46+
linux_public_ips = {
47+
for instance in oci_core_instance.instance :
48+
instance.display_name => instance.public_ip
49+
}
50+
51+
all_instances = local.linux_ids
52+
all_private_ips = local.linux_private_ips
53+
all_public_ips = local.linux_public_ips
54+
}
55+
56+
output "linux_instances" {
57+
value = local.linux_instances
58+
}
59+
60+
output "all_instances" {
61+
value = local.all_instances
62+
}
63+
64+
output "all_private_ips" {
65+
value = local.all_private_ips
66+
}
67+
68+
output "all_public_ips" {
69+
value = local.all_public_ips
70+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright © 2023, Oracle and/or its affiliates.
2+
# All rights reserved. Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
variable "tenancy_ocid" {
5+
type = string
6+
}
7+
8+
variable "instance_params" {
9+
10+
type = map(object({
11+
12+
availability_domain = number
13+
compartment_id = string
14+
display_name = string
15+
shape = string
16+
17+
defined_tags = map(string)
18+
freeform_tags = map(string)
19+
20+
subnet_id = string
21+
vnic_display_name = string
22+
assign_public_ip = string
23+
hostname_label = string
24+
25+
ocpus = number
26+
memory_in_gbs = number
27+
28+
source_type = string
29+
source_id = string
30+
31+
metadata = map(string)
32+
33+
fault_domain = string
34+
35+
provisioning_timeout_mins = string
36+
37+
}))
38+
39+
}

0 commit comments

Comments
 (0)