Skip to content

Commit 292dd9f

Browse files
authored
List of cidr blocks for bastion access (#31)
* changed bastion access to list of cidr blocks, renamed control variables so downstream modules can distinguish between bastion host and bastion svc * feat: changed bastion access to list of cidr blocks, renamed control variables so downstream modules can distinguish between bastion host and bastion svc * updated Copyright
1 parent 8854827 commit 292dd9f

14 files changed

+125
-77
lines changed

.terraform.lock.hcl

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ The format is based on {uri-changelog}[Keep a Changelog].
1010
= Unreleased
1111

1212
== New features
13+
* Renamed notification variables
14+
** create_bastion -> create_bastion_host
15+
** enable_notification -> create_bastion_notification
16+
** notification_endpoint -> bastion_notification_endpoint
17+
** notification_protocol -> bastion_notification_protocol
18+
** notification_topic -> bastion_notification_topic
19+
** Changed bastion access from a single CIDR to a list of CIDR blocks (#29)
1320
* Renamed variable bastion_upgrade --> upgrade_bastion
1421
* Renamed variable timezone --> bastion_timezone
1522
* AD lookup mechanism reimplemented to remove dependency on deprecated template_file data source

cloudinit/autonomous.template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2019, 2021 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

44
#cloud-config

compute.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2019, 2021 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

44
resource "oci_core_instance" "bastion" {
@@ -64,5 +64,5 @@ resource "oci_core_instance" "bastion" {
6464
create = "60m"
6565
}
6666

67-
count = var.create_bastion == true ? 1 : 0
67+
count = var.create_bastion_host == true ? 1 : 0
6868
}

datasources.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2019, 2021 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

44
data "oci_identity_availability_domain" "ad" {
@@ -48,7 +48,7 @@ data "cloudinit_config" "bastion" {
4848
}
4949
)
5050
}
51-
count = var.create_bastion == true ? 1 : 0
51+
count = var.create_bastion_host == true ? 1 : 0
5252
}
5353

5454
# Gets a list of VNIC attachments on the bastion instance
@@ -58,26 +58,26 @@ data "oci_core_vnic_attachments" "bastion_vnics_attachments" {
5858
depends_on = [oci_core_instance.bastion]
5959
instance_id = oci_core_instance.bastion[0].id
6060

61-
count = var.create_bastion == true ? 1 : 0
61+
count = var.create_bastion_host == true ? 1 : 0
6262
}
6363

6464
# Gets the OCID of the first (default) VNIC on the bastion instance
6565
data "oci_core_vnic" "bastion_vnic" {
6666
depends_on = [oci_core_instance.bastion]
6767
vnic_id = lookup(data.oci_core_vnic_attachments.bastion_vnics_attachments[0].vnic_attachments[0], "vnic_id")
6868

69-
count = var.create_bastion == true ? 1 : 0
69+
count = var.create_bastion_host == true ? 1 : 0
7070
}
7171

7272
data "oci_core_instance" "bastion" {
7373
depends_on = [oci_core_instance.bastion]
7474
instance_id = oci_core_instance.bastion[0].id
7575

76-
count = var.create_bastion == true ? 1 : 0
76+
count = var.create_bastion_host == true ? 1 : 0
7777
}
7878

7979
data "oci_ons_notification_topic" "bastion_notification" {
8080
topic_id = oci_ons_notification_topic.bastion_notification[0].topic_id
8181

82-
count = (var.create_bastion == true && var.enable_notification == true) ? 1 : 0
82+
count = (var.create_bastion_host == true && var.create_bastion_notification == true) ? 1 : 0
8383
}

docs/terraformoptions.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
9393
|1
9494

9595
|`bastion_access`
96-
|CIDR block in the form of a string to which ssh access to the bastion must be restricted to. *_ANYWHERE_* is equivalent to 0.0.0.0/0 and allows ssh access from anywhere.
97-
|ANYWHERE or a cidr block such as XXX.XXX.XXX.XXX/YY
98-
|ANYWHERE
96+
|A list of CIDR blocks to which ssh access to the bastion must be restricted to. *anywhere* is equivalent to 0.0.0.0/0 and allows ssh access from anywhere. Updatable.
97+
|["anywhere"] or a list of cidr block such as [XXX.XXX.XXX.XXX/YY]
98+
|["anywhere"]
9999

100100
|`ig_route_id`
101101
|the route id to the internet gateway of the VCN
@@ -128,8 +128,8 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
128128
|Values
129129
|Default
130130

131-
|`create_bastion`
132-
|whether to create the bastion
131+
|`create_bastion_host`
132+
|whether to create the bastion host
133133
| true/false
134134
|true
135135

@@ -200,22 +200,22 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
200200
|Values
201201
|Default
202202

203-
|`enable_notification`
203+
|`create_bastion_notification`
204204
|Whether to enable ONS notification for the bastion host.
205205
|true/false
206206
|false
207207

208-
|`notification_endpoint`
208+
|`bastion_notification_endpoint`
209209
|The subscription notification endpoint. Email address to be notified. *Required if enable_notification = true* ..
210210
|
211211
|Autonomous
212212

