Skip to content

Commit e717edd

Browse files
mclavelMarcelo Clavel
authored andcommitted
feat: support reserved_internal_range
1 parent 26624fe commit e717edd

File tree

18 files changed

+63
-22
lines changed

18 files changed

+63
-22
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ module "vpc" {
7373
range_name = "subnet-01-secondary-01"
7474
ip_cidr_range = "192.168.64.0/24"
7575
},
76+
{
77+
range_name = "subnet-01-secondary-02"
78+
reserved_internal_range = "networkconnectivity.googleapis.com/projects/my-project/locations/global/internalRanges/my-range"
79+
},
7680
]
7781
7882
subnet-02 = []
@@ -128,7 +132,7 @@ Then perform the following commands on the root folder:
128132
| project\_id | The ID of the project where this VPC will be created | `string` | n/a | yes |
129133
| routes | List of routes being created in this VPC | `list(map(string))` | `[]` | no |
130134
| routing\_mode | The network routing mode (default 'GLOBAL') | `string` | `"GLOBAL"` | no |
131-
| secondary\_ranges | Secondary ranges that will be used in some of the subnets | `map(list(object({ range_name = string, ip_cidr_range = string })))` | `{}` | no |
135+
| secondary\_ranges | Secondary ranges that will be used in some of the subnets | `map(list(object({ range_name = string, ip_cidr_range = optional(string), reserved_internal_range = optional(string) })))` | `{}` | no |
132136
| shared\_vpc\_host | Makes this project a Shared VPC host if 'true' (default 'false') | `bool` | `false` | no |
133137
| subnets | The list of subnets being created | <pre>list(object({<br> subnet_name = string<br> subnet_ip = string<br> subnet_region = string<br> subnet_private_access = optional(string)<br> subnet_private_ipv6_access = optional(string)<br> subnet_flow_logs = optional(string)<br> subnet_flow_logs_interval = optional(string)<br> subnet_flow_logs_sampling = optional(string)<br> subnet_flow_logs_metadata = optional(string)<br> subnet_flow_logs_filter = optional(string)<br> subnet_flow_logs_metadata_fields = optional(list(string))<br> description = optional(string)<br> purpose = optional(string)<br> role = optional(string)<br> stack_type = optional(string)<br> ipv6_access_type = optional(string)<br> }))</pre> | n/a | yes |
134138

examples/secondary_ranges/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ ranges and the third being given a single secondary range.
1717

1818
| Name | Description |
1919
|------|-------------|
20+
| internal\_range\_id | The ID of the created internal range |
21+
| internal\_range\_name | The name of the created internal range |
2022
| network\_name | The name of the VPC being created |
2123
| network\_self\_link | The URI of the VPC being created |
2224
| project\_id | VPC project id |

examples/secondary_ranges/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ module "vpc-secondary-ranges" {
7676
range_name = "${local.subnet_03}-01"
7777
ip_cidr_range = "192.168.66.0/24"
7878
},
79+
{
80+
range_name = "${local.subnet_03}-02"
81+
reserved_internal_range = "networkconnectivity.googleapis.com/${google_network_connectivity_internal_range.internal_range.id}"
82+
},
7983
]
8084
}
8185

@@ -103,3 +107,13 @@ module "vpc-secondary-ranges" {
103107
},
104108
]
105109
}
110+
111+
resource "google_network_connectivity_internal_range" "internal_range" {
112+
project = var.project_id
113+
name = "${var.network_name}-internal-range"
114+
description = "Example internal range for secondary subnet ranges"
115+
ip_cidr_range = "172.16.0.0/24"
116+
network = module.vpc-secondary-ranges.network_id
117+
usage = "FOR_VPC"
118+
peering = "FOR_SELF"
119+
}

examples/secondary_ranges/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ output "route_names" {
6363
value = module.vpc-secondary-ranges.route_names
6464
description = "The routes associated with this VPC"
6565
}
66+
67+
output "internal_range_id" {
68+
value = google_network_connectivity_internal_range.internal_range.id
69+
description = "The ID of the created internal range"
70+
}
71+
72+
output "internal_range_name" {
73+
value = google_network_connectivity_internal_range.internal_range.name
74+
description = "The name of the created internal range"
75+
}

