Skip to content

Commit ad165fa

Browse files
committed
feat: add reserved IP support
var.assign_public_ip becomes deprecated var.public_ip and var.public_ip_display_name are added to control this new resource var.public_ip accept a string with value NONE, RESERVED or EPHEMERAL. each keyword does what it says. fix #55
1 parent 2b814a1 commit ad165fa

File tree

8 files changed

+68
-43
lines changed

8 files changed

+68
-43
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Given a version number MAJOR.MINOR.PATCH:
1919
=== Deprecated
2020

2121
* `var.ssh_authorized_keys` is deprecated. Use `var.ssh_public_keys`.
22+
* `var.assign_public_ip` is deprecated. Use `var.public_ip` with the predefined keywords instead.
2223

2324
=== New features
2425

docs/terraformoptions.adoc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ No modules.
2525
|===
2626
|Name |Type
2727
|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
2829
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume[oci_core_volume.this] |resource
2930
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume_attachment[oci_core_volume_attachment.this] |resource
3031
|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
3133
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_shapes[oci_core_shapes.ad1] |data source
3234
|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
3336
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_availability_domains[oci_identity_availability_domains.ad] |data source
3437
|===
3538

@@ -45,7 +48,7 @@ No modules.
4548
|no
4649

4750
|[[input_assign_public_ip]] <<input_assign_public_ip,assign_public_ip>>
48-
|Whether the VNIC should be assigned a public IP address.
51+
|Deprecated: use `var.public_ip` instead. Whether the VNIC should be assigned a public IP address (Always EPHEMERAL).
4952
|`bool`
5053
|`false`
5154
|no
@@ -146,6 +149,18 @@ No modules.
146149
|`[]`
147150
|no
148151

