Skip to content

Commit 22d0229

Browse files
authored
feat: added 1 egress rule to operator subnet (#48)
* feat: added 1 egress rule to operator subnet so users can use OCI bastion service to ssh to operator Signed-off-by: Ali Mukadam <[email protected]> * feat: added 1 egress rule to operator subnet so users can use OCI bastion service to ssh to operator (#46) Signed-off-by: Ali Mukadam <[email protected]> * Added security list to operator subnet * renamed operator_tags to freeform_tags, updated docs Signed-off-by: Ali Mukadam <[email protected]> * formatting on options table Signed-off-by: Ali Mukadam <[email protected]> * formatting on options table Signed-off-by: Ali Mukadam <[email protected]>
1 parent e2b8164 commit 22d0229

File tree

12 files changed

+91
-110
lines changed

12 files changed

+91
-110
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on {uri-changelog}[Keep a Changelog].
1111

1212
== New features
1313
* Changed default tag values
14+
* Renamed operator_tags --> freeform_tags
1415
* Renamed notification variables
1516
* Renamed variable operating_system_version --> operator_os_version
1617
* Renamed variable operator_upgrade --> upgrade_operator

compute.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ resource "oci_core_instance" "operator" {
1717
}
1818

1919
compartment_id = var.compartment_id
20-
freeform_tags = var.tags
20+
21+
freeform_tags = var.freeform_tags
2122

2223
create_vnic_details {
2324
assign_public_ip = false
2425
display_name = var.label_prefix == "none" ? "operator-vnic" : "${var.label_prefix}-operator-vnic"
2526
hostname_label = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
26-
nsg_ids = concat(var.nsg_ids, [oci_core_network_security_group.operator[0].id])
27-
subnet_id = oci_core_subnet.operator[0].id
27+
nsg_ids = concat(var.nsg_ids, [oci_core_network_security_group.operator.id])
28+
subnet_id = oci_core_subnet.operator.id
2829
}
2930

3031
display_name = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
@@ -40,8 +41,8 @@ resource "oci_core_instance" "operator" {
4041
}
4142

4243
metadata = {
43-
ssh_authorized_keys = var.ssh_public_key != "" ? var.ssh_public_key : file(var.ssh_public_key_path)
44-
user_data = data.cloudinit_config.operator[0].rendered
44+
ssh_authorized_keys = (var.ssh_public_key != "") ? var.ssh_public_key : (var.ssh_public_key_path != "none") ? file(var.ssh_public_key_path) : ""
45+
user_data = data.cloudinit_config.operator.rendered
4546
}
4647

4748
shape = lookup(var.operator_shape, "shape", "VM.Standard.E4.Flex")
@@ -64,6 +65,4 @@ resource "oci_core_instance" "operator" {
6465
timeouts {
6566
create = "60m"
6667
}
67-
68-
count = var.create_operator == true ? 1 : 0
6968
}

datasources.tf

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data "oci_core_images" "oracle_images" {
3030
shape = lookup(var.operator_shape, "shape", "VM.Standard.E4.Flex")
3131
sort_by = "TIMECREATED"
3232

33-
count = (var.create_operator == true && var.operator_image_id == "Oracle") ? 1 : 0
33+
count = var.operator_image_id == "Oracle" ? 1 : 0
3434
}
3535

3636
# cloud init for operator
@@ -49,30 +49,23 @@ data "cloudinit_config" "operator" {
4949
}
5050
)
5151
}
52-
count = var.create_operator == true ? 1 : 0
5352
}
5453

5554
# Gets a list of VNIC attachments on the operator instance
5655
data "oci_core_vnic_attachments" "operator_vnics_attachments" {
5756
availability_domain = data.oci_identity_availability_domain.ad.name
5857
compartment_id = var.compartment_id
5958
depends_on = [oci_core_instance.operator]
60-
instance_id = oci_core_instance.operator[0].id
61-
62-
count = var.create_operator == true ? 1 : 0
59+
instance_id = oci_core_instance.operator.id
6360
}
6461

6562
# Gets the OCID of the first (default) VNIC on the operator instance
6663
data "oci_core_vnic" "operator_vnic" {
6764
depends_on = [oci_core_instance.operator]
68-
vnic_id = lookup(data.oci_core_vnic_attachments.operator_vnics_attachments[0].vnic_attachments[0], "vnic_id")
69-
70-
count = var.create_operator == true ? 1 : 0
65+
vnic_id = lookup(data.oci_core_vnic_attachments.operator_vnics_attachments.vnic_attachments[0], "vnic_id")
7166
}
7267

7368
data "oci_core_instance" "operator" {
7469
depends_on = [oci_core_instance.operator]
75-
instance_id = oci_core_instance.operator[0].id
76-
77-
count = var.create_operator == true ? 1 : 0
70+
instance_id = oci_core_instance.operator.id
7871
}

docs/prerequisites.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Open a terminal and test:
9797
[source,bash]
9898
----
9999
terraform -v
100-
Terraform v0.12.24
100+
Terraform v1.0.3
101101
----
102102

103103
=== Generate and upload your OCI API keys

