forked from oracle-quickstart/oci-arch-web-ha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute.tf
109 lines (87 loc) · 3.21 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
## Copyright © 2020, 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
# This Terraform script provisions a compute instance
data "template_file" "key_script" {
template = file("${path.module}/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
}
}
# Create Compute Instance
resource "oci_core_instance" "compute_instance1" {
availability_domain = local.availability_domain_name
compartment_id = var.compartment_ocid
display_name = "Web-Server-1"
shape = var.instance_shape
lifecycle {
ignore_changes = [ defined_tags["Oracle-Tags.CreatedBy"], defined_tags["Oracle-Tags.CreatedOn"] ]
}
dynamic "shape_config" {
for_each = local.is_flexible_node_shape ? [1] : []
content {
memory_in_gbs = var.instance_flex_shape_memory
ocpus = var.instance_flex_shape_ocpus
}
}
fault_domain = "FAULT-DOMAIN-1"
source_details {
source_type = "image"
source_id = data.oci_core_images.InstanceImageOCID.images[0].id
boot_volume_size_in_gbs = "50"
}
create_vnic_details {
subnet_id = oci_core_subnet.subnet_2.id
nsg_ids = [oci_core_network_security_group.WebSecurityGroup.id, oci_core_network_security_group.SSHSecurityGroup.id]
}
metadata = {
ssh_authorized_keys = local.ssh_public_key
user_data = data.template_cloudinit_config.cloud_init.rendered
}
defined_tags = {"${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
timeouts {
create = "60m"
}
}
resource "oci_core_instance" "compute_instance2" {
availability_domain = local.availability_domain_name
compartment_id = var.compartment_ocid
display_name = "Web-Server-2"
shape = var.instance_shape
lifecycle {
ignore_changes = [ defined_tags["Oracle-Tags.CreatedBy"], defined_tags["Oracle-Tags.CreatedOn"] ]
}
dynamic "shape_config" {
for_each = local.is_flexible_node_shape ? [1] : []
content {
memory_in_gbs = var.instance_flex_shape_memory
ocpus = var.instance_flex_shape_ocpus
}
}
fault_domain = "FAULT-DOMAIN-2"
source_details {
source_type = "image"
source_id = data.oci_core_images.InstanceImageOCID.images[0].id
boot_volume_size_in_gbs = "50"
}
create_vnic_details {
subnet_id = oci_core_subnet.subnet_2.id
nsg_ids = [oci_core_network_security_group.WebSecurityGroup.id, oci_core_network_security_group.SSHSecurityGroup.id]
}
metadata = {
ssh_authorized_keys = local.ssh_public_key
user_data = data.template_cloudinit_config.cloud_init.rendered
}
defined_tags = {"${oci_identity_tag_namespace.ArchitectureCenterTagNamespace.name}.${oci_identity_tag.ArchitectureCenterTag.name}" = var.release }
timeouts {
create = "60m"
}
}