generated from oracle-devrel/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
106b51e
commit 4f79b1e
Showing
3 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
cloud-foundation/modules/cloud-foundation-library/instance_flexible/instance.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
# } | ||
} |
70 changes: 70 additions & 0 deletions
70
cloud-foundation/modules/cloud-foundation-library/instance_flexible/outputs.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
39 changes: 39 additions & 0 deletions
39
cloud-foundation/modules/cloud-foundation-library/instance_flexible/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
})) | ||
|
||
} |