diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index fb4ce55..b197960 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -28,7 +28,7 @@ If you are running into one of these scenarios, we recommend opening an issue in ### Terraform Version and Provider Version - @@ -43,8 +43,8 @@ If you are not running the latest version of Terraform or the provider, please u ```hcl # Copy-paste your Terraform configurations here - for large Terraform configs, -# please use a service like Dropbox and share a link to the ZIP file. -# Please remove any sensitive information from configuration files before sharing them. +# please use a service like Dropbox and share a link to the ZIP file. +# Please remove any sensitive information from configuration files before sharing them. ``` ### Debug Output @@ -59,8 +59,8 @@ Github Gist: https://gist.github.com/ ### Panic Output - diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 96e5180..20d15fa 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -28,7 +28,7 @@ labels: enhancement ```hcl -# Copy-paste any Terraform configurations for how the requested feature may be used. +# Copy-paste any Terraform configurations for how the requested feature may be used. ``` ### References diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE index 35448df..cefda7e 100644 --- a/.github/PULL_REQUEST_TEMPLATE +++ b/.github/PULL_REQUEST_TEMPLATE @@ -1,6 +1,6 @@ # Proposed change - NAT Gateway`. -If a Service Gateway is also created by the module with `service_gateway_enabled = true`, a second rule is added to redirect all Oracle Network Services traffic to the Service Gateway created by this module: `All services in OSN --> Service Gateway` +If a Service Gateway is also created by the module with `create_service_gateway = true`, a second rule is added to redirect all Oracle Network Services traffic to the Service Gateway created by this module: `All services in OSN --> Service Gateway` == Custom routes terraform-oci-vcn modules have two optional Input Variables to inject user defined route rules into `internet-route` route table and `nat-route` route table using respectively: -- `internet_gateway_route_rules` with the following schema: +- `internet_gateway_route_rules` defined as a `list(map(string))` with the following expected schema: [source,hcl] ---- variable "internet_gateway_route_rules" { description = "(Updatable) List of routing rules to add to Internet Gateway Routing Table" type = list(object({ - destination = string - destination_type = string - network_entity_id = string - description = string + destination = string # required + destination_type = string # required + network_entity_id = string # required + description = string # optional })) default = null } ---- -- `nat_gateway_route_rules` with the following schema: +- `nat_gateway_route_rules` defined as a `list(map(string))` with the following expected schema: [source,hcl] ---- variable "nat_gateway_route_rules" { description = "(Updatable) List of routing rules to add to NAT Gateway Routing Table" type = list(object({ - destination = string - destination_type = string - network_entity_id = string - description = string + destination = string # required + destination_type = string # required + network_entity_id = string # required + description = string # optional })) default = null } diff --git a/docs/terraformoptions.adoc b/docs/terraformoptions.adoc index 3cb5d25..2887d4b 100644 --- a/docs/terraformoptions.adoc +++ b/docs/terraformoptions.adoc @@ -15,11 +15,11 @@ == Provider -[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"] +[stripes=odd,cols="2m,5,1m,1m", options=header,width="100%"] |=== |Parameter |Description -|Values +|Type |Default |`region` @@ -31,58 +31,87 @@ == General OCI -[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"] +[stripes=odd,cols="2m,5,1m,1m", options=header,width="100%"] |=== |Parameter |Description -|Values +|Type |Default |`compartment_id` |Compartment id where the VCN Cluster will be provisioned. *Required*. -| +|`string` | |`label_prefix` |a string to be prepended to the name of resources. *Required*. -| -|none +|`string` +|"none" |=== == VCN -[stripes=odd,cols="1d,4d,3a,3a", options=header,width="100%"] +[stripes=odd,cols="2m,8,1a,2m", options=header,width="100%"] |=== |Parameter |Description -|Values +|Type |Default -|`tags` +|`create_drg` +|whether to create Dynamic Routing Gateway. If set to true, creates a Dynamic Routing Gateway. +|`boolean` +|false + +|`create_internet_gateway` +|Whether to create an internet gateway. +|`boolean` +|false + +|`create_nat_gateway` +|Whether to create a NAT gateway. +|`boolean` +|false + +|`create_service_gateway` +|Whether to create a service gateway to use Oracle Services. +|`boolean` +|false + +|`drg_display_name` +|(Updatable) Name of Dynamic Routing Gateway. Does not have to be unique. +|`string` +|"drg" + +|`freeform_tags` |simple key-value pairs to tag the resources created specified in the form of a map -| e.g. -[source] +|`map(any)` + +e.g. +[source,HCL] ---- -tags = { +freeform_tags = { department = "finance" environment = "dev" } ---- -|tags = { +|freeform_tags = { environment = "dev" } -|`internet_gateway_enabled` -|Whether to create an internet gateway. -|true/false -|false +|`internet_gateway_display_name` +|(Updatable) Name of Internet Gateway. Does not have to be unique. +|`string` +|"internet-gateway" |`internet_gateway_route_rules` |(Updatable) List of routing rules to add to Internet Gateway Route Table. -| e.g. -[source] +|`list(map(string))` + +e.g. +[source,HCL] ---- [ { @@ -103,8 +132,10 @@ tags = { |`local_peering_gateways` |Map of Local Peering Gateways to attach to the VCN -| e.g. -[source] +|`map(any)` + +e.g. +[source,HCL] ---- local_peering_gateways = { to_spoke1 = { @@ -117,28 +148,29 @@ tags = { } } ---- - |null |`lockdown_default_seclist` |whether to remove all default security rules from the VCN Default Security List -|true/false +|`boolean` |true -|`nat_gateway_enabled` -|Whether to create a NAT gateway. -|true/false -|false +|`nat_gateway_display_name` +|(Updatable) Name of NAT Gateway. Does not have to be unique. +|`string` +|"nat-gateway" |nat_gateway_public_ip_id |OCID of reserved IP address for NAT gateway. If default value "none" is used, then a public IP address is selected from Oracle's public IP pool. -| -|none +|`string` +|"none" |`nat_gateway_route_rules` |(Updatable) List of routing rules to add to NAT Gateway Route Table -|e.g. -[source] +|`list(map(string))` + +e.g. +[source,HCL] ---- [ { @@ -157,15 +189,17 @@ tags = { ---- |null -|`service_gateway_enabled` -|Whether to create a service gateway to use Oracle Services. -|true/false -|false +|`service_gateway_display_name` +|(Updatable) Name of Service Gateway. Does not have to be unique. +|`string` +|"service-gateway" |`vcn_cidrs` |The list of IPv4 CIDR blocks the VCN will use. The CIDR block specified for the VCN must not overlap with the CIDR block of another network. -|e.g. -[source] +|`list(string)` + +e.g. +[source,HCL] ---- ["10.0.0.0/16", "172.16.0.0/16", "192.168.0.0/16"] ---- @@ -173,22 +207,12 @@ tags = { |`vcn_dns_label` |The internal DNS domain for resources created and prepended to "oraclevcn.com" which is the VCN-internal domain name. *Required* -| +|`string` | |`vcn_name` |The name of the VCN that will be appended to the label_prefix. *Required* -| -| - -|`create_drg` -|whether to create Dynamic Routing Gateway. If set to true, creates a Dynamic Routing Gateway. -|true/false -|false - -|`drg_display_name` -|(Updatable) Name of Dynamic Routing Gateway. Does not have to be unique. -| +|`string` | |=== diff --git a/examples/custom_route_rules/.terraform.lock.hcl b/examples/custom_route_rules/.terraform.lock.hcl new file mode 100644 index 0000000..202043b --- /dev/null +++ b/examples/custom_route_rules/.terraform.lock.hcl @@ -0,0 +1,20 @@ +# 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.41.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/examples/custom_route_rules/main.tf b/examples/custom_route_rules/main.tf index 68d86dd..822f150 100644 --- a/examples/custom_route_rules/main.tf +++ b/examples/custom_route_rules/main.tf @@ -4,38 +4,41 @@ # Version requirements terraform { - required_version = ">= 0.13" required_providers { oci = { source = "hashicorp/oci" - version = ">=4.0.0" + version = ">=4.41.0" } } + required_version = ">= 1.0.0" } # Resources module "vcn" { source = "oracle-terraform-modules/vcn/oci" - version = "3.0.0-RC2" + version = "3.0.0" # general oci parameters compartment_id = var.compartment_id label_prefix = var.label_prefix - tags = var.tags + freeform_tags = var.freeform_tags # vcn parameters create_drg = var.create_drg # boolean: true or false - internet_gateway_enabled = var.internet_gateway_enabled # boolean: true or false + create_internet_gateway = var.create_internet_gateway # boolean: true or false lockdown_default_seclist = var.lockdown_default_seclist # boolean: true or false - nat_gateway_enabled = var.nat_gateway_enabled # boolean: true or false - service_gateway_enabled = var.service_gateway_enabled # boolean: true or false + create_nat_gateway = var.create_nat_gateway # boolean: true or false + create_service_gateway = var.create_service_gateway # boolean: true or false vcn_cidrs = var.vcn_cidrs # List of IPv4 CIDRs vcn_dns_label = var.vcn_dns_label vcn_name = var.vcn_name # gateways parameters - drg_display_name = var.drg_display_name + drg_display_name = var.drg_display_name + internet_gateway_display_name = var.internet_gateway_display_name + nat_gateway_display_name = var.nat_gateway_display_name + service_gateway_display_name = var.service_gateway_display_name # routing rules diff --git a/examples/custom_route_rules/terraform.tfvars.example b/examples/custom_route_rules/terraform.tfvars.example index 333af2f..9c0d870 100644 --- a/examples/custom_route_rules/terraform.tfvars.example +++ b/examples/custom_route_rules/terraform.tfvars.example @@ -23,11 +23,11 @@ label_prefix = "dev" create_drg = false -internet_gateway_enabled = false +create_internet_gateway = false -nat_gateway_enabled = false +create_nat_gateway = false -service_gateway_enabled = false +create_service_gateway = false vcn_cidrs = ["10.0.0.0/16"] @@ -35,7 +35,7 @@ vcn_dns_label = "vcn" vcn_name = "vcn" -tags = { +freeform_tags = { environment = "dev" lob = "finance" } diff --git a/examples/custom_route_rules/variables.tf b/examples/custom_route_rules/variables.tf index 90e2f21..39fe8d8 100644 --- a/examples/custom_route_rules/variables.tf +++ b/examples/custom_route_rules/variables.tf @@ -55,7 +55,7 @@ variable "create_drg" { default = true } -variable "internet_gateway_enabled" { +variable "create_internet_gateway" { description = "whether to create the internet gateway" type = bool default = true @@ -67,23 +67,23 @@ variable "lockdown_default_seclist" { default = true } -variable "nat_gateway_enabled" { +variable "create_nat_gateway" { description = "whether to create a nat gateway in the vcn" type = bool default = true } -variable "service_gateway_enabled" { +variable "create_service_gateway" { description = "whether to create a service gateway" type = bool default = true } -variable "tags" { +variable "freeform_tags" { description = "simple key-value pairs to tag the resources created" type = map(any) default = { - terraformed = "yes" + terraformed = "please do not edit manually" module = "oracle-terraform-modules/vcn/oci" } } @@ -114,17 +114,30 @@ variable "drg_display_name" { default = "drg" } +variable "internet_gateway_display_name" { + description = "(Updatable) Name of Internet Gateway. Does not have to be unique." + type = string + default = "igw" +} + +variable "nat_gateway_display_name" { + description = "(Updatable) Name of NAT Gateway. Does not have to be unique." + type = string + default = "ngw" +} + +variable "service_gateway_display_name" { + description = "(Updatable) Name of Service Gateway. Does not have to be unique." + type = string + default = "sgw" +} + # routing rules variable "internet_gateway_route_rules" { description = "(Updatable) List of routing rules to add to Internet Gateway Route Table" - type = list(object({ - destination = string - destination_type = string - network_entity_id = string - description = string - })) - default = null + type = list(map(string)) + default = null } locals { @@ -152,6 +165,6 @@ locals { destination_type = "CIDR_BLOCK" network_entity_id = oci_core_local_peering_gateway.lpg.id description = "Terraformed - User added Routing Rule: To lpg with lpg_id directly passed by user. Useful for gateways created outside of vcn module" - }, + } ] } diff --git a/examples/hub-spoke/.terraform.lock.hcl b/examples/hub-spoke/.terraform.lock.hcl new file mode 100644 index 0000000..202043b --- /dev/null +++ b/examples/hub-spoke/.terraform.lock.hcl @@ -0,0 +1,20 @@ +# 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.41.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/examples/hub-spoke/main.tf b/examples/hub-spoke/main.tf index 6e3f82e..5cfa335 100644 --- a/examples/hub-spoke/main.tf +++ b/examples/hub-spoke/main.tf @@ -4,39 +4,42 @@ # Version requirements terraform { - required_version = ">= 0.13" required_providers { oci = { source = "hashicorp/oci" - version = ">=4.0.0" + version = ">=4.41.0" } } + required_version = ">= 1.0.0" } # Resources module "vcn_hub" { - # this module use the generic vcn module and configure it to act as a hub in a hub-and-spoke topology + # this module use the generic vcn module and configure it to act as a hub in a hub-and-spoke topology source = "oracle-terraform-modules/vcn/oci" - version = "3.0.0-RC2" + version = "3.0.0" # general oci parameters compartment_id = var.compartment_id label_prefix = var.label_prefix - tags = var.tags + freeform_tags = var.freeform_tags # vcn parameters create_drg = var.create_drg # boolean: true or false - internet_gateway_enabled = var.internet_gateway_enabled # boolean: true or false + create_internet_gateway = var.create_internet_gateway # boolean: true or false lockdown_default_seclist = var.lockdown_default_seclist # boolean: true or false - nat_gateway_enabled = var.nat_gateway_enabled # boolean: true or false - service_gateway_enabled = var.service_gateway_enabled # boolean: true or false + create_nat_gateway = var.create_nat_gateway # boolean: true or false + create_service_gateway = var.create_service_gateway # boolean: true or false vcn_cidrs = var.vcn_cidrs # List of IPv4 CIDRs vcn_dns_label = var.vcn_dns_label vcn_name = var.vcn_name # gateways parameters - drg_display_name = var.drg_display_name + drg_display_name = var.drg_display_name + internet_gateway_display_name = var.internet_gateway_display_name + nat_gateway_display_name = var.nat_gateway_display_name + service_gateway_display_name = var.service_gateway_display_name local_peering_gateways = { to_spoke1 = { # LPG will be in acceptor mode with a route table attached @@ -48,6 +51,9 @@ module "vcn_hub" { } to_spoke3 = {} # LPG will be in acceptor mode with no route table attached } + + # routing rules + internet_gateway_route_rules = var.internet_gateway_route_rules # this module input shows how to pass routing information to the vcn module through Variable Input. Can be initialized in a *.tfvars or *.auto.tfvars file } resource "oci_core_route_table" "VTR_spokes" { @@ -59,21 +65,21 @@ resource "oci_core_route_table" "VTR_spokes" { } module "vcn_spoke1" { - # this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology + # this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology source = "oracle-terraform-modules/vcn/oci" - version = "3.0.0-RC2" + version = "3.0.0" # general oci parameters compartment_id = var.compartment_id label_prefix = var.label_prefix - tags = var.tags + freeform_tags = var.freeform_tags # vcn parameters create_drg = false # boolean: true or false - internet_gateway_enabled = false # boolean: true or false + create_internet_gateway = false # boolean: true or false lockdown_default_seclist = true # boolean: true or false - nat_gateway_enabled = false # boolean: true or false - service_gateway_enabled = false # boolean: true or false + create_nat_gateway = false # boolean: true or false + create_service_gateway = false # boolean: true or false vcn_cidrs = ["10.0.1.0/24"] # VCN CIDR vcn_dns_label = "fraspoke1" vcn_name = "spoke1" @@ -88,21 +94,21 @@ module "vcn_spoke1" { } module "vcn_spoke2" { - # this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology + # this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology source = "oracle-terraform-modules/vcn/oci" - version = "3.0.0-RC2" + version = "3.0.0" # general oci parameters compartment_id = var.compartment_id label_prefix = var.label_prefix - tags = var.tags + freeform_tags = var.freeform_tags # vcn parameters create_drg = false # boolean: true or false - internet_gateway_enabled = false # boolean: true or false + create_internet_gateway = false # boolean: true or false lockdown_default_seclist = true # boolean: true or false - nat_gateway_enabled = false # boolean: true or false - service_gateway_enabled = false # boolean: true or false + create_nat_gateway = false # boolean: true or false + create_service_gateway = false # boolean: true or false vcn_cidrs = ["10.0.2.0/24"] # VCN CIDR vcn_dns_label = "fraspoke2" vcn_name = "spoke2" @@ -115,27 +121,26 @@ module "vcn_spoke2" { } module "vcn_spoke3" { - # this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology + # this module use the generic vcn module and configure it to act as a spoke in a hub-and-spoke topology source = "oracle-terraform-modules/vcn/oci" - version = "3.0.0-RC2" + version = "3.0.0" # general oci parameters compartment_id = var.compartment_id label_prefix = var.label_prefix - tags = var.tags + freeform_tags = var.freeform_tags # vcn parameters create_drg = false # boolean: true or false - internet_gateway_enabled = false # boolean: true or false + create_internet_gateway = false # boolean: true or false lockdown_default_seclist = true # boolean: true or false - nat_gateway_enabled = false # boolean: true or false - service_gateway_enabled = false # boolean: true or false + create_nat_gateway = false # boolean: true or false + create_service_gateway = false # boolean: true or false vcn_cidrs = ["10.0.3.0/24"] # VCN CIDR vcn_dns_label = "fraspoke3" vcn_name = "spoke3" # gateways parameters - local_peering_gateways = { to_hub = {} # LPG will be in acceptor mode with no route table attached } diff --git a/examples/hub-spoke/terraform.tfvars.example b/examples/hub-spoke/terraform.tfvars.example index 4d89300..09e88ee 100644 --- a/examples/hub-spoke/terraform.tfvars.example +++ b/examples/hub-spoke/terraform.tfvars.example @@ -23,11 +23,11 @@ label_prefix = "dev" create_drg = false -internet_gateway_enabled = false +create_internet_gateway = false -nat_gateway_enabled = false +create_nat_gateway = false -service_gateway_enabled = false +create_service_gateway = false vcn_cidrs = ["10.0.0.0/24"] @@ -35,9 +35,14 @@ vcn_dns_label = "vcn" vcn_name = "vcn" -tags = { +freeform_tags = { environment = "dev" lob = "finance" } +# gateways parameters +drg_display_name = "drg" +internet_gateway_display_name = "igw" +nat_gateway_display_name = "ngw" +service_gateway_display_name = "sgw" diff --git a/examples/hub-spoke/variables.tf b/examples/hub-spoke/variables.tf index ff85e7a..23a01ab 100644 --- a/examples/hub-spoke/variables.tf +++ b/examples/hub-spoke/variables.tf @@ -55,7 +55,7 @@ variable "create_drg" { default = false } -variable "internet_gateway_enabled" { +variable "create_internet_gateway" { description = "whether to create the internet gateway" type = bool default = false @@ -67,23 +67,23 @@ variable "lockdown_default_seclist" { default = true } -variable "nat_gateway_enabled" { +variable "create_nat_gateway" { description = "whether to create a nat gateway in the vcn" type = bool default = false } -variable "service_gateway_enabled" { +variable "create_service_gateway" { description = "whether to create a service gateway" type = bool default = false } -variable "tags" { +variable "freeform_tags" { description = "simple key-value pairs to tag the resources created" type = map(any) default = { - terraformed = "yes" + terraformed = "please do not edit manually" module = "oracle-terraform-modules/vcn/oci" } } @@ -114,17 +114,30 @@ variable "drg_display_name" { default = "drg" } +variable "internet_gateway_display_name" { + description = "(Updatable) Name of Internet Gateway. Does not have to be unique." + type = string + default = "igw" +} + +variable "nat_gateway_display_name" { + description = "(Updatable) Name of NAT Gateway. Does not have to be unique." + type = string + default = "ngw" +} + +variable "service_gateway_display_name" { + description = "(Updatable) Name of Service Gateway. Does not have to be unique." + type = string + default = "sgw" +} + # routing rules variable "internet_gateway_route_rules" { description = "(Updatable) List of routing rules to add to Internet Gateway Route Table" - type = list(object({ - destination = string - destination_type = string - network_entity_id = string - description = string - })) - default = null + type = list(map(string)) + default = null } # locals { diff --git a/examples/module_composition/.terraform.lock.hcl b/examples/module_composition/.terraform.lock.hcl new file mode 100644 index 0000000..b8783a6 --- /dev/null +++ b/examples/module_composition/.terraform.lock.hcl @@ -0,0 +1,20 @@ +# 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/examples/README.md b/examples/module_composition/README.md similarity index 86% rename from examples/README.md rename to examples/module_composition/README.md index 4f586a0..e4e2aec 100644 --- a/examples/README.md +++ b/examples/module_composition/README.md @@ -1,6 +1,7 @@ # Example reusing terraform-oci-vcn and extending to create other network resources -[rootvariables]:https://github.com/oracle-terraform-modules/terraform-oci-vcn/blob/main/examples/variables.tf +[rootvariables]:https://github.com/oracle-terraform-modules/terraform-oci-vcn/blob/main/examples/module_composition/variables.tf +[sampletfvars]:https://github.com/oracle-terraform-modules/terraform-oci-vcn/blob/main/examples/module_composition/terraform.tfvars.example [terraformoptions]:https://github.com/oracle-terraform-modules/terraform-oci-vcn/blob/main/docs/terraformoptions.adoc [terraform-oci-vcn]:https://registry.terraform.io/modules/oracle-terraform-modules/vcn/oci/latest @@ -34,27 +35,12 @@ provider "oci" { } ``` -4. Create the modules directory - -```shell -mkdir modules -cd modules -``` - -5. Add the terraform-oci-vcn module - -```shell -git clone https://github.com/oracle-terraform-modules/terraform-oci-vcn.git vcn -``` - -Note: Cloning is now optional as [the module is published in HashiCorp's registry][terraform-oci-vcn]. - ## Define project variables ### Variables to reuse the vcn module 1. Define the vcn parameters in the root `variables.tf`. -See [`variables.tf`][rootvariables] in this directory. +See an example for [`variables.tf`][rootvariables]. 2. Add additional variables if you need to. @@ -64,19 +50,19 @@ See [`variables.tf`][rootvariables] in this directory. ```HCL module "vcn" { - source = "./modules/vcn" - + source = "oracle-terraform-modules/vcn/oci" + # general oci parameters compartment_id = var.compartment_id label_prefix = var.label_prefix # vcn parameters - internet_gateway_enabled = var.internet_gateway_enabled - nat_gateway_enabled = var.nat_gateway_enabled - service_gateway_enabled = var.service_gateway_enabled + create_internet_gateway = var.create_internet_gateway + create_nat_gateway = var.create_nat_gateway + create_service_gateway = var.create_service_gateway create_drg = var.create_drg drg_display_name = var.drg_display_name - tags = var.tags + tags = var.freeform_tags vcn_cidrs = var.vcn_cidrs vcn_dns_label = var.vcn_dns_label vcn_name = var.vcn_name @@ -84,7 +70,8 @@ module "vcn" { } ``` -2. Enter appropriate values for `terraform.tfvars`. Review [Terraform Options][terraformoptions] for reference +2. Enter appropriate values for `terraform.tfvars`. Review [Terraform Options][terraformoptions] for reference. +You can also use this example [terraform.tfvars][sampletfvars]. Just remove the `.example` extension. ## Add your own modules @@ -94,7 +81,7 @@ module "vcn" { mkdir subnets ``` -2. Define the additional variables(e.g. subnet masks) in the root and module variable file (`variables.tf`) e.g. +2. Define the additional variables(e.g. subnet masks) in the root and module variable file (`variables.tf`) e.g. ```HCL variable "netnum" { @@ -153,7 +140,7 @@ resource "oci_core_security_list" "web" { ingress_security_rules { # allow ssh protocol = 6 - + source = "0.0.0.0" tcp_options { @@ -192,10 +179,10 @@ resource "oci_core_subnet" "web" { ```HCL module "subnets" { source = "./modules/subnets" - + netnum = var.netnum newbits = var.newbits - + # other required variables . . diff --git a/examples/main.tf b/examples/module_composition/main.tf similarity index 79% rename from examples/main.tf rename to examples/module_composition/main.tf index 72c27ce..2c8fc9f 100644 --- a/examples/main.tf +++ b/examples/module_composition/main.tf @@ -4,37 +4,41 @@ # Version requirements terraform { - required_version = ">= 0.13" required_providers { oci = { source = "hashicorp/oci" - version = ">=4.0.0" + version = ">=4.41.0" } } + required_version = ">= 1.0.0" } # Resources module "vcn" { - source = "../" + source = "oracle-terraform-modules/vcn/oci" + version = "3.0.0" # general oci parameters compartment_id = var.compartment_id label_prefix = var.label_prefix - tags = var.tags + freeform_tags = var.freeform_tags # vcn parameters create_drg = var.create_drg # boolean: true or false - internet_gateway_enabled = var.internet_gateway_enabled # boolean: true or false + create_internet_gateway = var.create_internet_gateway # boolean: true or false lockdown_default_seclist = var.lockdown_default_seclist # boolean: true or false - nat_gateway_enabled = var.nat_gateway_enabled # boolean: true or false - service_gateway_enabled = var.service_gateway_enabled # boolean: true or false + create_nat_gateway = var.create_nat_gateway # boolean: true or false + create_service_gateway = var.create_service_gateway # boolean: true or false vcn_cidrs = var.vcn_cidrs # List of IPv4 CIDRs vcn_dns_label = var.vcn_dns_label vcn_name = var.vcn_name # gateways parameters - drg_display_name = var.drg_display_name + drg_display_name = var.drg_display_name + internet_gateway_display_name = var.internet_gateway_display_name + nat_gateway_display_name = var.nat_gateway_display_name + service_gateway_display_name = var.service_gateway_display_name } # Outputs diff --git a/examples/terraform.tfvars.example b/examples/module_composition/terraform.tfvars.example similarity index 69% rename from examples/terraform.tfvars.example rename to examples/module_composition/terraform.tfvars.example index d3a54c3..feb5315 100644 --- a/examples/terraform.tfvars.example +++ b/examples/module_composition/terraform.tfvars.example @@ -23,11 +23,11 @@ label_prefix = "dev" create_drg = false -internet_gateway_enabled = false +create_internet_gateway = false -nat_gateway_enabled = false +create_nat_gateway = false -service_gateway_enabled = false +create_service_gateway = false vcn_cidrs = ["10.0.0.0/16", "172.16.0.0/16", "192.168.0.0/24"] @@ -37,7 +37,14 @@ vcn_name = "vcn" lockdown_default_seclist = false -tags = { +freeform_tags = { environment = "dev" lob = "finance" -} \ No newline at end of file +} + +# gateways parameters + +drg_display_name = "drg" +internet_gateway_display_name = "igw" +nat_gateway_display_name = "ngw" +service_gateway_display_name = "sgw" diff --git a/examples/variables.tf b/examples/module_composition/variables.tf similarity index 83% rename from examples/variables.tf rename to examples/module_composition/variables.tf index 9b93ef2..b159ee0 100644 --- a/examples/variables.tf +++ b/examples/module_composition/variables.tf @@ -55,7 +55,7 @@ variable "create_drg" { default = false } -variable "internet_gateway_enabled" { +variable "create_internet_gateway" { description = "whether to create the internet gateway" type = bool default = false @@ -67,23 +67,23 @@ variable "lockdown_default_seclist" { default = false } -variable "nat_gateway_enabled" { +variable "create_nat_gateway" { description = "whether to create a nat gateway in the vcn" type = bool default = false } -variable "service_gateway_enabled" { +variable "create_service_gateway" { description = "whether to create a service gateway" type = bool default = false } -variable "tags" { +variable "freeform_tags" { description = "simple key-value pairs to tag the resources created" type = map(any) default = { - terraformed = "yes" + terraformed = "please do not edit manually" module = "oracle-terraform-modules/vcn/oci" } } @@ -113,3 +113,22 @@ variable "drg_display_name" { type = string default = "drg" } + +variable "internet_gateway_display_name" { + description = "(Updatable) Name of Internet Gateway. Does not have to be unique." + type = string + default = "igw" +} + +variable "nat_gateway_display_name" { + description = "(Updatable) Name of NAT Gateway. Does not have to be unique." + type = string + default = "ngw" +} + +variable "service_gateway_display_name" { + description = "(Updatable) Name of Service Gateway. Does not have to be unique." + type = string + default = "sgw" +} + diff --git a/schema.yaml b/schema.yaml index a4b8456..3417739 100644 --- a/schema.yaml +++ b/schema.yaml @@ -17,7 +17,7 @@ variables: title: Region description: The OCI region where resources will be created required: true - + compartment_id: type: oci:identity:compartment:id title: Target Compartment @@ -31,10 +31,10 @@ variables: required: false default: dev - vcn_cidr: - type: string + vcn_cidrs: + type: list(string) title: VCN CIDR - default: 10.0.0.0/16 + default: ["10.0.0.0/16"] required: true vcn_name: @@ -55,6 +55,6 @@ variables: required: false default: true - tags: + freeform_tags: type: map visible: false diff --git a/terraform.tfvars.example b/terraform.tfvars.example index ecf6946..9f4c69c 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -12,21 +12,21 @@ compartment_id = "" label_prefix = "none" # vcn parameters -internet_gateway_enabled = false +create_internet_gateway = false -nat_gateway_enabled = false +create_nat_gateway = false nat_gateway_public_ip_id = "none" -service_gateway_enabled = false +create_service_gateway = false -vcn_cidr = "10.0.0.0/16" +vcn_cidrs = ["10.0.0.0/16"] vcn_dns_label = "vcn" vcn_name = "vcn" -tags = { +freeform_tags = { environment = "dev" } diff --git a/variables.tf b/variables.tf index a1abb96..e10cd6b 100644 --- a/variables.tf +++ b/variables.tf @@ -24,12 +24,11 @@ variable "label_prefix" { default = "none" } -variable "tags" { - #! Deprecation notice: will be renamed to freeform_tags at next major release - description = "simple key-value pairs to tag the resources created using freeform tags." +variable "freeform_tags" { + description = "simple key-value pairs to tag the resources created using freeform freeform_tags." type = map(any) default = { - terraformed = "yes" + terraformed = "Please do not edit manually" module = "oracle-terraform-modules/vcn/oci" } } @@ -42,8 +41,7 @@ variable "create_drg" { default = false } -variable "internet_gateway_enabled" { - #! Deprecation notice: will be renamed to create_internet_gateway at next major release +variable "create_internet_gateway" { description = "whether to create the internet gateway in the vcn. If set to true, creates an Internet Gateway." default = false type = bool @@ -61,8 +59,7 @@ variable "lockdown_default_seclist" { type = bool } -variable "nat_gateway_enabled" { - #! Deprecation notice: will be renamed to create_nat_gateway at next major release +variable "create_nat_gateway" { description = "whether to create a nat gateway in the vcn. If set to true, creates a nat gateway." default = false type = bool @@ -74,8 +71,7 @@ variable "nat_gateway_public_ip_id" { type = string } -variable "service_gateway_enabled" { - #! Deprecation notice: will be renamed to create_service_gateway at next major release +variable "create_service_gateway" { description = "whether to create a service gateway. If set to true, creates a service gateway." default = false type = bool @@ -102,29 +98,55 @@ variable "vcn_name" { variable "drg_display_name" { description = "(Updatable) Name of Dynamic Routing Gateway. Does not have to be unique." type = string - default = null + default = "drg" + + validation { + condition = length(var.drg_display_name) > 0 + error_message = "The drg_display_name value cannot be an empty string." + } +} + +variable "internet_gateway_display_name" { + description = "(Updatable) Name of Internet Gateway. Does not have to be unique." + type = string + default = "internet-gateway" + + validation { + condition = length(var.internet_gateway_display_name) > 0 + error_message = "The internet_gateway_display_name value cannot be an empty string." + } } -# routing rules +variable "nat_gateway_display_name" { + description = "(Updatable) Name of NAT Gateway. Does not have to be unique." + type = string + default = "nat-gateway" + + validation { + condition = length(var.nat_gateway_display_name) > 0 + error_message = "The nat_gateway_display_name value cannot be an empty string." + } +} + +variable "service_gateway_display_name" { + description = "(Updatable) Name of Service Gateway. Does not have to be unique." + type = string + default = "service-gateway" + + validation { + condition = length(var.service_gateway_display_name) > 0 + error_message = "The service_gateway_display_name value cannot be an empty string." + } +} variable "internet_gateway_route_rules" { description = "(Updatable) List of routing rules to add to Internet Gateway Route Table" - type = list(object({ - destination = string - destination_type = string - network_entity_id = string - description = string - })) - default = null + type = list(map(string)) + default = null } variable "nat_gateway_route_rules" { - description = "(Updatable) List of routing rules to add to NAT Gateway Route Table" - type = list(object({ - destination = string - destination_type = string - network_entity_id = string - description = string - })) - default = null + description = "(Updatable) list of routing rules to add to NAT Gateway Route Table" + type = list(map(string)) + default = null } diff --git a/vcn.tf b/vcn.tf index 5bf7a38..66213f2 100644 --- a/vcn.tf +++ b/vcn.tf @@ -3,11 +3,11 @@ resource "oci_core_vcn" "vcn" { # We still allow module users to declare a cidr using `vcn_cidr` instead of the now recommended `vcn_cidrs`, but internally we map both to `cidr_blocks` - # The module always use the new list of string structure and let the customer update his module definition block at his own pace. + # The module always use the new list of string structure and let the customer update his module definition block at his own pace. cidr_blocks = var.vcn_cidrs[*] compartment_id = var.compartment_id display_name = var.label_prefix == "none" ? var.vcn_name : "${var.label_prefix}-${var.vcn_name}" dns_label = var.vcn_dns_label - freeform_tags = var.tags + freeform_tags = var.freeform_tags } diff --git a/vcn_gateways.tf b/vcn_gateways.tf index 8d25d8b..a915652 100644 --- a/vcn_gateways.tf +++ b/vcn_gateways.tf @@ -7,20 +7,20 @@ resource "oci_core_internet_gateway" "ig" { compartment_id = var.compartment_id - display_name = var.label_prefix == "none" ? "internet-gateway" : "${var.label_prefix}-internet-gateway" + display_name = var.label_prefix == "none" ? var.internet_gateway_display_name : "${var.label_prefix}-${var.internet_gateway_display_name}" - freeform_tags = var.tags + freeform_tags = var.freeform_tags vcn_id = oci_core_vcn.vcn.id - count = var.internet_gateway_enabled == true ? 1 : 0 + count = var.create_internet_gateway == true ? 1 : 0 } resource "oci_core_route_table" "ig" { compartment_id = var.compartment_id display_name = var.label_prefix == "none" ? "internet-route" : "${var.label_prefix}-internet-route" - freeform_tags = var.tags + freeform_tags = var.freeform_tags route_rules { # * With this route table, Internet Gateway is always declared as the default gateway @@ -74,7 +74,7 @@ resource "oci_core_route_table" "ig" { vcn_id = oci_core_vcn.vcn.id - count = var.internet_gateway_enabled == true ? 1 : 0 + count = var.create_internet_gateway == true ? 1 : 0 } ####################### @@ -86,21 +86,21 @@ data "oci_core_services" "all_oci_services" { values = ["All .* Services In Oracle Services Network"] regex = true } - count = var.service_gateway_enabled == true ? 1 : 0 + count = var.create_service_gateway == true ? 1 : 0 } resource "oci_core_service_gateway" "service_gateway" { compartment_id = var.compartment_id - display_name = var.label_prefix == "none" ? "service-gateway" : "${var.label_prefix}-service-gateway" + display_name = var.label_prefix == "none" ? var.service_gateway_display_name : "${var.label_prefix}-${var.service_gateway_display_name}" - freeform_tags = var.tags + freeform_tags = var.freeform_tags services { service_id = lookup(data.oci_core_services.all_oci_services[0].services[0], "id") } vcn_id = oci_core_vcn.vcn.id - count = var.service_gateway_enabled == true ? 1 : 0 + count = var.create_service_gateway == true ? 1 : 0 } ################### @@ -108,22 +108,22 @@ resource "oci_core_service_gateway" "service_gateway" { ################### resource "oci_core_nat_gateway" "nat_gateway" { compartment_id = var.compartment_id - display_name = var.label_prefix == "none" ? "nat-gateway" : "${var.label_prefix}-nat-gateway" + display_name = var.label_prefix == "none" ? var.nat_gateway_display_name : "${var.label_prefix}-${var.nat_gateway_display_name}" - freeform_tags = var.tags + freeform_tags = var.freeform_tags public_ip_id = var.nat_gateway_public_ip_id != "none" ? var.nat_gateway_public_ip_id : null vcn_id = oci_core_vcn.vcn.id - count = var.nat_gateway_enabled == true ? 1 : 0 + count = var.create_nat_gateway == true ? 1 : 0 } resource "oci_core_route_table" "nat" { compartment_id = var.compartment_id display_name = var.label_prefix == "none" ? "nat-route" : "${var.label_prefix}-nat-route" - freeform_tags = var.tags + freeform_tags = var.freeform_tags route_rules { # * With this route table, NAT Gateway is always declared as the default gateway @@ -135,7 +135,7 @@ resource "oci_core_route_table" "nat" { dynamic "route_rules" { # * If Service Gateway is created with the module, automatically creates a rule to handle traffic for "all services" through Service Gateway - for_each = var.service_gateway_enabled == true ? [1] : [] + for_each = var.create_service_gateway == true ? [1] : [] content { destination = lookup(data.oci_core_services.all_oci_services[0].services[0], "cidr_block") @@ -190,7 +190,7 @@ resource "oci_core_route_table" "nat" { vcn_id = oci_core_vcn.vcn.id - count = var.nat_gateway_enabled == true ? 1 : 0 + count = var.create_nat_gateway == true ? 1 : 0 } ############################### @@ -199,16 +199,19 @@ resource "oci_core_route_table" "nat" { resource "oci_core_drg" "drg" { compartment_id = var.compartment_id - display_name = var.label_prefix == "none" ? var.drg_display_name : "${var.label_prefix}-drg" + display_name = var.label_prefix == "none" ? var.drg_display_name : "${var.label_prefix}-${var.drg_display_name}" - freeform_tags = var.tags + 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 - vcn_id = oci_core_vcn.vcn.id + drg_id = oci_core_drg.drg[count.index].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}" + + freeform_tags = var.freeform_tags count = var.create_drg == true ? 1 : 0 } @@ -222,7 +225,7 @@ resource "oci_core_local_peering_gateway" "lpg" { compartment_id = var.compartment_id display_name = var.label_prefix == "none" ? each.key : "${var.label_prefix}-${each.key}" - freeform_tags = var.tags + freeform_tags = var.freeform_tags vcn_id = oci_core_vcn.vcn.id diff --git a/versions.tf b/versions.tf index 49a723b..14a3a80 100644 --- a/versions.tf +++ b/versions.tf @@ -2,7 +2,7 @@ terraform { required_providers { oci = { source = "hashicorp/oci" - version = ">=4.0.0" + version = ">=4.41.0" } } required_version = ">= 1.0.0"