Skip to content

Commit ee7601c

Browse files
authored
Use updated data sources definition to look up VCN cidr. Also removed create_operator variable (#50)
Signed-off-by: Ali Mukadam <[email protected]>
1 parent 22d0229 commit ee7601c

File tree

8 files changed

+157
-152
lines changed

8 files changed

+157
-152
lines changed

CHANGELOG.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ The format is based on {uri-changelog}[Keep a Changelog].
2020
* AD lookup mechanism reimplemented to remove dependency on deprecated template_file data source
2121
* Replaced deprecated template_file data source with templatefile function
2222
* Set minimum Terraform version to 1.0.0
23-
* Renamed var.operator_enabled --> var.create_operator
2423
* New variable (`operator_state`) to specify state of operator host
2524
* Removed security list and using NSG instead
2625

2726
== Changes
2827
* Set default shape to E4.Flex
2928

29+
== Deletion
30+
* * Deleted var.operator_enabled. This can now be controlled using higher level modules.
31+
3032
== Deprecation notice
3133

3234
The following variables will be renamed at the next major release of this module:

compute.tf

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,67 @@
1-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2-
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3-
4-
resource "oci_core_instance" "operator" {
5-
availability_domain = data.oci_identity_availability_domain.ad.name
6-
7-
agent_config {
8-
9-
are_all_plugins_disabled = false
10-
is_management_disabled = false
11-
is_monitoring_disabled = false
12-
13-
plugins_config {
14-
desired_state = "ENABLED"
15-
name = "Bastion"
16-
}
17-
}
18-
19-
compartment_id = var.compartment_id
20-
21-
freeform_tags = var.freeform_tags
22-
23-
create_vnic_details {
24-
assign_public_ip = false
25-
display_name = var.label_prefix == "none" ? "operator-vnic" : "${var.label_prefix}-operator-vnic"
26-
hostname_label = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
27-
nsg_ids = concat(var.nsg_ids, [oci_core_network_security_group.operator.id])
28-
subnet_id = oci_core_subnet.operator.id
29-
}
30-
31-
display_name = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
32-
33-
launch_options {
34-
boot_volume_type = "PARAVIRTUALIZED"
35-
network_type = "PARAVIRTUALIZED"
36-
}
37-
38-
# prevent the operator from destroying and recreating itself if the image ocid changes
39-
lifecycle {
40-
ignore_changes = [source_details[0].source_id]
41-
}
42-
43-
metadata = {
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
46-
}
47-
48-
shape = lookup(var.operator_shape, "shape", "VM.Standard.E4.Flex")
49-
50-
dynamic "shape_config" {
51-
for_each = length(regexall("Flex", lookup(var.operator_shape, "shape", "VM.Standard.E4.Flex"))) > 0 ? [1] : []
52-
content {
53-
ocpus = max(1, lookup(var.operator_shape, "ocpus", 1))
54-
memory_in_gbs = (lookup(var.operator_shape, "memory", 4) / lookup(var.operator_shape, "ocpus", 1)) > 64 ? (lookup(var.operator_shape, "ocpus", 1) * 4) : lookup(var.operator_shape, "memory", 4)
55-
}
56-
}
57-
58-
source_details {
59-
source_type = "image"
60-
source_id = local.operator_image_id
61-
}
62-
63-
state = var.operator_state
64-
65-
timeouts {
66-
create = "60m"
67-
}
68-
}
1+
# Copyright 2017, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
resource "oci_core_instance" "operator" {
5+
availability_domain = data.oci_identity_availability_domain.ad.name
6+
7+
agent_config {
8+
9+
are_all_plugins_disabled = false
10+
is_management_disabled = false
11+
is_monitoring_disabled = false
12+
13+
plugins_config {
14+
desired_state = "ENABLED"
15+
name = "Bastion"
16+
}
17+
}
18+
19+
compartment_id = var.compartment_id
20+
freeform_tags = var.freeform_tags
21+
22+
create_vnic_details {
23+
assign_public_ip = false
24+
display_name = var.label_prefix == "none" ? "operator-vnic" : "${var.label_prefix}-operator-vnic"
25+
hostname_label = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
26+
nsg_ids = concat(var.nsg_ids, [oci_core_network_security_group.operator.id])
27+
subnet_id = oci_core_subnet.operator.id
28+
}
29+
30+
display_name = var.label_prefix == "none" ? "operator" : "${var.label_prefix}-operator"
31+
32+
launch_options {
33+
boot_volume_type = "PARAVIRTUALIZED"
34+
network_type = "PARAVIRTUALIZED"
35+
}
36+
37+
# prevent the operator from destroying and recreating itself if the image ocid changes
38+
lifecycle {
39+
ignore_changes = [source_details[0].source_id]
40+
}
41+
42+
metadata = {
43+
ssh_authorized_keys = (var.ssh_public_key != "") ? var.ssh_public_key : (var.ssh_public_key_path != "none") ? file(var.ssh_public_key_path) : ""
44+
user_data = data.cloudinit_config.operator.rendered
45+
}
46+
47+
shape = lookup(var.operator_shape, "shape", "VM.Standard.E4.Flex")
48+
49+
dynamic "shape_config" {
50+
for_each = length(regexall("Flex", lookup(var.operator_shape, "shape", "VM.Standard.E4.Flex"))) > 0 ? [1] : []
51+
content {
52+
ocpus = max(1, lookup(var.operator_shape, "ocpus", 1))
53+
memory_in_gbs = (lookup(var.operator_shape, "memory", 4) / lookup(var.operator_shape, "ocpus", 1)) > 64 ? (lookup(var.operator_shape, "ocpus", 1) * 4) : lookup(var.operator_shape, "memory", 4)
54+
}
55+
}
56+
57+
source_details {
58+
source_type = "image"
59+
source_id = local.operator_image_id
60+
}
61+
62+
state = var.operator_state
63+
64+
timeouts {
65+
create = "60m"
66+
}
67+
}

docs/instanceprincipal.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ When you enable this feature, by default, the operator host has privileges to ma
4343

4444
You can also turn on and off the feature at any time without impact on the operator host.
4545

46-
To enable, set enable_instance_principal to true:
46+
To enable, set operator_instance_principal to true:
4747

4848
[source,hcl]
4949
----
50-
enable_instance_principal = true
50+
operator_instance_principal = true
5151
----
5252

5353
and verify:
@@ -60,11 +60,11 @@ You should be able to see a list of VCNs created in the compartment.
6060

6161
==== Disabling instance_principal on the operator host
6262

63-
To disable, set enable_instance_principal to false:
63+
To disable, set operator_instance_principal to false:
6464

6565
[source, hcl]
6666
----
67-
enable_instance_principal = false
67+
operator_instance_principal = false
6868
----
6969

7070
. Run terraform apply again:

docs/quickstart.adoc

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

3232
1. git is installed
3333
2. ssh client is installed
34-
3. Terraform 0.12.24+ is installed
34+
3. Terraform 1.0.0 is installed
3535

3636
=== Provisioning using this git repo
3737

docs/terraformoptions.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,4 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
203203
|The name of the notification topic.
204204
|
205205
|operator
206+
|===

locals.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ locals {
2828

2929
tcp_protocol = 6
3030

31-
vcn_cidr = data.oci_core_vcn.vcn.cidr_block
31+
# we expect the operator to be in the first cidr block in the list of cidr blocks
32+
vcn_cidr = element(data.oci_core_vcn.vcn.cidr_blocks, 0)
3233
}

security.tf

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2-
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3-
4-
# operator nsg and rule
5-
resource "oci_core_network_security_group" "operator" {
6-
compartment_id = var.compartment_id
7-
display_name = "${var.label_prefix}-operator"
8-
vcn_id = var.vcn_id
9-
}
10-
11-
resource "oci_core_network_security_group_security_rule" "operator_egress_anywhere" {
12-
network_security_group_id = oci_core_network_security_group.operator.id
13-
description = "allow operator to egress to anywhere"
14-
destination = local.anywhere
15-
destination_type = "CIDR_BLOCK"
16-
direction = "EGRESS"
17-
protocol = local.all_protocols
18-
stateless = false
19-
20-
lifecycle {
21-
ignore_changes = [direction, protocol, source, source_type, tcp_options]
22-
}
23-
}
24-
25-
resource "oci_core_network_security_group_security_rule" "operator_egress_osn" {
26-
network_security_group_id = oci_core_network_security_group.operator.id
27-
description = "allow operator to egress to osn"
28-
destination = local.osn
29-
destination_type = "SERVICE_CIDR_BLOCK"
30-
direction = "EGRESS"
31-
protocol = local.all_protocols
32-
stateless = false
33-
34-
lifecycle {
35-
ignore_changes = [direction, protocol, source, source_type, tcp_options]
36-
}
37-
}
38-
39-
resource "oci_core_network_security_group_security_rule" "operator_ingress" {
40-
network_security_group_id = oci_core_network_security_group.operator.id
41-
description = "allow ssh access to operator from within vcn"
42-
direction = "INGRESS"
43-
protocol = local.tcp_protocol
44-
source = local.vcn_cidr
45-
source_type = "CIDR_BLOCK"
46-
stateless = false
47-
48-
tcp_options {
49-
destination_port_range {
50-
min = local.ssh_port
51-
max = local.ssh_port
52-
}
53-
}
54-
55-
lifecycle {
56-
ignore_changes = [direction, protocol, source, source_type, tcp_options]
57-
}
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-
}
75-
76-
vcn_id = var.vcn_id
77-
}
1+
# Copyright 2017, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
# operator nsg and rule
5+
resource "oci_core_network_security_group" "operator" {
6+
compartment_id = var.compartment_id
7+
display_name = "${var.label_prefix}-operator"
8+
vcn_id = var.vcn_id
9+
}
10+
11+
resource "oci_core_network_security_group_security_rule" "operator_egress_anywhere" {
12+
network_security_group_id = oci_core_network_security_group.operator.id
13+
description = "allow operator to egress to anywhere"
14+
destination = local.anywhere
15+
destination_type = "CIDR_BLOCK"
16+
direction = "EGRESS"
17+
protocol = local.all_protocols
18+
stateless = false
19+
20+
lifecycle {
21+
ignore_changes = [direction, protocol, source, source_type, tcp_options]
22+
}
23+
}
24+
25+
resource "oci_core_network_security_group_security_rule" "operator_egress_osn" {
26+
network_security_group_id = oci_core_network_security_group.operator.id
27+
description = "allow operator to egress to osn"
28+
destination = local.osn
29+
destination_type = "SERVICE_CIDR_BLOCK"
30+
direction = "EGRESS"
31+
protocol = local.all_protocols
32+
stateless = false
33+
34+
lifecycle {
35+
ignore_changes = [direction, protocol, source, source_type, tcp_options]
36+
}
37+
}
38+
39+
resource "oci_core_network_security_group_security_rule" "operator_ingress" {
40+
network_security_group_id = oci_core_network_security_group.operator.id
41+
description = "allow ssh access to operator from within vcn"
42+
direction = "INGRESS"
43+
protocol = local.tcp_protocol
44+
source = local.vcn_cidr
45+
source_type = "CIDR_BLOCK"
46+
stateless = false
47+
48+
tcp_options {
49+
destination_port_range {
50+
min = local.ssh_port
51+
max = local.ssh_port
52+
}
53+
}
54+
55+
lifecycle {
56+
ignore_changes = [direction, protocol, source, source_type, tcp_options]
57+
}
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+
}
75+
76+
vcn_id = var.vcn_id
77+
}

terraform.tfvars.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ freeform_tags = {
3030
role = "operator"
3131
}
3232

33+
operating_system_version = "8"
34+
3335
operator_image_id = "Oracle"
3436

3537
operator_instance_principal = true

0 commit comments

Comments
 (0)