152+
|[[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.
154+
|`string`
155+
|`"NONE"`
156+
|no
157+
158+
|[[input_public_ip_display_name]] <<input_public_ip_display_name,public_ip_display_name>>
159+
|(Updatable) A user-friendly name. Does not have to be unique, and it's changeable.
160+
|`string`
161+
|`null`
162+
|no
163+
149164
|[[input_resource_platform]] <<input_resource_platform,resource_platform>>
150165
|Platform to create resources in.
151166
|`string`
@@ -219,10 +234,16 @@ No modules.
219234
[cols="a,a",options="header,autowidth"]
220235
|===
221236
|Name |Description
237+
|[[output_instance_all_attributes]] <<output_instance_all_attributes,instance_all_attributes>> |all attributes of created instance
222238
|[[output_instance_id]] <<output_instance_id,instance_id>> |ocid of created instances.
223239
|[[output_instance_password]] <<output_instance_password,instance_password>> |Passwords to login to Windows instance.
224240
|[[output_instance_username]] <<output_instance_username,instance_username>> |Usernames to login to Windows instance.
225241
|[[output_instances_summary]] <<output_instances_summary,instances_summary>> |Private and Public IPs for each instance.
226242
|[[output_private_ip]] <<output_private_ip,private_ip>> |Private IPs of created instances.
243+
|[[output_private_ips_all_attributes]] <<output_private_ips_all_attributes,private_ips_all_attributes>> |all attributes of created private ips
227244
|[[output_public_ip]] <<output_public_ip,public_ip>> |Public IPs of created instances.
245+
|[[output_public_ip_all_attributes]] <<output_public_ip_all_attributes,public_ip_all_attributes>> |all attributes of created public ip
246+
|[[output_vnic_attachment_all_attributes]] <<output_vnic_attachment_all_attributes,vnic_attachment_all_attributes>> |all attributes of created vnic attachments
247+
|[[output_volume_all_attributes]] <<output_volume_all_attributes,volume_all_attributes>> |all attributes of created volumes
248+
|[[output_volume_attachment_all_attributes]] <<output_volume_attachment_all_attributes,volume_attachment_all_attributes>> |all attributes of created volumes attachments
228249
|===

examples/instances_reserved_public_ip/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This example illustrates how to use this module to creates compute instances wit
44

55
One modules will be configured:
66

7-
- 1 instance (1 OCPU, 1GB RAM) with a reserved public IP attached the primary VNIC.
7+
- 1 instance (1 OCPU, 1GB RAM) with a reserved public IP associated with the Primary IP of the primary VNIC.
88

99
## Prerequisites
1010

examples/instances_reserved_public_ip/main.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ module "instance_reserved_ip" {
3737
# operating system parameters
3838
ssh_authorized_keys = var.ssh_authorized_keys
3939
# networking parameters
40-
assign_public_ip = var.assign_public_ip
41-
public_ip = var.public_ip
42-
subnet_ocids = var.subnet_ocids
40+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
41+
subnet_ocids = var.subnet_ocids
4342
# storage parameters
4443
block_storage_sizes_in_gbs = [] # no block volume will be created
4544
preserve_boot_volume = false
4645
}
4746

4847
output "instance_reserved_ip" {
49-
description = "ocid of created instances."
48+
description = "IP information of the instances provisioned by this module."
5049
value = module.instance_reserved_ip.instances_summary
5150
}

examples/instances_reserved_public_ip/variables.tf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,10 @@ variable "ssh_authorized_keys" {
111111

112112
# networking parameters
113113

114-
variable "assign_public_ip" {
115-
description = "Whether the VNIC should be assigned a public IP address."
116-
type = bool
117-
default = false
118-
}
119-
120114
variable "public_ip" {
121115
description = "OCID of the Public IP to attach to primary vnic."
122116
type = string
123-
default = null
117+
default = "NONE"
124118
}
125119

126120
variable "subnet_ocids" {

main.tf

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,34 +148,33 @@ resource "oci_core_volume_attachment" "this" {
148148
####################
149149

150150
data "oci_core_vnic_attachments" "this" {
151-
#Required
151+
count = var.instance_count
152152
compartment_id = var.compartment_ocid
153-
154-
#Optional
155-
instance_id = oci_core_instance.this[0].id
153+
instance_id = oci_core_instance.this[count.index].id
156154

157155
depends_on = [
158156
oci_core_instance.this
159157
]
160158
}
161159

162160
data "oci_core_private_ips" "this" {
163-
vnic_id = data.oci_core_vnic_attachments.this.vnic_attachments[0].vnic_id
161+
count = var.instance_count
162+
vnic_id = data.oci_core_vnic_attachments.this[count.index].vnic_attachments[0].vnic_id
164163

165164
depends_on = [
166-
oci_core_instance.this
167-
]
165+
oci_core_instance.this
166+
]
168167
}
169168

170-
# resource "oci_core_public_ip" "this" {
171-
# count = (var.assign_public_ip == true && var.public_ip == true) ? 1 : 0
172-
# compartment_id = var.compartment_ocid
173-
# lifetime = "RESERVED"
169+
resource "oci_core_public_ip" "this" {
170+
count = var.public_ip == "NONE" ? 0 : var.instance_count
171+
compartment_id = var.compartment_ocid
172+
lifetime = var.public_ip
174173

175-
# # display_name = var.public_ip_display_name
176-
# private_ip_id = data.oci_core_private_ips.this.private_ips[0].id
177-
# # public_ip_pool_id = oci_core_public_ip_pool.test_public_ip_pool.id
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
176+
# public_ip_pool_id = oci_core_public_ip_pool.test_public_ip_pool.id # * (BYOIP CIDR Blocks) are not supported yet by this module.
178177

179-
# freeform_tags = local.merged_freeform_tags
180-
# defined_tags = var.defined_tags
181-
# }
178+
freeform_tags = local.merged_freeform_tags
179+
defined_tags = var.defined_tags
180+
}

outputs.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ output "instance_all_attributes" {
5050
value = { for k, v in oci_core_instance.this : k => v }
5151
}
5252

53-
# output "public_ip_all_attributes" {
54-
# description = "all attributes of created instance"
55-
# value = { for k, v in oci_core_public_ip.this : k => v }
56-
# }
57-
58-
output "vnic_attachment_all_attributes" {
59-
description = "all attributes of created vnic attachments"
60-
value = { for k, v in data.oci_core_vnic_attachments.this : k => v }
53+
output "public_ip_all_attributes" {
54+
description = "all attributes of created public ip"
55+
value = { for k, v in oci_core_public_ip.this : k => v }
6156
}
6257

6358
output "private_ips_all_attributes" {
6459
description = "all attributes of created private ips"
6560
value = { for k, v in data.oci_core_private_ips.this : k => v }
6661
}
6762

63+
output "vnic_attachment_all_attributes" {
64+
description = "all attributes of created vnic attachments"
65+
value = { for k, v in data.oci_core_vnic_attachments.this : k => v }
66+
}
67+
6868
output "volume_all_attributes" {
6969
description = "all attributes of created volumes"
7070
value = { for k, v in oci_core_volume.this : k => v }

variables.tf

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ variable "user_data" {
126126
# networking parameters
127127

128128
variable "assign_public_ip" {
129-
#! Deprecation notice: will be removed at next major release. Use "create_public_ip" instead.
130-
description = "Whether the VNIC should be assigned a public IP address."
129+
#! Deprecation notice: will be removed at next major release. Use `var.public_ip` instead.
130+
description = "Deprecated: use `var.public_ip` instead. Whether the VNIC should be assigned a public IP address (Always EPHEMERAL)."
131131
type = bool
132132
default = false
133133
}
@@ -151,9 +151,20 @@ variable "private_ips" {
151151
}
152152

153153
variable "public_ip" {
154-
description = "OCID of the Public IP to attach to primary vnic."
155-
type = string
156-
default = null
154+
description = "OCID of the Public IP to attach to primary vnic. Valid values are NONE, RESERVED or EPHEMERAL."
155+
type = string
156+
default = "NONE"
157+
158+
validation {
159+
condition = contains(["NONE", "RESERVED", "EPHEMERAL"], var.public_ip)
160+
error_message = "Accepted values are NONE, RESERVED or EPHEMERAL."
161+
}
162+
}
163+
164+
variable "public_ip_display_name" {
165+
description = "(Updatable) A user-friendly name. Does not have to be unique, and it's changeable."
166+
type = string
167+
default = null
157168
}
158169

159170
variable "skip_source_dest_check" {

0 commit comments

Comments
 (0)