Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 45cdb45

Browse files
authored
Merge pull request #10 from oracle-devrel/fixed-bastion
Fixed bastion
2 parents d29b901 + 069cb78 commit 45cdb45

File tree

3 files changed

+112
-7
lines changed

3 files changed

+112
-7
lines changed

bastion.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
## Copyright (c) 2022 Oracle and/or its affiliates.
22
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33

4+
locals {
5+
use_bastion_service = (var.free_tier == false && var.use_bastion_service == true) ? true : false
6+
use_bastion_host = (var.free_tier == false && var.use_bastion_service == false) ? true : false
7+
}
8+
49
resource "oci_bastion_bastion" "bastion-service" {
5-
count = var.use_bastion_service ? 1 : 0
10+
count = local.use_bastion_service ? 1 : 0
611
bastion_type = "STANDARD"
712
compartment_id = var.compartment_ocid
813
target_subnet_id = oci_core_subnet.vcn01_subnet_pub02.id
@@ -22,7 +27,7 @@ resource "oci_bastion_session" "ssh_via_bastion_service" {
2227
oci_core_network_security_group_security_rule.SSHSecurityIngressGroupRules
2328
]
2429

25-
count = var.use_bastion_service ? var.numberOfNodes : 0
30+
count = local.use_bastion_service ? var.numberOfNodes : 0
2631
bastion_id = oci_bastion_bastion.bastion-service[0].id
2732

2833
key_details {
@@ -45,7 +50,7 @@ resource "oci_bastion_session" "ssh_via_bastion_service" {
4550

4651

4752
resource "oci_core_instance" "bastion_instance" {
48-
count = var.use_bastion_service ? 0 : 1
53+
count = local.use_bastion_host ? 1 : 0
4954
availability_domain = var.availability_domain_name == "" ? data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain_number]["name"] : var.availability_domain_name
5055
compartment_id = var.compartment_ocid
5156
display_name = "BastionVM"

remote.tf

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ data "template_file" "tomcat_context_xml" {
3838
}
3939
}
4040

41-
resource "null_resource" "tomcat-server-config" {
41+
resource "null_resource" "tomcat_server_config_with_bastion" {
4242
depends_on = [oci_core_instance.tomcat-server, module.terraform-oci-arch-adb.adb_database]
43-
count = var.numberOfNodes
43+
count = var.free_tier ? 0 : var.numberOfNodes
4444

4545
provisioner "local-exec" {
4646
command = "echo '${module.terraform-oci-arch-adb.adb_database.adb_wallet_content}' >> ${var.atp_tde_wallet_zip_file}_encoded-${count.index}"
@@ -156,4 +156,100 @@ resource "null_resource" "tomcat-server-config" {
156156

157157
}
158158

159+
resource "null_resource" "tomcat_server_config_without_bastion" {
160+
depends_on = [oci_core_instance.tomcat-server, module.terraform-oci-arch-adb.adb_database]
161+
count = var.free_tier ? var.numberOfNodes : 0
162+
163+
provisioner "local-exec" {
164+
command = "echo '${module.terraform-oci-arch-adb.adb_database.adb_wallet_content}' >> ${var.atp_tde_wallet_zip_file}_encoded-${count.index}"
165+
}
166+
167+
provisioner "local-exec" {
168+
command = "base64 --decode ${var.atp_tde_wallet_zip_file}_encoded-${count.index} > ${var.atp_tde_wallet_zip_file}-${count.index}"
169+
}
170+
171+
provisioner "local-exec" {
172+
command = "rm -rf ${var.atp_tde_wallet_zip_file}_encoded-${count.index}"
173+
}
174+
175+
provisioner "file" {
176+
connection {
177+
type = "ssh"
178+
user = "opc"
179+
host = data.oci_core_vnic.tomcat-server_primaryvnic[count.index].public_ip_address
180+
private_key = tls_private_key.public_private_key_pair.private_key_pem
181+
script_path = "/home/opc/myssh.sh"
182+
agent = false
183+
timeout = "10m"
184+
}
185+
source = "${var.atp_tde_wallet_zip_file}-${count.index}"
186+
destination = "/tmp/${var.atp_tde_wallet_zip_file}"
187+
}
188+
189+
provisioner "local-exec" {
190+
command = "rm -rf ${var.atp_tde_wallet_zip_file}-${count.index}"
191+
}
192+
193+
provisioner "file" {
194+
connection {
195+
type = "ssh"
196+
user = "opc"
197+
host = data.oci_core_vnic.tomcat-server_primaryvnic[count.index].public_ip_address
198+
private_key = tls_private_key.public_private_key_pair.private_key_pem
199+
script_path = "/home/opc/myssh.sh"
200+
agent = false
201+
timeout = "10m"
202+
}
203+
204+
content = data.template_file.tomcat_template[count.index].rendered
205+
destination = "/home/opc/tomcat_bootstrap.sh"
206+
}
207+
208+
provisioner "file" {
209+
connection {
210+
type = "ssh"
211+
user = "opc"
212+
host = data.oci_core_vnic.tomcat-server_primaryvnic[count.index].public_ip_address
213+
private_key = tls_private_key.public_private_key_pair.private_key_pem
214+
script_path = "/home/opc/myssh.sh"
215+
agent = false
216+
timeout = "10m"
217+
}
218+
219+
content = data.template_file.tomcat_service_template[count.index].rendered
220+
destination = "/home/opc/tomcat.service"
221+
}
222+
223+
provisioner "file" {
224+
connection {
225+
type = "ssh"
226+
user = "opc"
227+
host = data.oci_core_vnic.tomcat-server_primaryvnic[count.index].public_ip_address
228+
private_key = tls_private_key.public_private_key_pair.private_key_pem
229+
script_path = "/home/opc/myssh.sh"
230+
agent = false
231+
timeout = "10m"
232+
}
233+
234+
content = data.template_file.tomcat_context_xml.rendered
235+
destination = "~/context.xml"
236+
}
237+
238+
provisioner "remote-exec" {
239+
connection {
240+
type = "ssh"
241+
user = "opc"
242+
host = data.oci_core_vnic.tomcat-server_primaryvnic[count.index].public_ip_address
243+
private_key = tls_private_key.public_private_key_pair.private_key_pem
244+
script_path = "/home/opc/myssh.sh"
245+
agent = false
246+
timeout = "10m"
247+
}
248+
inline = [
249+
"chmod +x ~/tomcat_bootstrap.sh",
250+
"sudo ~/tomcat_bootstrap.sh"
251+
]
252+
}
253+
254+
}
159255

schema.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,16 @@ variables:
160160

161161
use_bastion_service:
162162
type: boolean
163-
visibile: true
164163
default: false
165164
required: false
166165
title: "Use OCI Bastion Service"
167166
description: "Check the box to use OCI Bastion Service instead of Bastion Host VM."
168-
167+
visible:
168+
and:
169+
- eq:
170+
- free_tier
171+
- false
172+
169173
# Optional Configuration
170174

171175
ssh_public_key:

0 commit comments

Comments
 (0)