Skip to content

Commit 80b3370

Browse files
authored
feat: add support for Network Security Groups (#83)
Examples also provision their own networking environment Fix #81
1 parent 4246d37 commit 80b3370

File tree

11 files changed

+113
-27
lines changed

11 files changed

+113
-27
lines changed

CHANGELOG.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Given a version number MAJOR.MINOR.PATCH:
1414
* MINOR version when adding functionality in a backwards compatible manner,
1515
* PATCH version when making backwards compatible bug fixes.
1616
17+
== 2.3.0 - 2021-11-12
18+
19+
=== New features
20+
21+
* Add support for instance_state: the provisionned instance state can be RUNNING or STOPPED
22+
* Add support for NSG: option to attach an NSG to the first VNIC
23+
1724
== 2.2.0 - 2021-09-27
1825

1926
=== Deprecated

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The current focus is to close the gap between this module and the provider's cap
6565

6666
We will continue to push in that direction with the goal of [feature parity with the provider's capabilities](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/projects/4), as well as adding more features and integration points with other OCI services: Block Volume Backups, Secondary VNICs and IPs, etc ...
6767

68-
Given the dependency to Network and Storage for Compute Instances, it is a perfect place to illustrate [module composition principles](https://www.terraform.io/docs/language/modules/develop/composition.html) and how to reuse the other official Terraform OCI modules.
68+
Given the dependency to Network and Storage for Compute Instances, this module is also a perfect place to illustrate [module composition principles](https://www.terraform.io/docs/language/modules/develop/composition.html) and how to reuse the other official Terraform OCI modules.
6969

7070
## Contributing
7171

docs/terraformoptions.adoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// BEGIN_TF_DOCS
21

32
== Requirements
43

@@ -13,7 +12,7 @@
1312
[cols="a,a",options="header,autowidth"]
1413
|===
1514
|Name |Version
16-
|[[provider_oci]] <<provider_oci,oci>> |4.17.0
15+
|[[provider_oci]] <<provider_oci,oci>> |>= 3.27
1716
|===
1817
== Resources
1918

@@ -152,6 +151,12 @@
152151
|`false`
153152
|no
154153

154+
|[[input_primary_vnic_nsg_ids]] <<input_primary_vnic_nsg_ids,primary_vnic_nsg_ids>>
155+
|A list of the OCIDs of the network security groups (NSGs) to add the primary VNIC to
156+
|`list(string)`
157+
|`null`
158+
|no
159+
155160
|[[input_private_ips]] <<input_private_ips,private_ips>>
156161
|Private IP addresses of your choice to assign to the VNICs.
157162
|`list(string)`
@@ -255,5 +260,3 @@
255260
|[[output_volume_all_attributes]] <<output_volume_all_attributes,volume_all_attributes>> |all attributes of created volumes
256261
|[[output_volume_attachment_all_attributes]] <<output_volume_attachment_all_attributes,volume_attachment_all_attributes>> |all attributes of created volumes attachments
257262
|===
258-
259-
// END_TF_DOCS

examples/instances_fixed_shape/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Creating Compute Instances using fixed shape
22

3-
This example illustrates how to use this module to creates compute instances using Fixed Shape, and optionally provision and attach a block volume to the created instances.
3+
This example illustrates how to use this module to creates compute instances using Fixed Shape with all the related networking, and optionally provision and attach a block volume to the created instances.
44

5-
Two modules will be configured:
5+
Two compute-instance modules will be configured:
66

77
- the first module will create 1 instance (shape VM.Standard2.1) with 1 Block Volume (50GB) attached to it
88
- the second module will create 1 instances (shape VM.Standard2.1) with no additional Block Volume
99

10+
Networking to house theses instances will also be created:
11+
12+
- one VCN using the [VCN module](https://registry.terraform.io/modules/oracle-terraform-modules/vcn/oci/latest) from Terraform Registry
13+
- one subnet
14+
- on Network Security Group
15+
1016
## Prerequisites
1117

1218
You will need to collect the following information before you start:

examples/instances_fixed_shape/main.tf

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ module "instance_nonflex" {
3535
# operating system parameters
3636
ssh_public_keys = var.ssh_public_keys
3737
# networking parameters
38-
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
39-
subnet_ocids = var.subnet_ocids
38+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
39+
subnet_ocids = [oci_core_subnet.example_sub.id]
40+
primary_vnic_nsg_ids = null
4041
# storage parameters
4142
boot_volume_backup_policy = var.boot_volume_backup_policy
4243
block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs
@@ -68,8 +69,9 @@ module "instance_nonflex_custom" {
6869
# operating system parameters
6970
ssh_public_keys = var.ssh_public_keys
7071
# networking parameters
71-
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
72-
subnet_ocids = var.subnet_ocids
72+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
73+
subnet_ocids = [oci_core_subnet.example_sub.id]
74+
primary_vnic_nsg_ids = [oci_core_network_security_group.example_nsg.id]
7375
# storage parameters
7476
boot_volume_backup_policy = var.boot_volume_backup_policy
7577
block_storage_sizes_in_gbs = [] # no block volume will be created
@@ -79,3 +81,35 @@ output "instance_nonflex_custom" {
7981
description = "ocid of created instances."
8082
value = module.instance_nonflex_custom.instances_summary
8183
}
84+
85+
module "example_vcn" {
86+
source = "oracle-terraform-modules/vcn/oci"
87+
88+
# general oci parameters
89+
compartment_id = var.compartment_ocid
90+
91+
# vcn parameters
92+
lockdown_default_seclist = false # boolean: true or false
93+
}
94+
95+
resource "oci_core_network_security_group" "example_nsg" {
96+
#Required
97+
compartment_id = var.compartment_ocid
98+
vcn_id = module.example_vcn.vcn_id
99+
100+
#Optional
101+
display_name = "NSG_example"
102+
freeform_tags = var.freeform_tags
103+
}
104+
105+
resource "oci_core_subnet" "example_sub" {
106+
#Required
107+
cidr_block = "10.0.0.0/24"
108+
compartment_id = var.compartment_ocid
109+
vcn_id = module.example_vcn.vcn_id
110+
111+
#Optional
112+
display_name = "example-sub"
113+
dns_label = "example"
114+
prohibit_public_ip_on_vnic = true
115+
}

examples/instances_fixed_shape/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ variable "public_ip" {
135135
default = "NONE"
136136
}
137137

138-
variable "subnet_ocids" {
139-
description = "The unique identifiers (OCIDs) of the subnets in which the instance primary VNICs are created."
140-
type = list(string)
141-
}
142-
143138
# storage parameters
144139

145140
variable "boot_volume_backup_policy" {

examples/instances_flex_shape/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Creating Compute Instances using Flex shape
22

3-
This example illustrates how to use this module to creates compute instances using Flex Shape, and optionally provision and attach a block volume to the created instances.
3+
This example illustrates how to use this module to creates compute instances using Flex Shape with all the related networking, and optionally provision and attach a block volume to the created instances.
44

5-
Two modules will be configured:
5+
Two compute-instance modules will be configured:
66

77
- the first module will create 1 instance (1 OCPU, 16GB RAM) with 1 Block Volume (50GB) attached to it
88
- the second module, if uncommented, will create 4 instances (1 OCUP, 1GB RAM) with no additional Block Volume
99

10+
Networking to house theses instances will also be created:
11+
12+
- one VCN using the [VCN module](https://registry.terraform.io/modules/oracle-terraform-modules/vcn/oci/latest) from Terraform Registry
13+
- one subnet
14+
- on Network Security Group
15+
1016
## Prerequisites
1117

1218
You will need to collect the following information before you start:

examples/instances_flex_shape/main.tf

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ module "instance_flex" {
3333
shape = var.shape
3434
source_ocid = var.source_ocid
3535
source_type = var.source_type
36-
instance_flex_memory_in_gbs = 1 # only used if shape is Flex type
37-
instance_flex_ocpus = 1 # only used if shape is Flex type
36+
instance_flex_memory_in_gbs = var.instance_flex_memory_in_gbs # only used if shape is Flex type
37+
instance_flex_ocpus = 1 # only used if shape is Flex type
3838
# operating system parameters
3939
ssh_public_keys = var.ssh_public_keys
4040
# networking parameters
41-
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
42-
subnet_ocids = var.subnet_ocids
41+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
42+
subnet_ocids = [oci_core_subnet.example_sub.id]
43+
primary_vnic_nsg_ids = [oci_core_network_security_group.example_nsg.id]
4344
# storage parameters
4445
boot_volume_backup_policy = var.boot_volume_backup_policy
4546
block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs
@@ -50,6 +51,38 @@ output "instance_flex" {
5051
value = module.instance_flex.instances_summary
5152
}
5253

54+
module "example_vcn" {
55+
source = "oracle-terraform-modules/vcn/oci"
56+
57+
# general oci parameters
58+
compartment_id = var.compartment_ocid
59+
60+
# vcn parameters
61+
lockdown_default_seclist = false # boolean: true or false
62+
}
63+
64+
resource "oci_core_network_security_group" "example_nsg" {
65+
#Required
66+
compartment_id = var.compartment_ocid
67+
vcn_id = module.example_vcn.vcn_id
68+
69+
#Optional
70+
display_name = "NSG_example"
71+
freeform_tags = var.freeform_tags
72+
}
73+
74+
resource "oci_core_subnet" "example_sub" {
75+
#Required
76+
cidr_block = "10.0.0.0/24"
77+
compartment_id = var.compartment_ocid
78+
vcn_id = module.example_vcn.vcn_id
79+
80+
#Optional
81+
display_name = "example-sub"
82+
dns_label = "example"
83+
prohibit_public_ip_on_vnic = true
84+
}
85+
5386
# # # * This module will create 4 Flex Compute Instances, using values provided to the module: 1 OCPU, 1 GB memory.
5487
# module "instance_flex_custom" {
5588
# source = "oracle-terraform-modules/compute-instance/oci"

examples/instances_flex_shape/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ variable "public_ip" {
136136
default = "NONE"
137137
}
138138

139-
variable "subnet_ocids" {
140-
description = "The unique identifiers (OCIDs) of the subnets in which the instance primary VNICs are created."
141-
type = list(string)
142-
}
143-
144139
# storage parameters
145140

146141
variable "boot_volume_backup_policy" {

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ resource "oci_core_instance" "instance" {
9393
skip_source_dest_check = var.skip_source_dest_check
9494
// Current implementation requires providing a list of subnets when using ad-specific subnets
9595
subnet_id = data.oci_core_subnet.instance_subnet[count.index % length(data.oci_core_subnet.instance_subnet.*.id)].id
96+
nsg_ids = var.primary_vnic_nsg_ids
9697

9798
freeform_tags = local.merged_freeform_tags
9899
defined_tags = var.defined_tags

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ variable "vnic_name" {
196196
default = ""
197197
}
198198

199+
variable "primary_vnic_nsg_ids" {
200+
description = "A list of the OCIDs of the network security groups (NSGs) to add the primary VNIC to"
201+
type = list(string)
202+
default = null
203+
}
204+
199205
# storage parameters
200206

201207
variable "attachment_type" {

0 commit comments

Comments
 (0)