213-
|`notification_protocol`
213+
|`bastion_notification_protocol`
214214
|The notification protocol used.
215215
|
216216
|EMAIL
217217

218-
|`notification_topic`
218+
|`bastion_notification_topic`
219219
|The name of the notification topic.
220220
|
221221
|bastion
@@ -237,7 +237,7 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
237237
[source]
238238
----
239239
tags = {
240-
department = "finance"
240+
access = "public"
241241
environment = "dev"
242242
role = "bastion"
243243
}

locals.tf

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
# Copyright 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2019, 2021 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

44
# Protocols are specified as protocol numbers.
55
# https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
66

77
locals {
8-
all_protocols = "all"
9-
10-
anywhere = "0.0.0.0/0"
11-
8+
all_protocols = "all"
9+
10+
anywhere = "0.0.0.0/0"
11+
1212
autonomous_template = "${path.module}/cloudinit/autonomous.template.yaml"
13-
14-
bastion_image_id = var.bastion_image_id == "Autonomous" ? data.oci_core_images.autonomous_images.images.0.id : var.bastion_image_id
15-
13+
14+
bastion_image_id = var.bastion_image_id == "Autonomous" ? data.oci_core_images.autonomous_images.images.0.id : var.bastion_image_id
15+
1616
notification_template = base64gzip(
1717
templatefile("${path.module}/scripts/notification.template.sh",
1818
{
19-
enable_notification = var.enable_notification,
20-
topic_id = var.enable_notification == true ? oci_ons_notification_topic.bastion_notification[0].topic_id : "null"
19+
create_bastion_notification = var.create_bastion_notification,
20+
topic_id = var.create_bastion_notification == true ? oci_ons_notification_topic.bastion_notification[0].topic_id : "null"
2121
}
2222
)
2323
)
24-
25-
ssh_port = 22
26-
24+
25+
ssh_port = 22
26+
2727
tcp_protocol = 6
28-
29-
vcn_cidr = data.oci_core_vcn.vcn.cidr_block
28+
29+
vcn_cidr = data.oci_core_vcn.vcn.cidr_block
3030
}

ons.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2019, 2021 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

44
provider "oci" {
@@ -12,18 +12,18 @@ provider "oci" {
1212

1313
resource "oci_ons_notification_topic" "bastion_notification" {
1414
compartment_id = var.compartment_id
15-
name = var.label_prefix == "none" ? var.notification_topic : "${var.label_prefix}-${var.notification_topic}"
15+
name = var.label_prefix == "none" ? var.bastion_notification_topic : "${var.label_prefix}-${var.bastion_notification_topic}"
1616

17-
count = (var.create_bastion == true && var.enable_notification == true) ? 1 : 0
17+
count = (var.create_bastion_host == true && var.create_bastion_notification == true) ? 1 : 0
1818
}
1919

2020
resource "oci_ons_subscription" "bastion_notification" {
2121
compartment_id = var.compartment_id
22-
endpoint = var.notification_endpoint
23-
protocol = var.notification_protocol
22+
endpoint = var.bastion_notification_endpoint
23+
protocol = var.bastion_notification_protocol
2424
topic_id = oci_ons_notification_topic.bastion_notification[0].topic_id
2525

26-
count = (var.create_bastion == true && var.enable_notification == true) ? 1 : 0
26+
count = (var.create_bastion_host == true && var.create_bastion_notification == true) ? 1 : 0
2727
}
2828

2929
resource "oci_identity_dynamic_group" "bastion_notification" {
@@ -35,7 +35,7 @@ resource "oci_identity_dynamic_group" "bastion_notification" {
3535
matching_rule = "ALL {instance.id = '${join(",", data.oci_core_instance.bastion.*.id)}'}"
3636
name = var.label_prefix == "none" ? "bastion-notification" : "${var.label_prefix}-bastion-notification"
3737

38-
count = (var.create_bastion == true && var.enable_notification == true) ? 1 : 0
38+
count = (var.create_bastion_host == true && var.create_bastion_notification == true) ? 1 : 0
3939
}
4040

4141
resource "oci_identity_policy" "bastion_notification" {
@@ -47,5 +47,5 @@ resource "oci_identity_policy" "bastion_notification" {
4747
name = var.label_prefix == "none" ? "bastion-notification" : "${var.label_prefix}-bastion-notification"
4848
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.bastion_notification[0].name} to use ons-topic in compartment id ${var.compartment_id} where request.permission='ONS_TOPIC_PUBLISH'"]
4949

50-
count = (var.create_bastion == true && var.enable_notification == true) ? 1 : 0
50+
count = (var.create_bastion_host == true && var.create_bastion_notification == true) ? 1 : 0
5151
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved.
1+
# Copyright 2019, 2021 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

44
output "bastion_public_ip" {

scripts/notification.template.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

3-
# Copyright 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved.
3+
# Copyright 2019, 2021 Oracle Corporation and/or affiliates. All rights reserved.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55

6-
if [ ${enable_notification} ]; then
6+
if [ ${create_bastion_notification} ]; then
77
sudo al-config -T ${topic_id}
88
else
99
echo 'ONS notification not enabled'

0 commit comments

Comments
 (0)