docs/terraformoptions.adoc

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
2222

2323
== Provider and Identity
2424

25-
[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"]
25+
[stripes=odd,cols="2,5,1,1", options=header,width="100%"]
2626
|===
2727
|Parameter
2828
|Description
@@ -38,7 +38,7 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
3838

3939
== General OCI
4040

41-
[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"]
41+
[stripes=odd,cols="2,5,1,1", options=header,width="100%"]
4242
|===
4343
|Parameter
4444
|Description
@@ -53,27 +53,27 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
5353
|`label_prefix`
5454
|a string to be prepended to the name of resources. *Required*.
5555
|
56-
|None
56+
|none
5757

5858

5959
|===
6060

6161
== Network Parameters
6262

63-
[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"]
63+
[stripes=odd,cols="2,5,1,1", options=header,width="100%"]
6464
|===
6565
|Parameter
6666
|Description
6767
|Values
6868
|Default
6969

7070
|`availability_domain`
71-
|the AD to place the operator host
71+
|The AD to place the operator host
7272
| 1
7373
| 1
7474

7575
|`nat_route_id`
76-
|the route id to the NAT gateway of the VCN
76+
|The route id to the NAT gateway of the VCN
7777
|
7878
|
7979

@@ -101,23 +101,37 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
101101

102102
== Operator Host Parameters
103103

104-
[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"]
104+
[stripes=odd,cols="2,5,1,1", options=header,width="100%"]
105105
|===
106106
|Parameter
107107
|Description
108108
|Values
109109
|Default
110110

111-
|`create_operator`
112-
|whether to create the operator
113-
| true/false
114-
|true
111+
|`freeform_tags`
112+
|Freeform tags for operator.
113+
|
114+
|`freeform_tags = {
115+
access = "restricted"
116+
environment = "dev"
117+
role = "operator"
118+
}`
115119

116120
|`operator_image_id`
117121
|Provide a custom image id for the operator host or leave as Oracle.
118122
|imageid/Oracle
119123
|Oracle
120124

125+
|`operator_instance_principal`
126+
|Whether to enable instance_principal on the operator.
127+
|true/false
128+
|false
129+
130+
|`operator_os_version`
131+
|The version of the Oracle Linux to use.
132+
|
133+
|8
134+
121135
|`operator_shape`
122136
|The shape of operator instance. This is now specified as a map and supports E3.Flex. If a non-Flex shape is specified, then the other parameters are ignored.
123137
|e.g. `operator_shape = {
@@ -135,18 +149,13 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
135149

136150
|`operator_state`
137151
|The target state for the instance. Could be set to RUNNING or STOPPED. (Updatable)
138-
|RUNNING|STOPPED
152+
|RUNNING/STOPPED
139153
|RUNNING
140154

141-
|`operator_upgrade`
142-
|Whether to upgrade the operator host packages after provisioning. It's useful to set this to false during development/testing so the operator is provisioned faster.
143-
|true/false
144-
|true
145-
146-
|`operator_os_version`
147-
|The version of the Oracle Linux to use.
148-
|
149-
|8
155+
|`operator_timezone`
156+
|The preferred timezone for the operator host. {uri-timezones}[List of timezones]
157+
|e.g. Australia/Sydney
158+
|The preferred timezone for the operator host. {uri-timezones}[List of timezones]
150159

151160
|`ssh_public_key`
152161
|the content of the ssh public key used to access the operator. set this or the ssh_public_key_path
@@ -158,17 +167,17 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
158167
|""
159168
|
160169

161-
|`operator_timezone`
162-
|The preferred timezone for the operator host. {uri-timezones}[List of timezones]
163-
|e.g. Australia/Sydney
164-
|The preferred timezone for the operator host. {uri-timezones}[List of timezones]
170+
|`upgrade_operator`
171+
|Whether to upgrade the operator host packages after provisioning. It's useful to set this to false during development/testing so the operator is provisioned faster.
172+
|true/false
173+
|true
165174

166175
|===
167176

168177

169178
== Notification Parameters
170179

171-
[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"]
180+
[stripes=odd,cols="2,5,1,1", options=header,width="100%"]
172181
|===
173182
|Parameter
174183
|Description
@@ -194,26 +203,3 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
194203
|The name of the notification topic.
195204
|
196205
|operator
197-
|===
198-
199-
== Tagging Parameters
200-
201-
[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"]
202-
|===
203-
|Parameter
204-
|Description
205-
|Values
206-
|Default
207-
208-
|`operator_tags`
209-
|Freeform tags for operator.
210-
|
211-
|
212-
[source]
213-
----
214-
operator_tags = {
215-
access = "restricted"
216-
environment = "dev"
217-
role = "operator"
218-
}
219-
----

instance_principal.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ resource "oci_identity_dynamic_group" "operator_instance_principal" {
1414
matching_rule = "ALL {instance.id = '${join(",", data.oci_core_instance.operator.*.id)}'}"
1515
name = "operator-instance-principal-${substr(uuid(), 0, 8)}"
1616

17-
count = var.create_operator == true && var.operator_instance_principal == true ? 1 : 0
17+
count = var.operator_instance_principal == true ? 1 : 0
1818
}
1919

2020
resource "oci_identity_policy" "operator_instance_principal" {
@@ -25,5 +25,5 @@ resource "oci_identity_policy" "operator_instance_principal" {
2525
name = var.label_prefix == "none" ? "operator-instance-principal" : "${var.label_prefix}-operator-instance-principal"
2626
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.operator_instance_principal[0].name} to manage all-resources in compartment id ${var.compartment_id}"]
2727

28-
count = var.create_operator == true && var.operator_instance_principal == true ? 1 : 0
28+
count = var.operator_instance_principal == true ? 1 : 0
2929
}

locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ locals {
1111

1212
operator_image_id = var.operator_image_id == "Oracle" ? data.oci_core_images.oracle_images[0].images.0.id : var.operator_image_id
1313

14+
operator_subnet = cidrsubnet(local.vcn_cidr, var.newbits, var.netnum)
1415
operator_template = "${path.module}/cloudinit/operator.template.yaml"
1516

1617
operator_script_template = base64gzip(

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ output "operator_private_ip" {
66
}
77

88
output "operator_instance_principal_group_name" {
9-
value = var.create_operator == true && var.operator_instance_principal == true ? oci_identity_dynamic_group.operator_instance_principal[0].name : null
9+
value = var.operator_instance_principal == true ? oci_identity_dynamic_group.operator_instance_principal[0].name : null
1010
}
1111

1212
output "operator_subnet_id" {

security.tf

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ resource "oci_core_network_security_group" "operator" {
66
compartment_id = var.compartment_id
77
display_name = "${var.label_prefix}-operator"
88
vcn_id = var.vcn_id
9-
10-
count = var.create_operator == true ? 1 : 0
119
}
1210

1311
resource "oci_core_network_security_group_security_rule" "operator_egress_anywhere" {
14-
network_security_group_id = oci_core_network_security_group.operator[0].id
12+
network_security_group_id = oci_core_network_security_group.operator.id
1513
description = "allow operator to egress to anywhere"
1614
destination = local.anywhere
1715
destination_type = "CIDR_BLOCK"
@@ -22,12 +20,10 @@ resource "oci_core_network_security_group_security_rule" "operator_egress_anywhe
2220
lifecycle {
2321
ignore_changes = [direction, protocol, source, source_type, tcp_options]
2422
}
25-
26-
count = var.create_operator == true ? 1 : 0
2723
}
2824

2925
resource "oci_core_network_security_group_security_rule" "operator_egress_osn" {
30-
network_security_group_id = oci_core_network_security_group.operator[0].id
26+
network_security_group_id = oci_core_network_security_group.operator.id
3127
description = "allow operator to egress to osn"
3228
destination = local.osn
3329
destination_type = "SERVICE_CIDR_BLOCK"
@@ -38,12 +34,10 @@ resource "oci_core_network_security_group_security_rule" "operator_egress_osn" {
3834
lifecycle {
3935
ignore_changes = [direction, protocol, source, source_type, tcp_options]
4036
}
41-
42-
count = var.create_operator == true ? 1 : 0
4337
}
4438

4539
resource "oci_core_network_security_group_security_rule" "operator_ingress" {
46-
network_security_group_id = oci_core_network_security_group.operator[0].id
40+
network_security_group_id = oci_core_network_security_group.operator.id
4741
description = "allow ssh access to operator from within vcn"
4842
direction = "INGRESS"
4943
protocol = local.tcp_protocol
@@ -61,6 +55,23 @@ resource "oci_core_network_security_group_security_rule" "operator_ingress" {
6155
lifecycle {
6256
ignore_changes = [direction, protocol, source, source_type, tcp_options]
6357
}
58+
}
59+
60+
resource "oci_core_security_list" "operator" {
61+
compartment_id = var.compartment_id
62+
display_name = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
63+
freeform_tags = var.freeform_tags
64+
65+
# egress rule to the same subnet to allow users to use OCI Bastion service to connect to the operator
66+
egress_security_rules {
67+
protocol = local.tcp_protocol
68+
destination = local.operator_subnet
69+
70+
tcp_options {
71+
min = local.ssh_port
72+
max = local.ssh_port
73+
}
74+
}
6475

65-
count = var.create_operator == true ? 1 : 0
76+
vcn_id = var.vcn_id
6677
}

subnets.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

44
resource "oci_core_subnet" "operator" {
5-
cidr_block = cidrsubnet(local.vcn_cidr, var.newbits, var.netnum)
5+
cidr_block = local.operator_subnet
66
compartment_id = var.compartment_id
77
display_name = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
88
dns_label = "operator"
9-
freeform_tags = var.tags
9+
freeform_tags = var.freeform_tags
1010
prohibit_public_ip_on_vnic = true
1111
route_table_id = var.nat_route_id
12+
security_list_ids = [oci_core_security_list.operator.id]
1213
vcn_id = var.vcn_id
13-
14-
count = var.create_operator == true ? 1 : 0
1514
}

0 commit comments

Comments
 (0)