diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl deleted file mode 100644 index b8783a6..0000000 --- a/.terraform.lock.hcl +++ /dev/null @@ -1,20 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/oci" { - version = "4.41.0" - constraints = ">= 4.0.0" - hashes = [ - "h1:DC6r7BHQ277FCkPoAPBNJDqZxZZ6PacXoHWLovbU7l4=", - "zh:03ed0ba0eeb7cf926b407c575c285ffc2c45edcb36154116a59d443b16738e92", - "zh:074a02105ef2988c9646b21f793030a805aefcefe273822d5c41285dcaddf956", - "zh:3a6e091fccd3e27040b36bd1ac5d0b47485174667218c6af47802b184d1d3fdc", - "zh:3def971d5d5dbff33c1b7264654378f143d76d5de7430c187710607a0c8e0b22", - "zh:3f343b4f87716f6269b16d7f71eeb8c66db8e6764e25071a9b288daeb1f9464d", - "zh:52a8c88ea9c96022dfb60fe6973cb6b94aac6fc2f922dcc444bf1925dc3db7fd", - "zh:7bd3ed0c4ffcee1dd280104ee79d7a6f2b513b8f4e4a6395f1bbf3894b41527a", - "zh:a116e61180a033a5804d4f82e31d066f340c00029716aa3b4c0af6e098fb6826", - "zh:b2c94b1f25c8a65e6254a9b2602996963a1a22cba6703ec7803faefc2997fcc6", - "zh:ca562056592f610d93c8bde80f14188a82bcdf09be91a28d24c838cec5bc947e", - ] -} diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 9074534..ba2e66c 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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) @@ -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) diff --git a/docs/terraformoptions.adoc b/docs/terraformoptions.adoc index 8d1a880..54ca41c 100644 --- a/docs/terraformoptions.adoc +++ b/docs/terraformoptions.adoc @@ -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 @@ -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" +} |=== @@ -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 @@ -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" @@ -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` @@ -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* diff --git a/examples/custom_route_rules/variables.tf b/examples/custom_route_rules/variables.tf index 998b030..ed8b276 100644 --- a/examples/custom_route_rules/variables.tf +++ b/examples/custom_route_rules/variables.tf @@ -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" { @@ -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 diff --git a/examples/drg/README.md b/examples/drg/README.md new file mode 100644 index 0000000..0d5ce4c --- /dev/null +++ b/examples/drg/README.md @@ -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. + + + +This diagram illustrates what will be created by this example. + + + +## How to declare a DRG + + + +## 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. diff --git a/examples/drg/main.tf b/examples/drg/main.tf new file mode 100644 index 0000000..7ef792b --- /dev/null +++ b/examples/drg/main.tf @@ -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 +# } diff --git a/examples/drg/outputs.tf b/examples/drg/outputs.tf new file mode 100644 index 0000000..5e23eec --- /dev/null +++ b/examples/drg/outputs.tf @@ -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 +} diff --git a/examples/drg/terraform.tfvars.example b/examples/drg/terraform.tfvars.example new file mode 100644 index 0000000..ae82667 --- /dev/null +++ b/examples/drg/terraform.tfvars.example @@ -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 : "" + } +} \ No newline at end of file diff --git a/examples/drg/variables.tf b/examples/drg/variables.tf new file mode 100644 index 0000000..64a615b --- /dev/null +++ b/examples/drg/variables.tf @@ -0,0 +1,82 @@ +# 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 + +# provider identity parameters +variable "api_fingerprint" { + description = "fingerprint of oci api private key" + type = string + # no default value, asking user to explicitly set this variable's value. see codingconventions.adoc +} + +variable "api_private_key_path" { + description = "path to oci api private key used" + type = string + # no default value, asking user to explicitly set this variable's value. see codingconventions.adoc +} + +variable "region" { + description = "the oci region where resources will be created" + type = string + # no default value, asking user to explicitly set this variable's value. see codingconventions.adoc + # List of regions: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm#ServiceAvailabilityAcrossRegions +} + +variable "tenancy_id" { + description = "tenancy id where to create the sources" + type = string + # no default value, asking user to explicitly set this variable's value. see codingconventions.adoc +} + +variable "user_id" { + description = "id of user that terraform will use to create the resources" + type = string + # no default value, asking user to explicitly set this variable's value. see codingconventions.adoc +} + +# general oci parameters + +variable "compartment_id" { + description = "compartment id where to create all resources" + type = string + # no default value, asking user to explicitly set this variable's value. see codingconventions.adoc +} + +variable "label_prefix" { + description = "a string that will be prepended to all resources" + type = string + default = "terraform-oci" +} + +# drg parameters + +variable "drg_display_name" { + description = "(Updatable) Name of Dynamic Routing Gateway. Does not have to be unique." + type = string + default = "drg_hub" +} + +# vcn parameters + +variable "vcn_spokes" { + type = map(any) + default = { + vcn_spoke1 = { + cidrs = ["10.0.1.0/24", "10.0.2.0/24"] + dns_label = "spoke1" + create_internet_gateway = true + create_nat_gateway = true + create_service_gateway = true + enable_ipv6 = true + lockdown_default_seclist = true + } + vcn_spoke2 = { + cidrs = ["10.0.3.0/24"] + dns_label = "spoke2" + create_internet_gateway = true + create_nat_gateway = false + create_service_gateway = true + enable_ipv6 = false + lockdown_default_seclist = true + } + } +} diff --git a/examples/hub-spoke/terraform.tfvars.example b/examples/hub-spoke/terraform.tfvars.example index 1ec11de..4d90f55 100644 --- a/examples/hub-spoke/terraform.tfvars.example +++ b/examples/hub-spoke/terraform.tfvars.example @@ -1,4 +1,4 @@ -# Copyright (c) 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved. +# 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 # provider identity parameters diff --git a/examples/hub-spoke/variables.tf b/examples/hub-spoke/variables.tf index f736bb4..e84d0c9 100644 --- a/examples/hub-spoke/variables.tf +++ b/examples/hub-spoke/variables.tf @@ -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" { @@ -85,15 +94,6 @@ variable "enable_ipv6" { default = true } -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 "vcn_cidrs" { description = "The list of IPv4 CIDR blocks the VCN will use." type = list(string) diff --git a/examples/module_composition/variables.tf b/examples/module_composition/variables.tf index af71fb8..e416c18 100644 --- a/examples/module_composition/variables.tf +++ b/examples/module_composition/variables.tf @@ -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" { @@ -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 diff --git a/main.tf b/main.tf index ec957f2..f20e94d 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,19 @@ # Copyright (c) 2019, 2020 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 + +#! Calling module/drg from vcn module for backward compatibility with feature related to `var.create_drg` +#! deprecation notice: this internal module call will be removed at next major release + +module "drg_from_vcn_module" { + source = "./modules/drg/" + + # general oci parameters + compartment_id = var.compartment_id + label_prefix = var.label_prefix + + # drg parameters + drg_display_name = var.label_prefix == "none" ? "${var.drg_display_name}_created_from_${var.vcn_name}" : "${var.drg_display_name}" + + count = var.create_drg == true ? 1 : 0 +} \ No newline at end of file diff --git a/modules/drg/README.md b/modules/drg/README.md new file mode 100644 index 0000000..b378027 --- /dev/null +++ b/modules/drg/README.md @@ -0,0 +1,44 @@ +# modules/drg + +## About + +This Terraform module creates an OCI [DRG](https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/managingDRGs.htm). It is used internally by the [VCN module](https://registry.terraform.io/modules/oracle-terraform-modules/vcn/oci/latest) but can also be used to provision a DRG independently from the VCN module.. + + + +## Requirements + +No requirements. +## Providers + +| Name | Version | +|------|---------| +| [oci](#provider\_oci) | 4.45.0 | +## Resources + +| Name | Type | +|------|------| +| [oci_core_drg.drg](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_drg) | resource | +| [oci_core_drg_attachment.vcns](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_drg_attachment) | resource | +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [compartment\_id](#input\_compartment\_id) | compartment id where to create all resources | `string` | n/a | yes | +| [defined\_tags](#input\_defined\_tags) | predefined and scoped to a namespace to tag the created resources using OCI Defined tags. | `map(any)` | `null` | no | +| [drg\_display\_name](#input\_drg\_display\_name) | (Updatable) Name of Dynamic Routing Gateway. Does not have to be unique. | `string` | `"drg"` | no | +| [drg\_vcn\_attachments](#input\_drg\_vcn\_attachments) | The OCID of the network resource attached to the DRG | `map(any)` | `null` | no | +| [freeform\_tags](#input\_freeform\_tags) | simple key-value pairs to tag the created resources using freeform OCI Free-form tags. | `map(any)` |
{
"module": "oracle-terraform-modules/vcn/oci//modules/drg",
"terraformed": "Please do not edit manually"
}
| no | +| [label\_prefix](#input\_label\_prefix) | a string that will be prepended to all resources | `string` | `"none"` | no | +| [region](#input\_region) | the OCI region where resources will be created | `string` | `null` | no | +## Outputs + +| Name | Description | +|------|-------------| +| [drg\_all\_attributes](#output\_drg\_all\_attributes) | all attributes of created drg | +| [drg\_attachment\_all\_attributes](#output\_drg\_attachment\_all\_attributes) | all attributes related to drg attachment | +| [drg\_display\_name](#output\_drg\_display\_name) | display name of drg if it is created | +| [drg\_id](#output\_drg\_id) | id of drg if it is created | +| [drg\_summary](#output\_drg\_summary) | drg information summary | + + \ No newline at end of file diff --git a/modules/drg/drg.tf b/modules/drg/drg.tf new file mode 100644 index 0000000..4e02efe --- /dev/null +++ b/modules/drg/drg.tf @@ -0,0 +1,32 @@ +# 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 + +resource "oci_core_drg" "drg" { + compartment_id = var.compartment_id + display_name = var.label_prefix == "none" ? var.drg_display_name : "${var.label_prefix}-${var.drg_display_name}" + + freeform_tags = var.freeform_tags + defined_tags = var.defined_tags +} + +resource "oci_core_drg_attachment" "vcns" { + for_each = var.drg_vcn_attachments != null ? var.drg_vcn_attachments : {} + display_name = var.label_prefix == "none" ? "${var.drg_display_name}-to-${each.key}" : "${var.label_prefix}-${var.drg_display_name}-to-${each.key}" + + freeform_tags = var.freeform_tags + defined_tags = var.defined_tags + + drg_id = oci_core_drg.drg.id + + network_details { + id = each.value.vcn_id # required + route_table_id = each.value.vcn_transit_routing_rt_id != null ? each.value.vcn_transit_routing_rt_id : null # optional. Only needed when using VCN Transit Routing or Network Appliance service chaining + type = "VCN" # Required + } + + drg_route_table_id = each.value.drg_route_table_id != null ? each.value.drg_route_table_id : null # (Optional) (Updatable) string + + # * args not valid for attachment type VCN at the moment + export_drg_route_distribution_id = null # (Optional) (Updatable) string + remove_export_drg_route_distribution_trigger = false # (Optional) (Updatable) boolean +} diff --git a/modules/drg/outputs.tf b/modules/drg/outputs.tf new file mode 100644 index 0000000..c4798e9 --- /dev/null +++ b/modules/drg/outputs.tf @@ -0,0 +1,35 @@ +# Copyright (c) 2019, 2020 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/ + +output "drg_id" { + description = "id of drg if it is created" + value = join(",", oci_core_drg.drg[*].id) +} + +output "drg_display_name" { + description = "display name of drg if it is created" + value = join(",", oci_core_drg.drg[*].display_name) +} + +# Complete outputs for each resources with provider parity. Auto-updating. +# Usefull for module composition. + +output "drg_all_attributes" { + description = "all attributes of created drg" + value = { for k, v in oci_core_drg.drg : k => v } +} + +output "drg_attachment_all_attributes" { + description = "all attributes related to drg attachment" + value = { for k, v in oci_core_drg_attachment.vcns : k => v } +} + +output "drg_summary" { + description = "drg information summary" + value = { + (oci_core_drg.drg.display_name) = { + drg_id = oci_core_drg.drg.id + vcn_attachments = { for k, v in oci_core_drg_attachment.vcns : k => v.network_details[0].id } + } + } +} diff --git a/modules/drg/variables.tf b/modules/drg/variables.tf new file mode 100644 index 0000000..1e59426 --- /dev/null +++ b/modules/drg/variables.tf @@ -0,0 +1,59 @@ +# 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 + +# provider identity parameters + +variable "region" { + # List of regions: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm#ServiceAvailabilityAcrossRegions + description = "the OCI region where resources will be created" + type = string + default = null +} + +# general oci parameters + +variable "compartment_id" { + description = "compartment id where to create all resources" + type = string + # no default value, asking user to explicitly set this variable's value. see codingconventions.adoc +} + +variable "label_prefix" { + description = "a string that will be prepended to all resources" + type = string + default = "none" +} + +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//modules/drg" + } +} + +variable "defined_tags" { + description = "predefined and scoped to a namespace to tag the created resources using OCI Defined tags." + type = map(any) + default = null +} + +# drg parameters + +variable "drg_display_name" { + description = "(Updatable) Name of Dynamic Routing Gateway. Does not have to be unique." + type = string + default = "drg" + + validation { + condition = length(var.drg_display_name) > 0 + error_message = "The drg_display_name value cannot be an empty string." + } +} + +variable "drg_vcn_attachments" { + description = "The OCID of the network resource attached to the DRG" + type = map(any) + default = null +} diff --git a/outputs.tf b/outputs.tf index 77fad1a..b30d782 100644 --- a/outputs.tf +++ b/outputs.tf @@ -7,10 +7,10 @@ output "vcn_id" { } output "drg_id" { - description = "id of drg if it is created" - value = join(",", oci_core_drg.drg[*].id) + #! deprecation notice: this output will be removed at next major release + description = "Deprecated: Use drg sub-module instead. id of drg if it is created" + value = join(",", module.drg_from_vcn_module[*].drg_id) } - output "nat_gateway_id" { description = "id of nat gateway if it is created" value = join(",", oci_core_nat_gateway.nat_gateway[*].id) @@ -39,14 +39,10 @@ output "nat_route_id" { # New complete outputs for each resources with provider parity. Auto-updating. # Usefull for module composition. -output "drg_all_attributes" { - description = "all attributes of created drg" - value = { for k, v in oci_core_drg.drg : k => v } -} - output "drg_attachment_all_attributes" { - description = "all attributes related to drg attachment" - value = { for k, v in oci_core_drg_attachment.drg : k => v } + #! deprecation notice: this output will be removed at next major release + description = "Deprecated: Use drg sub-module instead. all attributes related to drg attachment" + value = { for k, v in oci_core_drg_attachment.drg_from_vcn_module : k => v } } output "internet_gateway_all_attributes" { diff --git a/terraform.tfvars.example b/terraform.tfvars.example index c37d762..9ac8a17 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -1,4 +1,4 @@ -# Copyright (c) 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved. +# 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 # Region diff --git a/variables.tf b/variables.tf index 3747f0d..fa4f530 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,4 @@ -# Copyright (c) 2019, 2020 Oracle Corporation and/or affiliates. All rights reserved. +# 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 # provider identity parameters @@ -25,7 +25,7 @@ variable "label_prefix" { } variable "freeform_tags" { - description = "simple key-value pairs to tag the resources created using freeform 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" @@ -36,7 +36,8 @@ variable "freeform_tags" { # vcn parameters variable "create_drg" { - description = "whether to create Dynamic Routing Gateway. If set to true, creates a Dynamic Routing Gateway and attach it to the vcn." + #! Deprecation notice: Please use drg sub-module instead + description = "Deprecated: Use drg sub-module instead. Whether to create Dynamic Routing Gateway. If set to true, creates a Dynamic Routing Gateway and attach it to the vcn." type = bool default = false } @@ -65,12 +66,6 @@ variable "enable_ipv6" { default = false } -variable "local_peering_gateways" { - description = "Map of Local Peering Gateways to attach to the VCN." - type = map(any) - default = null -} - variable "lockdown_default_seclist" { description = "whether to remove all default security rules from the VCN Default Security List" default = true @@ -92,17 +87,29 @@ variable "vcn_cidrs" { variable "vcn_dns_label" { description = "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" type = string + default = "vcnmodule" + + validation { + condition = length(regexall("^[^0-9][a-zA-Z0-9_]+$", var.vcn_dns_label)) > 0 + error_message = "DNS label must be an alphanumeric string that begins with a letter." + } } variable "vcn_name" { description = "user-friendly name of to use for the vcn to be appended to the label_prefix" type = string + default = "vcn-module" + validation { + condition = length(var.vcn_name) > 0 + error_message = "The vcn_name value cannot be an empty string." + } } # gateways parameters variable "drg_display_name" { - description = "(Updatable) Name of Dynamic Routing Gateway. Does not have to be unique." + #! Deprecation notice: Please use drg sub-module instead + description = "Deprecated: Use drg sub-module instead. (Updatable) Name of Internet Gateway. Does not have to be unique." type = string default = "drg" @@ -123,6 +130,12 @@ variable "internet_gateway_display_name" { } } +variable "local_peering_gateways" { + description = "Map of Local Peering Gateways to attach to the VCN." + type = map(any) + default = null +} + variable "nat_gateway_display_name" { description = "(Updatable) Name of NAT Gateway. Does not have to be unique." type = string diff --git a/vcn_gateways.tf b/vcn_gateways.tf index a915652..082b84b 100644 --- a/vcn_gateways.tf +++ b/vcn_gateways.tf @@ -38,7 +38,7 @@ resource "oci_core_route_table" "ig" { content { destination = route_rules.value.destination destination_type = route_rules.value.destination_type - network_entity_id = oci_core_drg.drg[0].id + network_entity_id = module.drg_from_vcn_module[0].drg_id description = route_rules.value.description } } @@ -154,7 +154,7 @@ resource "oci_core_route_table" "nat" { content { destination = route_rules.value.destination destination_type = route_rules.value.destination_type - network_entity_id = oci_core_drg.drg[0].id + network_entity_id = module.drg_from_vcn_module[0].drg_id description = route_rules.value.description } } @@ -174,7 +174,7 @@ resource "oci_core_route_table" "nat" { } dynamic "route_rules" { - # * filter var.internet_gateway_route_rules for generic routes + # * filter var.nat_gateway_route_rules for generic routes # * can take any Named Value : String, Input Variable, Local Value, Data Source, Resource, Module Output ... # * useful for gateways that are not managed by the module for_each = var.nat_gateway_route_rules != null ? { for k, v in var.nat_gateway_route_rules : k => v @@ -197,17 +197,10 @@ resource "oci_core_route_table" "nat" { # Dynamic Routing Gateway (DRG) ############################### -resource "oci_core_drg" "drg" { - compartment_id = var.compartment_id - display_name = var.label_prefix == "none" ? var.drg_display_name : "${var.label_prefix}-${var.drg_display_name}" - - freeform_tags = var.freeform_tags - - count = var.create_drg == true ? 1 : 0 -} - -resource "oci_core_drg_attachment" "drg" { - drg_id = oci_core_drg.drg[count.index].id +#! this resource is here for backward compatibility with feature related to `var.create_drg` +#! deprecation notice: this resource will be removed at next major release +resource "oci_core_drg_attachment" "drg_from_vcn_module" { + drg_id = module.drg_from_vcn_module[0].drg_id vcn_id = oci_core_vcn.vcn.id display_name = var.label_prefix == "none" ? "${var.drg_display_name}-to-${oci_core_vcn.vcn.display_name}" : "${var.label_prefix}-${var.drg_display_name}-to-${oci_core_vcn.vcn.display_name}"