examples/secondary_ranges/versions.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ terraform {
1919

2020
required_providers {
2121
google = {
22-
source = "hashicorp/google"
22+
source = "hashicorp/google"
23+
version = ">= 6.0"
2324
}
2425
null = {
2526
version = ">= 3.0"

metadata.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ spec:
158158
required: true
159159
- name: secondary_ranges
160160
description: Secondary ranges that will be used in some of the subnets
161-
varType: map(list(object({ range_name = string, ip_cidr_range = string })))
161+
varType: map(list(object({ range_name = string, ip_cidr_range = optional(string), reserved_internal_range = optional(string) })))
162162
defaultValue: {}
163163
- name: routes
164164
description: List of routes being created in this VPC
@@ -354,6 +354,6 @@ spec:
354354
- servicenetworking.googleapis.com
355355
providerVersions:
356356
- source: hashicorp/google
357-
version: ">= 4.64, < 8"
357+
version: ">= 6.0, < 8"
358358
- source: hashicorp/google-beta
359-
version: ">= 4.64, < 8"
359+
version: ">= 6.0, < 8"

modules/subnets-beta/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ module "vpc" {
5252
range_name = "subnet-01-secondary-01"
5353
ip_cidr_range = "192.168.64.0/24"
5454
},
55+
{
56+
range_name = "subnet-01-secondary-02"
57+
reserved_internal_range = "networkconnectivity.googleapis.com/projects/my-project/locations/global/internalRanges/my-range"
58+
},
5559
]
5660
5761
subnet-02 = []
@@ -67,7 +71,7 @@ module "vpc" {
6771
| module\_depends\_on | List of modules or resources this module depends on. | `list(any)` | `[]` | no |
6872
| network\_name | The name of the network where subnets will be created | `string` | n/a | yes |
6973
| project\_id | The ID of the project where subnets will be created | `string` | n/a | yes |
70-
| secondary\_ranges | Secondary ranges that will be used in some of the subnets | `map(list(object({ range_name = string, ip_cidr_range = string })))` | `{}` | no |
74+
| secondary\_ranges | Secondary ranges that will be used in some of the subnets | `map(list(object({ range_name = string, ip_cidr_range = optional(string), reserved_internal_range = optional(string) })))` | `{}` | no |
7175
| subnets | The list of subnets being created | <pre>list(object({<br> subnet_name = string<br> subnet_ip = string<br> subnet_region = string<br> subnet_private_access = optional(string, "false")<br> subnet_private_ipv6_access = optional(string)<br> subnet_flow_logs = optional(bool, false)<br> subnet_flow_logs_interval = optional(string, "INTERVAL_5_SEC")<br> subnet_flow_logs_sampling = optional(string, "0.5")<br> subnet_flow_logs_metadata = optional(string, "INCLUDE_ALL_METADATA")<br> subnet_flow_logs_filter = optional(string, "true")<br> subnet_flow_logs_metadata_fields = optional(list(string), [])<br> description = optional(string)<br> purpose = optional(string)<br> role = optional(string)<br> stack_type = optional(string)<br> ipv6_access_type = optional(string)<br> }))</pre> | n/a | yes |
7276

7377
## Outputs

modules/subnets-beta/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ resource "google_compute_subnetwork" "subnetwork" {
5656
for_each = contains(keys(var.secondary_ranges), each.value.subnet_name) == true ? var.secondary_ranges[each.value.subnet_name] : []
5757

5858
content {
59-
range_name = secondary_ip_range.value.range_name
60-
ip_cidr_range = secondary_ip_range.value.ip_cidr_range
59+
range_name = secondary_ip_range.value.range_name
60+
ip_cidr_range = secondary_ip_range.value.ip_cidr_range
61+
reserved_internal_range = secondary_ip_range.value.reserved_internal_range
6162
}
6263
}
6364

modules/subnets-beta/metadata.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ spec:
122122
required: true
123123
- name: secondary_ranges
124124
description: Secondary ranges that will be used in some of the subnets
125-
varType: map(list(object({ range_name = string, ip_cidr_range = string })))
125+
varType: map(list(object({ range_name = string, ip_cidr_range = optional(string), reserved_internal_range = optional(string) })))
126126
defaultValue: {}
127127
- name: module_depends_on
128128
description: List of modules or resources this module depends on.
@@ -161,4 +161,4 @@ spec:
161161
- servicenetworking.googleapis.com
162162
providerVersions:
163163
- source: hashicorp/google-beta
164-
version: ">= 2.19, < 8"
164+
version: ">= 6.0, < 8"

modules/subnets-beta/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ variable "subnets" {
4747
}
4848

4949
variable "secondary_ranges" {
50-
type = map(list(object({ range_name = string, ip_cidr_range = string })))
50+
type = map(list(object({ range_name = string, ip_cidr_range = optional(string), reserved_internal_range = optional(string) })))
5151
description = "Secondary ranges that will be used in some of the subnets"
5252
default = {}
5353
}

0 commit comments

Comments
 (0)