This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcompute.tf
90 lines (76 loc) · 2.69 KB
/
compute.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
## Copyright © 2021, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
data "template_file" "key_script" {
template = file("./scripts/sshkey.tpl")
vars = {
ssh_public_key = tls_private_key.public_private_key_pair.public_key_openssh
}
}
data "template_cloudinit_config" "cloud_init" {
gzip = true
base64_encode = true
part {
filename = "ainit.sh"
content_type = "text/x-shellscript"
content = data.template_file.key_script.rendered
}
}
# Dictionary Locals
locals {
compute_flexible_shapes = [
"VM.Standard.E3.Flex",
"VM.Standard.E4.Flex",
"VM.Standard.A1.Flex",
"VM.Optimized3.Flex"
]
}
# Checks if is using Flexible Compute Shapes
locals {
is_flexible_node_shape = contains(local.compute_flexible_shapes, var.InstanceShape)
}
resource "oci_core_instance" "tomcat-server" {
count = var.numberOfNodes
availability_domain = var.availablity_domain_name == "" ? data.oci_identity_availability_domains.ADs.availability_domains[var.availablity_domain_number]["name"] : var.availablity_domain_name
compartment_id = var.compartment_ocid
display_name = "tomcat-server-${count.index}"
fault_domain = "FAULT-DOMAIN-${(count.index % 3) + 1}"
shape = var.InstanceShape
dynamic "agent_config" {
for_each = var.use_bastion_service ? [1] : []
content {
are_all_plugins_disabled = false
is_management_disabled = false
is_monitoring_disabled = false
plugins_config {
desired_state = "ENABLED"
name = "Bastion"
}
}
}
create_vnic_details {
subnet_id = oci_core_subnet.vcn01_subnet_app01.id
display_name = "primaryvnic"
assign_public_ip = false
nsg_ids = [oci_core_network_security_group.SSHSecurityGroup.id, oci_core_network_security_group.APPSecurityGroup.id]
}
source_details {
source_type = "image"
source_id = lookup(data.oci_core_images.InstanceImageOCID.images[0], "id")
boot_volume_size_in_gbs = "50"
}
provisioner "local-exec" {
command = "sleep 240"
}
metadata = {
ssh_authorized_keys = var.ssh_public_key
user_data = data.template_cloudinit_config.cloud_init.rendered
}
dynamic "shape_config" {
for_each = local.is_flexible_node_shape ? [1] : []
content {
memory_in_gbs = var.InstanceFlexShapeMemory
ocpus = var.InstanceFlexShapeOCPUS
}
}
defined_tags = { "${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
}