Skip to content

Commit 754be6a

Browse files
authored
Merge pull request #28 from hyder/issue-27
use Autonomous Platform image for bastion. Make the notification & su…
2 parents 109aa69 + fd70039 commit 754be6a

File tree

12 files changed

+24
-108
lines changed

12 files changed

+24
-108
lines changed

docs/terraformoptions.adoc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ Configuration Terraform Options:
149149

150150
|bastion_image_id
151151
|Custom image id for the bastion host
152-
|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.
153-
|NONE
152+
|imageid/Autonomous
153+
|Autonomous
154154

155155
|bastion_shape
156156
|The shape of bastion instance.
@@ -222,11 +222,6 @@ Configuration Terraform Options:
222222
|
223223
|
224224

225-
|use_autonomous
226-
|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.
227-
|true/false
228-
|false
229-
230225
|===
231226

232227
== Admin Host
@@ -245,8 +240,8 @@ Configuration Terraform Options:
245240

246241
|admin_image_id
247242
|Custom image id for the admin host
248-
|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. For now, *do not use Autonomous for the admin host.*
249-
|NONE
243+
|image_id/Oracle. If the value is set to Oracle, an Oracle Platform image will be used instead.
244+
|Oracle
250245

251246
|enable_instance_principal
252247
|Whether to enable instance_principal on the admin server. Refer to {uri-instance-principal-note}[instance_principal][instance_principal]
@@ -288,9 +283,4 @@ Configuration Terraform Options:
288283
|
289284
|Australia/Sydney
290285

291-
|admin_use_autonomous
292-
|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. *Do not use autonomous for now*
293-
|true/false
294-
|false
295-
296286
|===

locals.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ locals {
3636
bastion_upgrade = var.oci_base_bastion.bastion_upgrade
3737
ssh_public_key_path = var.oci_base_bastion.ssh_public_key_path
3838
timezone = var.oci_base_bastion.timezone
39-
use_autonomous = var.oci_base_bastion.use_autonomous
4039
}
4140

