Skip to content

Commit 473e1e5

Browse files
committed
fix(reserved IP): add feedback from PR#71 review
- fix assign_public_ip test condition - rename terraform resources from <this> to more meaningful name
1 parent ad165fa commit 473e1e5

File tree

11 files changed

+64
-59
lines changed

11 files changed

+64
-59
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Given a version number MAJOR.MINOR.PATCH:
2626
* Add support for freeform and defined tags for instances, vnics and block volumes (Fix #10, #11, #12, #13, #18, #20)
2727
* Add "module watermark" freeform tags: module defined and user defined freeform tags are merged on the final resource
2828
* Add support to provide the `ssh_authorized_keys` argument as a string or as a file (Fix #67 #70)
29-
* Provision instances with reserved Public IP
30-
* [ ] Define a backup policy for boot volume and additional block volumes
29+
* Add support for reserved Public IP on instance first VNIC (fix #55)
30+
* [ ] Define a backup policy for boot volume and additional block volumes (fix #64)
3131
* Add new outputs for each provisioned resources: "all_attributes" outputs have full provider coverage and are auto-updating.
3232

3333
=== Documentation

docs/terraformoptions.adoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ No modules.
2424
[cols="a,a",options="header,autowidth"]
2525
|===
2626
|Name |Type
27-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_instance[oci_core_instance.this] |resource
28-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_public_ip[oci_core_public_ip.this] |resource
29-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume[oci_core_volume.this] |resource
30-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume_attachment[oci_core_volume_attachment.this] |resource
31-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_instance_credentials[oci_core_instance_credentials.this] |data source
32-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_private_ips[oci_core_private_ips.this] |data source
27+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_instance[oci_core_instance.instance] |resource
28+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_public_ip[oci_core_public_ip.public_ip] |resource
29+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume[oci_core_volume.volume] |resource
30+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume_attachment[oci_core_volume_attachment.volume_attachment] |resource
31+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_instance_credentials[oci_core_instance_credentials.crendential] |data source
32+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_private_ips[oci_core_private_ips.private_ips] |data source
3333
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_shapes[oci_core_shapes.ad1] |data source
34-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_subnet[oci_core_subnet.this] |data source
35-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_vnic_attachments[oci_core_vnic_attachments.this] |data source
34+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_subnet[oci_core_subnet.instance_subnet] |data source
35+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_vnic_attachments[oci_core_vnic_attachments.vnic_attachment] |data source
3636
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_availability_domains[oci_identity_availability_domains.ad] |data source
3737
|===
3838

@@ -150,7 +150,7 @@ No modules.
150150
|no
151151

152152
|[[input_public_ip]] <<input_public_ip,public_ip>>
153-
|OCID of the Public IP to attach to primary vnic. Valid values are NONE, RESERVED or EPHEMERAL.
153+
|Whether to create a Public IP to attach to primary vnic and wwhich lifetime. Valid values are NONE, RESERVED or EPHEMERAL.
154154
|`string`
155155
|`"NONE"`
156156
|no

examples/instances_fixed_shape/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ module "instance_nonflex" {
3434
# operating system parameters
3535
ssh_public_keys = var.ssh_public_keys
3636
# networking parameters
37-
assign_public_ip = var.assign_public_ip
38-
subnet_ocids = var.subnet_ocids
37+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
38+
subnet_ocids = var.subnet_ocids
3939
# storage parameters
4040
block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs
4141
}
@@ -65,8 +65,8 @@ module "instance_nonflex_custom" {
6565
# operating system parameters
6666
ssh_public_keys = var.ssh_public_keys
6767
# networking parameters
68-
assign_public_ip = var.assign_public_ip
69-
subnet_ocids = var.subnet_ocids
68+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
69+
subnet_ocids = var.subnet_ocids
7070
# storage parameters
7171
block_storage_sizes_in_gbs = [] # no block volume will be created
7272
}

examples/instances_fixed_shape/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ variable "assign_public_ip" {
118118
default = false
119119
}
120120

121+
variable "public_ip" {
122+
description = "Whether to create a Public IP to attach to primary vnic and wwhich lifetime. Valid values are NONE, RESERVED or EPHEMERAL."
123+
type = string
124+
default = "NONE"
125+
}
126+
121127
variable "subnet_ocids" {
122128
description = "The unique identifiers (OCIDs) of the subnets in which the instance primary VNICs are created."
123129
type = list(string)

examples/instances_flex_shape/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ module "instance_flex" {
3737
# operating system parameters
3838
ssh_public_keys = var.ssh_public_keys
3939
# networking parameters
40-
assign_public_ip = var.assign_public_ip
41-
subnet_ocids = var.subnet_ocids
40+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
41+
subnet_ocids = var.subnet_ocids
4242
# storage parameters
4343
block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs
4444
}
@@ -67,7 +67,7 @@ output "instance_flex" {
6767
# # operating system parameters
6868
# ssh_public_key = var.ssh_public_key
6969
# # networking parameters
70-
# assign_public_ip = var.assign_public_ip
70+
# public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
7171
# subnet_ocids = var.subnet_ocids
7272
# # storage parameters
7373
# block_storage_sizes_in_gbs = [] # no block volume will be created

examples/instances_flex_shape/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ variable "ssh_public_keys" {
119119

120120
# networking parameters
121121

122-
variable "assign_public_ip" {
123-
description = "Whether the VNIC should be assigned a public IP address."
124-
type = bool
125-
default = false
122+
variable "public_ip" {
123+
description = "Whether to create a Public IP to attach to primary vnic and wwhich lifetime. Valid values are NONE, RESERVED or EPHEMERAL."
124+
type = string
125+
default = "NONE"
126126
}
127127

128128
variable "subnet_ocids" {

examples/instances_reserved_public_ip/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ provider "oci" {
1919

2020
# # * This module will create 1 Flex Compute Instances, with a reserved public IP
2121
module "instance_reserved_ip" {
22-
source = "../../"
23-
# source = "oracle-terraform-modules/compute-instance/oci"
22+
source = "oracle-terraform-modules/compute-instance/oci"
2423
# general oci parameters
2524
compartment_ocid = var.compartment_ocid
2625
freeform_tags = var.freeform_tags

examples/instances_reserved_public_ip/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ variable "ssh_authorized_keys" {
112112
# networking parameters
113113

114114
variable "public_ip" {
115-
description = "OCID of the Public IP to attach to primary vnic."
115+
description = "Whether to create a Public IP to attach to primary vnic and wwhich lifetime. Valid values are NONE, RESERVED or EPHEMERAL."
116116
type = string
117117
default = "NONE"
118118
}

main.tf

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ locals {
2424
####################
2525
# Subnet Datasource
2626
####################
27-
data "oci_core_subnet" "this" {
27+
data "oci_core_subnet" "instance_subnet" {
2828
count = length(var.subnet_ocids)
2929
subnet_id = element(var.subnet_ocids, count.index)
3030
}
@@ -56,7 +56,7 @@ locals {
5656
############
5757
# Instance
5858
############
59-
resource "oci_core_instance" "this" {
59+
resource "oci_core_instance" "instance" {
6060
count = var.instance_count
6161
// If no explicit AD number, spread instances on all ADs in round-robin. Looping to the first when last AD is reached
6262
availability_domain = var.ad_number == null ? element(local.ADs, count.index) : element(local.ADs, var.ad_number - 1)
@@ -74,7 +74,7 @@ resource "oci_core_instance" "this" {
7474
}
7575

7676
create_vnic_details {
77-
assign_public_ip = var.public_ip == null ? var.assign_public_ip : false
77+
assign_public_ip = var.public_ip == "NONE" ? var.assign_public_ip : false
7878
display_name = var.vnic_name == "" ? "" : var.instance_count != "1" ? "${var.vnic_name}_${count.index + 1}" : var.vnic_name
7979
hostname_label = var.hostname_label == "" ? "" : var.instance_count != "1" ? "${var.hostname_label}-${count.index + 1}" : var.hostname_label
8080
private_ip = element(
@@ -83,7 +83,7 @@ resource "oci_core_instance" "this" {
8383
)
8484
skip_source_dest_check = var.skip_source_dest_check
8585
// Current implementation requires providing a list of subnets when using ad-specific subnets
86-
subnet_id = data.oci_core_subnet.this[count.index % length(data.oci_core_subnet.this.*.id)].id
86+
subnet_id = data.oci_core_subnet.instance_subnet[count.index % length(data.oci_core_subnet.instance_subnet.*.id)].id
8787

8888
freeform_tags = local.merged_freeform_tags
8989
defined_tags = var.defined_tags
@@ -111,19 +111,19 @@ resource "oci_core_instance" "this" {
111111
##################################
112112
# Instance Credentials Datasource
113113
##################################
114-
data "oci_core_instance_credentials" "this" {
114+
data "oci_core_instance_credentials" "crendential" {
115115
count = var.resource_platform != "linux" ? var.instance_count : 0
116-
instance_id = oci_core_instance.this[count.index].id
116+
instance_id = oci_core_instance.instance[count.index].id
117117
}
118118

119119
#########
120120
# Volume
121121
#########
122-
resource "oci_core_volume" "this" {
122+
resource "oci_core_volume" "volume" {
123123
count = var.instance_count * length(var.block_storage_sizes_in_gbs)
124-
availability_domain = oci_core_instance.this[count.index % var.instance_count].availability_domain
124+
availability_domain = oci_core_instance.instance[count.index % var.instance_count].availability_domain
125125
compartment_id = var.compartment_ocid
126-
display_name = "${oci_core_instance.this[count.index % var.instance_count].display_name}_volume${floor(count.index / var.instance_count)}"
126+
display_name = "${oci_core_instance.instance[count.index % var.instance_count].display_name}_volume${floor(count.index / var.instance_count)}"
127127
size_in_gbs = element(
128128
var.block_storage_sizes_in_gbs,
129129
floor(count.index / var.instance_count),
@@ -135,44 +135,44 @@ resource "oci_core_volume" "this" {
135135
####################
136136
# Volume Attachment
137137
####################
138-
resource "oci_core_volume_attachment" "this" {
138+
resource "oci_core_volume_attachment" "volume_attachment" {
139139
count = var.instance_count * length(var.block_storage_sizes_in_gbs)
140140
attachment_type = var.attachment_type
141-
instance_id = oci_core_instance.this[count.index % var.instance_count].id
142-
volume_id = oci_core_volume.this[count.index].id
141+
instance_id = oci_core_instance.instance[count.index % var.instance_count].id
142+
volume_id = oci_core_volume.volume[count.index].id
143143
use_chap = var.use_chap
144144
}
145145

146146
####################
147147
# Networking
148148
####################
149149

150-
data "oci_core_vnic_attachments" "this" {
150+
data "oci_core_vnic_attachments" "vnic_attachment" {
151151
count = var.instance_count
152152
compartment_id = var.compartment_ocid
153-
instance_id = oci_core_instance.this[count.index].id
153+
instance_id = oci_core_instance.instance[count.index].id
154154

155155
depends_on = [
156-
oci_core_instance.this
156+
oci_core_instance.instance
157157
]
158158
}
159159

160-
data "oci_core_private_ips" "this" {
160+
data "oci_core_private_ips" "private_ips" {
161161
count = var.instance_count
162-
vnic_id = data.oci_core_vnic_attachments.this[count.index].vnic_attachments[0].vnic_id
162+
vnic_id = data.oci_core_vnic_attachments.vnic_attachment[count.index].vnic_attachments[0].vnic_id
163163

164164
depends_on = [
165-
oci_core_instance.this
165+
oci_core_instance.instance
166166
]
167167
}
168168

169-
resource "oci_core_public_ip" "this" {
169+
resource "oci_core_public_ip" "public_ip" {
170170
count = var.public_ip == "NONE" ? 0 : var.instance_count
171171
compartment_id = var.compartment_ocid
172172
lifetime = var.public_ip
173173

174-
display_name = var.public_ip_display_name != null ? var.public_ip_display_name : oci_core_instance.this[count.index].display_name
175-
private_ip_id = data.oci_core_private_ips.this[count.index].private_ips[0].id
174+
display_name = var.public_ip_display_name != null ? var.public_ip_display_name : oci_core_instance.instance[count.index].display_name
175+
private_ip_id = data.oci_core_private_ips.private_ips[count.index].private_ips[0].id
176176
# public_ip_pool_id = oci_core_public_ip_pool.test_public_ip_pool.id # * (BYOIP CIDR Blocks) are not supported yet by this module.
177177

178178
freeform_tags = local.merged_freeform_tags

outputs.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
locals {
44
instances_details = [
55
// display name, Primary VNIC Public/Private IP for each instance
6-
for i in oci_core_instance.this : <<EOT
6+
for i in oci_core_instance.instance : <<EOT
77
${~i.display_name~}
88
Primary-PublicIP: %{if i.public_ip != ""}${i.public_ip~}%{else}N/A%{endif~}
99
Primary-PrivateIP: ${i.private_ip~}
@@ -18,59 +18,59 @@ output "instances_summary" {
1818

1919
output "instance_id" {
2020
description = "ocid of created instances. "
21-
value = oci_core_instance.this.*.id
21+
value = oci_core_instance.instance.*.id
2222
}
2323

2424
output "private_ip" {
2525
description = "Private IPs of created instances. "
26-
value = oci_core_instance.this.*.private_ip
26+
value = oci_core_instance.instance.*.private_ip
2727
}
2828

2929
output "public_ip" {
3030
description = "Public IPs of created instances. "
31-
value = oci_core_instance.this.*.public_ip
31+
value = oci_core_instance.instance.*.public_ip
3232
}
3333

3434
output "instance_username" {
3535
description = "Usernames to login to Windows instance. "
36-
value = data.oci_core_instance_credentials.this.*.username
36+
value = data.oci_core_instance_credentials.crendential.*.username
3737
}
3838

3939
output "instance_password" {
4040
description = "Passwords to login to Windows instance. "
4141
sensitive = true
42-
value = data.oci_core_instance_credentials.this.*.password
42+
value = data.oci_core_instance_credentials.crendential.*.password
4343
}
4444

4545
# New complete outputs for each resources with provider parity. Auto-updating.
4646
# Usefull for module composition.
4747

4848
output "instance_all_attributes" {
4949
description = "all attributes of created instance"
50-
value = { for k, v in oci_core_instance.this : k => v }
50+
value = { for k, v in oci_core_instance.instance : k => v }
5151
}
5252

5353
output "public_ip_all_attributes" {
5454
description = "all attributes of created public ip"
55-
value = { for k, v in oci_core_public_ip.this : k => v }
55+
value = { for k, v in oci_core_public_ip.public_ip : k => v }
5656
}
5757

5858
output "private_ips_all_attributes" {
5959
description = "all attributes of created private ips"
60-
value = { for k, v in data.oci_core_private_ips.this : k => v }
60+
value = { for k, v in data.oci_core_private_ips.private_ips : k => v }
6161
}
6262

6363
output "vnic_attachment_all_attributes" {
6464
description = "all attributes of created vnic attachments"
65-
value = { for k, v in data.oci_core_vnic_attachments.this : k => v }
65+
value = { for k, v in data.oci_core_vnic_attachments.vnic_attachment : k => v }
6666
}
6767

6868
output "volume_all_attributes" {
6969
description = "all attributes of created volumes"
70-
value = { for k, v in oci_core_volume.this : k => v }
70+
value = { for k, v in oci_core_volume.volume : k => v }
7171
}
7272

7373
output "volume_attachment_all_attributes" {
7474
description = "all attributes of created volumes attachments"
75-
value = { for k, v in oci_core_volume_attachment.this : k => v }
75+
value = { for k, v in oci_core_volume_attachment.volume_attachment : k => v }
7676
}

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ variable "private_ips" {
151151
}
152152

153153
variable "public_ip" {
154-
description = "OCID of the Public IP to attach to primary vnic. Valid values are NONE, RESERVED or EPHEMERAL."
154+
description = "Whether to create a Public IP to attach to primary vnic and wwhich lifetime. Valid values are NONE, RESERVED or EPHEMERAL."
155155
type = string
156156
default = "NONE"
157157

0 commit comments

Comments
 (0)