Skip to content

Commit 3b9a4e6

Browse files
authored
Merge pull request #15 from hyder/image_id
added option to switch from Autonomous Linux to Oracle Linux platform…
2 parents 8a5b8e8 + 629ab4e commit 3b9a4e6

File tree

13 files changed

+117
-23
lines changed

13 files changed

+117
-23
lines changed

docs/terraformoptions.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,21 @@ Configuration Terraform Options:
141141
|XXX.XXX.XXX.XXX/YY
142142
|ANYWHERE
143143

144+
|bastion_image_id
145+
|Custom image id for the bastion host
146+
|image id or NONE. If the value is set to NONE, an Oracle Platform image will be used instead. Set use_autonomous to _false_ if you want to use your own image.
147+
|NONE
148+
144149
|bastion_shape
145150
|The shape of bastion instance.
146151
|
147152
|VM.Standard.E2.1
148153

154+
|bastion_upgrade
155+
|Whether to upgrade the bastion host packages after provisioning. It's useful to set this to false during development so the bastion is provisioned faster.
156+
|true/false
157+
|true
158+
149159
|create_bastion
150160
|Whether to create the bastion host.
151161
|true/false
@@ -216,4 +226,9 @@ Configuration Terraform Options:
216226
|
217227
|
218228

229+
|use_autonomous
230+
|Whether to use Autonomous Linux or an Oracle Linux Platform image or custom image. Set to false if you want to use your own image id or Oracle Linux Platform image.
231+
|true/false
232+
|false
233+
219234
|===

