Skip to content

Commit 5b0c5c4

Browse files
authored
feat: add reserved public ip (#71)
- var.public_ip and var.public_ip_display_name are added to control this new feature - var.public_ip accept a string with value NONE, RESERVED or EPHEMERAL. each keyword does what it says. - var.assign_public_ip becomes deprecated - rename terraform resources from <this> to more meaningful name fix #55
1 parent bad0668 commit 5b0c5c4

File tree

16 files changed

+426
-54
lines changed

16 files changed

+426
-54
lines changed

CHANGELOG.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ 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

2526
* Add support for freeform and defined tags for instances, vnics and block volumes (Fix #10, #11, #12, #13, #18, #20)
2627
* Add "module watermark" freeform tags: module defined and user defined freeform tags are merged on the final resource
2728
* Add support to provide the `ssh_authorized_keys` argument as a string or as a file (Fix #67 #70)
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)
31+
* Add new outputs for each provisioned resources: "all_attributes" outputs have full provider coverage and are auto-updating.
2832

2933
=== Documentation
3034

@@ -47,7 +51,6 @@ Given a version number MAJOR.MINOR.PATCH:
4751
* Outputs produces unnecessarily multidimensional objects (Issue #31)
4852
* Repo maintenance:
4953
** add .gitattributes for consistent line ending and tab
50-
** add pre-commit configuration file
5154

5255
== 2.0.4 - 2021-02-13
5356

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Oracle Cloud Infrastructure Terraform Module for Compute Instance
22

3-
This Module provides an easy way to launch compute instances with advanced settings and good practices embedded.
3+
This module provides an easy way to launch compute instances with advanced settings and good practices embedded.
44

55
On top of the compute instance capabilities, this module can also provision and attach additional Block Volumes to the instances.
66

@@ -10,24 +10,20 @@ On top of the compute instance capabilities, this module can also provision and
1010
>
1111
> Oracle recommends that you do not use custom images without these rules unless you understand the security risks. See [Compute Best Practices](https://docs.cloud.oracle.com/iaas/Content/Compute/References/bestpracticescompute.htm#two) for recommendations on how to manage instances.
1212
13-
## Maintainers
14-
15-
This module is maintained by Oracle.
16-
1713
## Requirements
1814

1915
The diagram below summarizes the required components and their respective versions to use this module.
2016

2117
![versions](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/blob/main/docs/diagrams/versions.svg?raw=true&sanitize=true)
2218

23-
To enforce versions compatibility of both Terraform and the OCI provider, your root configuration should ideally include this block in `main.tf` for version pinning:
19+
To enforce versions compatibility of both Terraform and the OCI provider, your root configuration should ideally include this block for version pinning:
2420

2521
```HCL
2622
terraform {
27-
required_version = ">= 0.12"
23+
required_version = ">= 0.12.6"
2824
required_providers {
2925
oci = {
30-
version = ">= 3.27"
26+
version = ">= 4.0.0"
3127
}
3228
}
3329
}
@@ -59,11 +55,11 @@ module "instance" {
5955

6056
## What's coming next for this module?
6157

62-
The current focus is to get back in close the gap between this module and the provider's capabilities. We started with a complete code base update for [HCL2 syntax compatibility](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/releases/tag/v2.0.2), then adding support for [Regional Subnets](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/releases/tag/v2.0.4) and now [Flexible Shapes](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/pull/49).
58+
The current focus is to close the gap between this module and the provider's capabilities. We started with a complete codebase update for [HCL2 syntax compatibility](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/releases/tag/v2.0.2), then adding support for [Regional Subnets](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/releases/tag/v2.0.4) and lastly [Flexible Shapes](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/pull/49).
6359

6460
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 ...
6561

66-
Compute Instances are also a perfect place to illustrate [module composition principles](https://www.terraform.io/docs/language/modules/develop/composition.html) reusing the other existing official Terraform OCI Modules
62+
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.
6763

6864
## Configuring iSCSI volume attachments
6965

@@ -73,7 +69,8 @@ Compute Instances are also a perfect place to illustrate [module composition pri
7369

7470
## Contributing
7571

76-
This project is open source. Oracle appreciates any contributions that are made by the open source community: raising issues, improving documentation, fixing bugs, or adding new features.
72+
This project is open source and maintained by Oracle.
73+
Oracle appreciates any contributions that are made by the open source community: raising issues, improving documentation, fixing bugs, or adding new features.
7774

7875
Learn how to [contribute](https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/blob/main/CONTRIBUTING.adoc).
7976

docs/terraformoptions.adoc

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +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_volume[oci_core_volume.this] |resource
29-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume_attachment[oci_core_volume_attachment.this] |resource
30-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_instance_credentials[oci_core_instance_credentials.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.credential] |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
3133
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_shapes[oci_core_shapes.ad1] |data source
32-
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_subnet[oci_core_subnet.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
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+
|Whether to create a Public IP to attach to primary vnic and which lifetime. 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_fixed_shape/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ You will need to collect the following information before you start:
1313

1414
1. your OCI provider authentication values
1515
2. a compartment OCID in which the instances will be created
16-
3. a subnet OCID to which the instance's primary VNICs will be attached
16+
3. a source OCID to deploy the instance, usually an image ocid from [OCI Platform Images list]
17+
4. a subnet OCID to which the instance's primary VNICs will be attached
1718

1819
For detailed instructions, see [docs/prerequisites.adoc]
1920

@@ -33,3 +34,5 @@ Then apply the example using the following commands:
3334

3435
[Terraform Variable Definition file]:https://www.terraform.io/docs/language/values/variables.html#variable-definitions-tfvars-files
3536
[docs/prerequisites.adoc]:https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/blob/main/docs/prerequisites.adoc
37+
[Provisioning Infrastructure with Terraform]:https://www.terraform.io/docs/cli/run/index.html
38+
[OCI Platform Images list]:https://docs.oracle.com/en-us/iaas/images/

examples/instances_fixed_shape/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) 2018, 2021 Oracle and/or its affiliates.
22

33
terraform {
4-
required_version = ">= 0.12" // terraform version below 0.12 is not tested/supported with this module
4+
required_version = ">= 0.13" // terraform version below 0.12 is not tested/supported with this module
55
required_providers {
66
oci = {
7-
version = ">= 3.27" // force downloading oci-provider compatible with terraform v0.12
7+
version = ">= 4.0.0" // force downloading oci-provider compatible with terraform v0.12
88
}
99
}
1010
}
@@ -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 which 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/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ You will need to collect the following information before you start:
1313

1414
1. your OCI provider authentication values
1515
2. a compartment OCID in which the instances will be created
16-
3. a subnet OCID to which the instance's primary VNICs will be attached
16+
3. a source OCID to deploy the instance, usually an image ocid from [OCI Platform Images list]
17+
4. a subnet OCID to which the instance's primary VNICs will be attached
1718

1819
For detailed instructions, see [docs/prerequisites.adoc]
1920

@@ -33,3 +34,5 @@ Then apply the example using the following commands:
3334

3435
[Terraform Variable Definition file]:https://www.terraform.io/docs/language/values/variables.html#variable-definitions-tfvars-files
3536
[docs/prerequisites.adoc]:https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/blob/main/docs/prerequisites.adoc
37+
[Provisioning Infrastructure with Terraform]:https://www.terraform.io/docs/cli/run/index.html
38+
[OCI Platform Images list]:https://docs.oracle.com/en-us/iaas/images/

examples/instances_flex_shape/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) 2018, 2021 Oracle and/or its affiliates.
22

33
terraform {
4-
required_version = ">= 0.12" // terraform version below 0.12 is not tested/supported with this module
4+
required_version = ">= 0.13" // terraform version below 0.12 is not tested/supported with this module
55
required_providers {
66
oci = {
7-
version = ">= 3.27" // force downloading oci-provider compatible with terraform v0.12
7+
version = ">= 4.0.0" // force downloading oci-provider compatible with terraform v0.12
88
}
99
}
1010
}
@@ -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 which lifetime. Valid values are NONE, RESERVED or EPHEMERAL."
124+
type = string
125+
default = "NONE"
126126
}
127127

128128
variable "subnet_ocids" {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Creating Compute Instances using Flex shape
2+
3+
This example illustrates how to use this module to creates compute instances with a reserved public IP.
4+
5+
One modules will be configured:
6+
7+
- 1 instance (1 OCPU, 1GB RAM) with a reserved public IP associated with the Primary IP of the primary VNIC.
8+
9+
## Prerequisites
10+
11+
You will need to collect the following information before you start:
12+
13+
1. your OCI provider authentication values
14+
2. a compartment OCID in which the instances will be created
15+
3. a source OCID to deploy the instance, usually an image ocid from [OCI Platform Images list]
16+
4. a subnet OCID to which the instance's primary VNICs will be attached
17+
18+
For detailed instructions, see [docs/prerequisites.adoc]
19+
20+
## Using this example with Terraform cli
21+
22+
Prepare one [Terraform Variable Definition file] named `terraform.tfvars` with the required authentication information.
23+
24+
*TIP: You can rename and configure `terraform.tfvars.example` from this example's folder.*
25+
26+
Then apply the example using the following commands:
27+
28+
```shell
29+
> terraform init
30+
> terraform plan
31+
> terraform apply
32+
```
33+
34+
See [Provisioning Infrastructure with Terraform] for more details about Terraform CLI and the available subcommands.
35+
36+
[Terraform Variable Definition file]:https://www.terraform.io/docs/language/values/variables.html#variable-definitions-tfvars-files
37+
[docs/prerequisites.adoc]:https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/blob/main/docs/prerequisites.adoc
38+
[Provisioning Infrastructure with Terraform]:https://www.terraform.io/docs/cli/run/index.html
39+
[OCI Platform Images list]:https://docs.oracle.com/en-us/iaas/images/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2018, 2021 Oracle and/or its affiliates.
2+
3+
terraform {
4+
required_version = ">= 0.13" // terraform version below 0.12 is not tested/supported with this module
5+
required_providers {
6+
oci = {
7+
version = ">= 4.0.0" // force downloading oci-provider compatible with terraform v0.12
8+
}
9+
}
10+
}
11+
12+
provider "oci" {
13+
tenancy_ocid = var.tenancy_ocid
14+
user_ocid = var.user_ocid
15+
fingerprint = var.fingerprint
16+
private_key_path = var.private_key_path
17+
region = var.region
18+
}
19+
20+
# # * This module will create 1 Flex Compute Instances, with a reserved public IP
21+
module "instance_reserved_ip" {
22+
source = "oracle-terraform-modules/compute-instance/oci"
23+
# general oci parameters
24+
compartment_ocid = var.compartment_ocid
25+
freeform_tags = var.freeform_tags
26+
defined_tags = var.defined_tags
27+
# compute instance parameters
28+
ad_number = null
29+
instance_count = 1
30+
instance_display_name = "instance_reserved_ip"
31+
shape = var.shape
32+
source_ocid = var.source_ocid
33+
source_type = var.source_type
34+
instance_flex_memory_in_gbs = 1 # only used if shape is Flex type
35+
instance_flex_ocpus = 1 # only used if shape is Flex type
36+
# operating system parameters
37+
ssh_authorized_keys = var.ssh_authorized_keys
38+
# networking parameters
39+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
40+
subnet_ocids = var.subnet_ocids
41+
# storage parameters
42+
block_storage_sizes_in_gbs = [] # no block volume will be created
43+
preserve_boot_volume = false
44+
}
45+
46+
output "instance_reserved_ip" {
47+
description = "IP information of the instances provisioned by this module."
48+
value = module.instance_reserved_ip.instances_summary
49+
}

0 commit comments

Comments
 (0)