Skip to content

Commit

Permalink
Refactor drg attachment (#67)
Browse files Browse the repository at this point in the history
At this stage, drg sub-module is a the same level of features than before refactor
implementation fully backward compatible.

* feat(drg): arguments provider parity
  - all arguments available on oci provider for oci_core_drg are supported by the module
  - all attributes are accessible through drg_all_attributes ouput
* feat(drg): add vcn attachment
* feat(drg): add support for route tables definition

VCN attachments are regrouped under one oci_core_drg_attachment resource,
taking a map(any) as input from var.drg_vcn_attachments.

This new map allows to define two route tables:
- drg_route_table_id to control routing inside the drg
- vcn_transit_routing_id to control transit routing on the vcn attachment

Other attachment types will generate distinct oci_core_drg_attachment resources.
add a new drg_summary output that combine drg name, drg id and vcn attachments.

other minor changes:

- make vcn_name and vcn_dns_label optional inputs
- add feature to disable vcn dns

fix: #46 , #66
  • Loading branch information
kral2 authored Oct 11, 2021
1 parent dabecf2 commit ac971d6
Show file tree
Hide file tree
Showing 21 changed files with 556 additions and 112 deletions.
20 changes: 0 additions & 20 deletions .terraform.lock.hcl

This file was deleted.

30 changes: 22 additions & 8 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,31 @@ Given a version number MAJOR.MINOR.PATCH:
- MINOR version when adding functionality in a backwards compatible manner,
- PATCH version when making backwards compatible bug fixes.
== v3.1.0 (Unreleased)
== v3.1.0 (October 06, 2021)

=== New features
* Added add IPv6 support for VCN (fixes #62)
* Added IPv6 support for VCN (fixes #62)
* Added capability to attach multiple vcn to a drg using the new drg sub-module
* Added optional DNS activation on VCN. `var.vcn_dns_label` is now also validated to be alphanumeric string that begins with a letter (fixes #66)

=== Changes
* drg is refactored as an independent sub-module
* `var.vcn_name` is not a required input anymore for vcn module. Default value is set to `"vcn-module"`
* `var.vcn_dns_label` is not a required input anymore for vcn module. Default value is set to `"vcnmodule"`

=== Deprecation notice

Creating a DRG directly from vcn module with `var.create_drg` is deprecated. Previous features related to `var.create_drg` remains unchanged and works as expected before:

* DRG provisioning and attachment features are moving to their own sub-module as part of the "DRG refactor" effort (#46)
* Any new feature related to DRG will be handled into the new vcn sub-module: `module/drg`

== v3.0.0 (September 03, 2021)

=== Breaking changes
* Changed minimum Terraform version to 1.0.0 (fixes #49)
* Deprecated `vcn_cidr`, use `vcn_cidrs` instead (list of IPv4 CIDRs).
* Deprecated previous gateway-creation variable names. See v2.2.0 deprecation notice and codingconventions (fixes #24 and #54)
* removed `var.vcn_cidr` (string), use `var.vcn_cidrs` instead (list of strings: IPv4 CIDRs).
* renamed previous gateway-creation variable names. See **v2.2.0 deprecation notice** and codingconventions (fixes #24 and #54)

=== New features
* Added support for local peering gateways (fixes #38)
Expand Down Expand Up @@ -71,10 +85,10 @@ Given a version number MAJOR.MINOR.PATCH:

The folowwing variables will be renamed at the next major release of this module (related to issue #24):

* var.internet_gateway_enabled --> var.create_internet_gateway
* var.nat_gateway_enabled --> var.create_nat_gateway
* var.service_gateway_enabled --> var.create_service_gateway
* var.tags --> var.freeform_tags
* `var.internet_gateway_enabled` will be renamed to `var.create_internet_gateway`
* `var.nat_gateway_enabled` will be renamed to `var.create_nat_gateway`
* `var.service_gateway_enabled` will be renamed to `var.create_service_gateway`
* `var.tags` will be renamed to `var.freeform_tags`

== v2.1.0 (February 03, 2021)

Expand Down
41 changes: 20 additions & 21 deletions docs/terraformoptions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

== General OCI

[stripes=odd,cols="2m,5,1m,1m", options=header,width="100%"]
[stripes=odd,cols="1m,4,3a,2m", options=header,width="100%"]
|===
|Parameter
|Description
Expand All @@ -48,6 +48,21 @@
|`string`
|"none"

|`freeform_tags`
|simple key-value pairs to tag the resources created specified in the form of a map
|`map(any)`

e.g.
[source,HCL]
----
freeform_tags = {
department = "finance"
environment = "dev"
}
----
|freeform_tags = {
environment = "dev"
}

|===

Expand All @@ -61,7 +76,7 @@
|Default

|`create_drg`
|whether to create Dynamic Routing Gateway. If set to true, creates a Dynamic Routing Gateway.
|Deprecated: Use drg sub-module instead. whether to create Dynamic Routing Gateway. If set to true, creates a Dynamic Routing Gateway.
|`boolean`
|false

Expand All @@ -81,7 +96,7 @@
|false

|`drg_display_name`
|(Updatable) Name of Dynamic Routing Gateway. Does not have to be unique.
|Deprecated: Use drg sub-module instead. (Updatable) Name of Dynamic Routing Gateway. Does not have to be unique.
|`string`
|"drg"

Expand All @@ -90,22 +105,6 @@
|`boolean`
|false

|`freeform_tags`
|simple key-value pairs to tag the resources created specified in the form of a map
|`map(any)`

e.g.
[source,HCL]
----
freeform_tags = {
department = "finance"
environment = "dev"
}
----
|freeform_tags = {
environment = "dev"
}

|`internet_gateway_display_name`
|(Updatable) Name of Internet Gateway. Does not have to be unique.
|`string`
Expand Down Expand Up @@ -211,9 +210,9 @@ e.g.
| `["10.0.0.0/16"]`

|`vcn_dns_label`
|The internal DNS domain for resources created and prepended to "oraclevcn.com" which is the VCN-internal domain name. *Required*
|A DNS label for the VCN, used in conjunction with the VNIC's hostname and subnet's DNS label to form a fully qualified domain name (FQDN) for each VNIC within this subnet
|`string`
|
|"vcnmodule"

|`vcn_name`
|The name of the VCN that will be appended to the label_prefix. *Required*
Expand Down
18 changes: 9 additions & 9 deletions examples/custom_route_rules/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ variable "label_prefix" {
default = "terraform-oci"
}

variable "freeform_tags" {
description = "simple key-value pairs to tag the created resources using freeform OCI Free-form tags."
type = map(any)
default = {
terraformed = "please do not edit manually"
module = "oracle-terraform-modules/vcn/oci"
}
}

# vcn parameters

variable "create_drg" {
Expand Down Expand Up @@ -79,15 +88,6 @@ variable "enable_ipv6" {
default = false
}

variable "freeform_tags" {
description = "simple key-value pairs to tag the resources created"
type = map(any)
default = {
terraformed = "please do not edit manually"
module = "oracle-terraform-modules/vcn/oci"
}
}

variable "lockdown_default_seclist" {
description = "whether to remove all default security rules from the VCN Default Security List"
type = bool
Expand Down
41 changes: 41 additions & 0 deletions examples/drg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Creating a DRG

[docs/prerequisites]:https://github.com/oracle-terraform-modules/terraform-oci-vcn/blob/main/docs/prerequisites.adoc
[Provisioning Infrastructure with Terraform]:https://www.terraform.io/docs/cli/run/index.html

This example illustrates how to use submodule `drg` from `terraform-oci-vcn` module to create a DRG. Use this example if you need to create a DRG independently from a VCN.

<!-- insert list of created resources here -->

This diagram illustrates what will be created by this example.

<!-- insert diagram here -->

## How to declare a DRG

<!-- update provisioning info -->

## Prerequisites

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

1. your OCI provider authentication values
2. a compartment OCID in which the present configuration will be created

For detailed instructions, see [docs/prerequisites]

## Using this example with Terraform CLI

Prepare one [Terraform Variable Definition file] named `terraform.tfvars` with the required authentication information.

*TIP: You can rename and configure `terraform.tfvars.example` from this example's folder.*

Then apply the example using the following commands:

```shell
> terraform init
> terraform plan
> terraform apply
```

See [Provisioning Infrastructure with Terraform] for more details about Terraform CLI and the available subcommands.
71 changes: 71 additions & 0 deletions examples/drg/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2019, 2021, Oracle Corporation and/or affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

# Version requirements

terraform {
required_providers {
oci = {
source = "hashicorp/oci"
version = ">=4.41.0"
}
}
required_version = ">= 1.0.0"
}

# Resources

module "drg_hub" {
source = "oracle-terraform-modules/vcn/oci//modules/drg"

# general oci parameters
compartment_id = var.compartment_id
label_prefix = var.label_prefix

# drg parameters
drg_display_name = var.drg_display_name
drg_vcn_attachments = { for k, v in module.vcn_spokes : k => {
# instead of manually setting the vcn_id in a variable named var.vcn_attachments for example
# this `for` expression gets the vcn_id values dynamically from the vcn module used in the same
# configuration below. for example on how to setup this field manually, please see terraform.tfvars.example
# in this folder.
vcn_id : v.vcn_id
vcn_transit_routing_rt_id : null
drg_route_table_id : null
}
}
}

module "vcn_spokes" {
source = "oracle-terraform-modules/vcn/oci"
version = "3.1.0"
for_each = var.vcn_spokes

# general oci parameters
compartment_id = var.compartment_id
label_prefix = var.label_prefix

# vcn parameters
create_internet_gateway = each.value["create_internet_gateway"] # boolean: true or false
lockdown_default_seclist = each.value["lockdown_default_seclist"] # boolean: true or false
create_nat_gateway = each.value["create_nat_gateway"] # boolean: true or false
create_service_gateway = each.value["create_service_gateway"] # boolean: true or false
enable_ipv6 = each.value["enable_ipv6"] # boolean: true or false
vcn_cidrs = each.value["cidrs"] # List of IPv4 CIDRs
vcn_dns_label = each.value["dns_label"] # string
vcn_name = each.key # string
}

# resource "oci_core_remote_peering_connection" "test_rpc" {
# * boilerplate to start RPC support development
# #Required
# compartment_id = var.compartment_id
# drg_id = module.drg_hub.drg_id

# #Optional
# # defined_tags = {"Operations.CostCenter"= "42"}
# display_name = "test_rpc"
# # freeform_tags = {"Department"= "Finance"}
# # peer_id = oci_core_remote_peering_connection.test_remote_peering_connection2.id
# # peer_region_name = var.remote_peering_connection_peer_region_name
# }
21 changes: 21 additions & 0 deletions examples/drg/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2019, 2021, Oracle Corporation and/or affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

# display a summary of the drg and its attachments
output "module_drg_hub" {
description = "drg name, OCID and vcn attachment summary"
value = module.drg_hub.drg_summary
}

# display names and ids of a module that use for_each and shows how to use the *_all_attributes output to select a specific field
output "module_vcn_spokes" {
description = "vcn names and OCIDs"
value = { for vcn in module.vcn_spokes : "${~vcn.vcn_all_attributes.display_name~}" => "${vcn.vcn_id~}" }
# We combine here two expressions:
# 1. "for" expression to loop over each key of module.vcn_spokes wrapped with {...} to produce an object
# 2. "String Template directives" for interpolation and whitespace stripping:
# --> ${ ... } evaluates the expression given between the markers, then inserts it into the final string https://www.terraform.io/docs/language/expressions/strings.html#interpolation
# --> ~ indicates whitespace stripping before or after https://www.terraform.io/docs/language/expressions/strings.html#whitespace-stripping
#
# result will be an object containing "vcn.display_name" = "vcn.id" for each vcn in the vcn_spokes module
}
48 changes: 48 additions & 0 deletions examples/drg/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2019, 2021 Oracle Corporation and/or affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

api_fingerprint = ""
api_private_key_path = ""
compartment_id = ""
drg_display_name = "drg_hub"
label_prefix = "terraform-oci"
region = ""
tenancy_id = ""
user_id = ""
vcn_spokes = {
"vcn_spoke1": {
"cidrs": [
"10.0.1.0/24",
"10.0.2.0/24"
],
"create_internet_gateway": true,
"create_nat_gateway": true,
"create_service_gateway": true,
"dns_label": "spoke1",
"enable_ipv6": true,
"lockdown_default_seclist": true
},
"vcn_spoke2": {
"cidrs": [
"10.0.3.0/24"
],
"create_internet_gateway": true,
"create_nat_gateway": false,
"create_service_gateway": true,
"dns_label": "spoke2",
"enable_ipv6": false,
"lockdown_default_seclist": true
}
}
vcn_attachments = {
"vcn_spoke1": {
vcn_id : ""
vcn_transit_routing_rt_id : ""
drg_route_table_id : ""
},
"vcn_spoke2": {
vcn_id : ""
vcn_transit_routing_rt_id : ""
drg_route_table_id : ""
}
}
Loading

0 comments on commit ac971d6

Please sign in to comment.