4241
oci_bastion_notification = {

modules/admin/compute.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resource "oci_core_instance" "admin" {
2929

3030
source_details {
3131
source_type = "image"
32-
source_id = var.oci_admin.admin_image_id == "NONE" ? data.oci_core_images.admin_images.images.0.id : var.oci_admin.image_id
32+
source_id = local.admin_image_id
3333
}
3434

3535
timeouts {

modules/admin/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ locals {
99
anywhere = "0.0.0.0/0"
1010
ssh_port = 22
1111
tcp_protocol = 6
12+
admin_image_id = var.oci_admin.admin_image_id == "Oracle" ? data.oci_core_images.admin_images.images.0.id : var.oci_admin.admin_image_id
1213
}

modules/bastion/cloudinit/oracle.template.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

modules/bastion/datasources.tf

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,14 @@
11
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

4-
data "oci_core_app_catalog_listings" "autonomous_linux" {
5-
display_name = "Oracle Autonomous Linux"
6-
count = var.oci_bastion.use_autonomous == true ? 1 : 0
7-
}
8-
9-
data "oci_core_app_catalog_listing_resource_versions" "autonomous_linux" {
10-
#Required
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
13-
}
14-
15-
# Gets the Autonomous Linux image id
16-
data "oci_core_app_catalog_subscriptions" "autonomous_linux" {
17-
#Required
18-
compartment_id = var.oci_base_identity.compartment_id
19-
20-
#Optional
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
23-
}
24-
254
data "template_file" "autonomous_template" {
265
template = file("${path.module}/scripts/notification.template.sh")
276

287
vars = {
298
notification_enabled = var.oci_bastion_notification.notification_enabled
309
topic_id = var.oci_bastion_notification.notification_enabled == true ? oci_ons_notification_topic.bastion_notification[0].topic_id : "null"
3110
}
32-
count = var.oci_bastion.bastion_enabled == true && var.oci_bastion.use_autonomous == true ? 1 : 0
11+
count = (var.oci_bastion.bastion_enabled == true && var.oci_bastion.bastion_image_id == "Autonomous") ? 1 : 0
3312
}
3413

3514
data "template_file" "autonomous_cloud_init_file" {
@@ -39,32 +18,15 @@ data "template_file" "autonomous_cloud_init_file" {
3918
notification_sh_content = base64gzip(data.template_file.autonomous_template[0].rendered)
4019
timezone = var.oci_bastion.timezone
4120
}
42-
count = var.oci_bastion.bastion_enabled == true && var.oci_bastion.use_autonomous == true ? 1 : 0
21+
count = (var.oci_bastion.bastion_enabled == true && var.oci_bastion.bastion_image_id == "Autonomous") ? 1 : 0
4322
}
4423

45-
data "oci_core_images" "oracle_images" {
24+
data "oci_core_images" "autonomous_images" {
4625
compartment_id = var.oci_base_identity.compartment_id
47-
operating_system = "Oracle Linux"
26+
operating_system = "Autonomous Linux"
4827
operating_system_version = "7.7"
4928
shape = var.oci_bastion.bastion_shape
5029
sort_by = "TIMECREATED"
51-
count = var.oci_bastion.bastion_enabled == 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.bastion_enabled == 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.bastion_enabled == true && var.oci_bastion.use_autonomous == false ? 1 : 0
6830
}
6931

7032
# cloud init for bastion
@@ -75,7 +37,7 @@ data "template_cloudinit_config" "bastion" {
7537
part {
7638
filename = "bastion.yaml"
7739
content_type = "text/cloud-config"
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
40+
content = data.template_file.autonomous_cloud_init_file[0].rendered
7941
}
8042
count = var.oci_bastion.bastion_enabled == true ? 1 : 0
8143
}

modules/bastion/locals.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
# https://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
12-
autonomous_image_id = var.oci_bastion.use_autonomous == true ? lookup(data.oci_core_app_catalog_subscriptions.autonomous_linux[0].app_catalog_subscriptions[0], "listing_resource_id") : null
13-
oracle_image_id = var.oci_bastion.use_autonomous == false ? data.oci_core_images.oracle_images[0].images.0.id : null
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)
8+
all_protocols = "all"
9+
anywhere = "0.0.0.0/0"
10+
ssh_port = 22
11+
tcp_protocol = 6
12+
bastion_image_id = var.oci_bastion.bastion_image_id == "Autonomous" ? data.oci_core_images.autonomous_images.images.0.id : var.oci_bastion.bastion_image_id
1513
}

modules/bastion/ons.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "oci_ons_notification_topic" "bastion_notification" {
2525
#Required
2626
compartment_id = var.oci_base_identity.compartment_id
2727
name = "${var.oci_bastion_general.label_prefix}-${var.oci_bastion_notification.notification_topic}"
28-
count = var.oci_bastion_notification.notification_enabled == true ? 1 : 0
28+
count = (var.oci_bastion.bastion_enabled == true && var.oci_bastion_notification.notification_enabled == true) ? 1 : 0
2929
}
3030

3131
resource "oci_ons_subscription" "bastion_notification" {
@@ -34,7 +34,7 @@ resource "oci_ons_subscription" "bastion_notification" {
3434
endpoint = var.oci_bastion_notification.notification_endpoint
3535
protocol = var.oci_bastion_notification.notification_protocol
3636
topic_id = oci_ons_notification_topic.bastion_notification[0].topic_id
37-
count = var.oci_bastion_notification.notification_enabled == true ? 1 : 0
37+
count = (var.oci_bastion.bastion_enabled == true && var.oci_bastion_notification.notification_enabled == true) ? 1 : 0
3838
}
3939

4040
resource "oci_identity_dynamic_group" "bastion_notification" {
@@ -44,7 +44,7 @@ resource "oci_identity_dynamic_group" "bastion_notification" {
4444
matching_rule = "ALL {instance.id = '${join(",", data.oci_core_instance.bastion.*.id)}'}"
4545
name = "${var.oci_bastion_general.label_prefix}-bastion-notification"
4646
depends_on = [oci_core_instance.bastion]
47-
count = var.oci_bastion_notification.notification_enabled == true && var.oci_bastion.bastion_enabled == true ? 1 : 0
47+
count = (var.oci_bastion.bastion_enabled == true && var.oci_bastion_notification.notification_enabled == true) ? 1 : 0
4848
}
4949

5050
resource "oci_identity_policy" "bastion_notification" {
@@ -54,5 +54,5 @@ resource "oci_identity_policy" "bastion_notification" {
5454
name = "${var.oci_bastion_general.label_prefix}-bastion-notification"
5555
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.bastion_notification[0].name} to use ons-topic in compartment id ${data.oci_identity_compartments.compartments_id.compartments.0.id} where request.permission='ONS_TOPIC_PUBLISH'"]
5656
depends_on = [oci_core_instance.bastion]
57-
count = var.oci_bastion.bastion_enabled == true && var.oci_bastion_notification.notification_enabled == true ? 1 : 0
57+
count = (var.oci_bastion.bastion_enabled == true && var.oci_bastion_notification.notification_enabled == true) ? 1 : 0
5858
}

modules/bastion/scripts/oracle.template.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

modules/bastion/variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ variable "oci_bastion" {
4747
bastion_upgrade = bool
4848
ssh_public_key_path = string
4949
timezone = string
50-
use_autonomous = bool
5150
})
5251
description = "bastion host parameters"
5352
}

0 commit comments

Comments
 (0)