locals.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ locals {
3030

3131
oci_bastion = {
3232
bastion_access = var.oci_base_bastion.bastion_access
33+
bastion_image_id = var.oci_base_bastion.bastion_image_id
3334
bastion_shape = var.oci_base_bastion.bastion_shape
35+
bastion_upgrade = var.oci_base_bastion.bastion_upgrade
3436
create_bastion = var.oci_base_bastion.create_bastion
3537
enable_instance_principal = var.oci_base_bastion.enable_instance_principal
3638
ssh_public_key_path = var.oci_base_bastion.ssh_public_key_path
3739
timezone = var.oci_base_bastion.timezone
40+
use_autonomous = var.oci_base_bastion.use_autonomous
3841
}
3942

4043
oci_bastion_notification = {
File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
4+
#cloud-config
5+
bastion_package_upgrade: ${bastion_package_upgrade}
6+
packages:
7+
- ntp
8+
- python-pip
9+
timezone: ${timezone}
10+
11+
write_files:
12+
# setup script
13+
- path: "/root/bastion/bastion.sh"
14+
permissions: "0700"
15+
encoding: "gzip+base64"
16+
content: |
17+
${bastion_sh_content}
18+
runcmd:
19+
- echo "Configuring bastion..." | tee /root/bastion/bastion.txt
20+
- bash /root/bastion/bastion.sh
21+
- pip install oci-cli --upgrade pip
22+
- echo "export OCI_CLI_AUTH=instance_principal" >> /home/opc/.bashrc
23+
- touch /home/opc/bastion.finish

modules/bastion/compute.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ resource "oci_core_instance" "bastion" {
66
compartment_id = var.oci_base_identity.compartment_id
77

88
create_vnic_details {
9-
subnet_id = oci_core_subnet.bastion[0].id
10-
display_name = "${var.oci_bastion_general.label_prefix}-bastion-vnic"
11-
hostname_label = "bastion"
9+
assign_public_ip = true
10+
subnet_id = oci_core_subnet.bastion[0].id
11+
display_name = "${var.oci_bastion_general.label_prefix}-bastion-vnic"
12+
hostname_label = "bastion"
1213
}
1314

1415
display_name = "${var.oci_bastion_general.label_prefix}-bastion"
@@ -23,12 +24,12 @@ resource "oci_core_instance" "bastion" {
2324

2425
source_details {
2526
source_type = "image"
26-
source_id = lookup(data.oci_core_app_catalog_subscriptions.autonomous_linux.app_catalog_subscriptions[0], "listing_resource_id")
27+
source_id = local.bastion_image_id
2728
}
2829

2930
timeouts {
3031
create = "60m"
3132
}
3233

3334
count = var.oci_bastion.create_bastion == true ? 1 : 0
34-
}
35+
}

modules/bastion/datasources.tf

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
data "oci_core_app_catalog_listings" "autonomous_linux" {
55
display_name = "Oracle Autonomous Linux"
6+
count = var.oci_bastion.use_autonomous == true ? 1 : 0
67
}
78

89
data "oci_core_app_catalog_listing_resource_versions" "autonomous_linux" {
910
#Required
10-
listing_id = lookup(data.oci_core_app_catalog_listings.autonomous_linux.app_catalog_listings[0], "listing_id")
11+
listing_id = lookup(data.oci_core_app_catalog_listings.autonomous_linux[0].app_catalog_listings[0], "listing_id")
12+
count = var.oci_bastion.use_autonomous == true ? 1 : 0
1113
}
1214

1315
# Gets the Autonomous Linux image id
@@ -16,27 +18,53 @@ data "oci_core_app_catalog_subscriptions" "autonomous_linux" {
1618
compartment_id = var.oci_base_identity.compartment_id
1719

1820
#Optional
19-
listing_id = lookup(data.oci_core_app_catalog_listing_resource_versions.autonomous_linux.app_catalog_listing_resource_versions[0], "listing_id")
21+
listing_id = lookup(data.oci_core_app_catalog_listing_resource_versions.autonomous_linux[0].app_catalog_listing_resource_versions[0], "listing_id")
22+
count = var.oci_bastion.use_autonomous == true ? 1 : 0
2023
}
2124

22-
data "template_file" "bastion_template" {
23-
template = file("${path.module}/scripts/bastion.template.sh")
25+
data "template_file" "autonomous_template" {
26+
template = file("${path.module}/scripts/notification.template.sh")
2427

2528
vars = {
2629
notification_enabled = var.oci_bastion_notification.enable_notification
27-
topic_id = var.oci_bastion_notification.enable_notification == true ? oci_ons_notification_topic.bastion_notification[0].topic_id : "null"
30+
topic_id = var.oci_bastion_notification.enable_notification == true ? oci_ons_notification_topic.bastion_notification[0].topic_id : "null"
2831
}
29-
count = var.oci_bastion.create_bastion == true ? 1 : 0
32+
count = var.oci_bastion.create_bastion == true && var.oci_bastion.use_autonomous == true ? 1 : 0
3033
}
3134

32-
data "template_file" "bastion_cloud_init_file" {
33-
template = file("${path.module}/cloudinit/bastion.template.yaml")
35+
data "template_file" "autonomous_cloud_init_file" {
36+
template = file("${path.module}/cloudinit/autonomous.template.yaml")
3437

3538
vars = {
36-
notification_sh_content = base64gzip(data.template_file.bastion_template[0].rendered)
39+
notification_sh_content = base64gzip(data.template_file.autonomous_template[0].rendered)
3740
timezone = var.oci_bastion.timezone
3841
}
39-
count = var.oci_bastion.create_bastion == true ? 1 : 0
42+
count = var.oci_bastion.create_bastion == true && var.oci_bastion.use_autonomous == true ? 1 : 0
43+
}
44+
45+
data "oci_core_images" "oracle_images" {
46+
compartment_id = var.oci_base_identity.compartment_id
47+
operating_system = "Oracle Linux"
48+
operating_system_version = "7.7"
49+
shape = var.oci_bastion.bastion_shape
50+
sort_by = "TIMECREATED"
51+
count = var.oci_bastion.create_bastion == true && var.oci_bastion.use_autonomous == false ? 1 : 0
52+
}
53+
54+
data "template_file" "oracle_template" {
55+
template = file("${path.module}/scripts/oracle.template.sh")
56+
count = var.oci_bastion.create_bastion == true && var.oci_bastion.use_autonomous == false ? 1 : 0
57+
}
58+
59+
data "template_file" "oracle_cloud_init_file" {
60+
template = file("${path.module}/cloudinit/oracle.template.yaml")
61+
62+
vars = {
63+
bastion_sh_content = base64gzip(data.template_file.oracle_template[0].rendered)
64+
bastion_package_upgrade = var.oci_bastion.bastion_upgrade
65+
timezone = var.oci_bastion.timezone
66+
}
67+
count = var.oci_bastion.create_bastion == true && var.oci_bastion.use_autonomous == false ? 1 : 0
4068
}
4169

4270
# cloud init for bastion
@@ -47,7 +75,7 @@ data "template_cloudinit_config" "bastion" {
4775
part {
4876
filename = "bastion.yaml"
4977
content_type = "text/cloud-config"
50-
content = data.template_file.bastion_cloud_init_file[0].rendered
78+
content = var.oci_bastion.use_autonomous == true ? data.template_file.autonomous_cloud_init_file[0].rendered : data.template_file.oracle_cloud_init_file[0].rendered
5179
}
5280
count = var.oci_bastion.create_bastion == true ? 1 : 0
5381
}
@@ -62,14 +90,13 @@ data "oci_core_vnic_attachments" "bastion_vnics_attachments" {
6290
}
6391

6492
# Gets the OCID of the first (default) VNIC on the bastion instance
65-
data "oci_core_vnic" "bastion_vnic" {
93+
data "oci_core_vnic" "bastion_vnic_1" {
6694
vnic_id = lookup(data.oci_core_vnic_attachments.bastion_vnics_attachments[0].vnic_attachments[0], "vnic_id")
6795
depends_on = ["oci_core_instance.bastion"]
6896
count = var.oci_bastion.create_bastion == true ? 1 : 0
6997
}
7098

7199
data "oci_core_instance" "bastion" {
72-
#Required
73100
instance_id = oci_core_instance.bastion[0].id
74101
depends_on = ["oci_core_instance.bastion"]
75102
count = var.oci_bastion.create_bastion == true ? 1 : 0

modules/bastion/locals.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
# http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
66

77
locals {
8-
all_protocols = "all"
9-
anywhere = "0.0.0.0/0"
10-
ssh_port = 22
11-
tcp_protocol = 6
8+
all_protocols = "all"
9+
anywhere = "0.0.0.0/0"
10+
ssh_port = 22
11+
tcp_protocol = 6
12+
autonomous_image_id = lookup(data.oci_core_app_catalog_subscriptions.autonomous_linux[0].app_catalog_subscriptions[0], "listing_resource_id")
13+
oracle_image_id = data.oci_core_images.oracle_images[0].images.0.id
14+
bastion_image_id = var.oci_bastion.use_autonomous == true ? local.autonomous_image_id : (var.oci_bastion.bastion_image_id == "NONE" ? local.oracle_image_id : var.oci_bastion.bastion_image_id)
1215
}

modules/bastion/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
output "bastion_public_ip" {
55
description = "public IP address of bastion host"
6-
value = join(",", data.oci_core_vnic.bastion_vnic.*.public_ip_address)
6+
value = join(",", data.oci_core_vnic.bastion_vnic_1.*.public_ip_address)
77
}
88

99
output "bastion_instance_principal_group_name" {
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl
5+
6+
yum update --security
7+
8+
sed -i -e "s/autoinstall\s=\sno/autoinstall = yes/g" /etc/uptrack/uptrack.conf
9+
10+
uptrack-upgrade

0 commit comments

Comments
 (0)