Skip to content

Commit 451c131

Browse files
feat: Add support for setting purpose, network_tier, prefix_length, and ip_version (#29)
1 parent 8e0d0bd commit 451c131

File tree

7 files changed

+87
-56
lines changed

7 files changed

+87
-56
lines changed

README.md

+22-19
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,30 @@ dreaded `value of 'count' cannot be computed` error. Future versions of
178178
Terraform may change this fact, but this is the current limitation.
179179

180180
[^]: (autogen_docs_start)
181-
182181
## Inputs
183182

184183
| Name | Description | Type | Default | Required |
185-
|------|-------------|:----:|:-----:|:-----:|
186-
| address\_type | The type of address to reserve, either "INTERNAL" or "EXTERNAL". If unspecified, defaults to "INTERNAL". | string | `"INTERNAL"` | no |
187-
| addresses | A list of IP addresses to create. GCP will reserve unreserved addresses if given the value "". If multiple names are given the default value is sufficient to have multiple addresses automatically picked for each name. | list | `<list>` | no |
188-
| dns\_domain | The domain to append to DNS short names when registering in Cloud DNS. | string | `""` | no |
189-
| dns\_managed\_zone | The name of the managed zone to create records within. This managed zone must exist in the host project. | string | `""` | no |
190-
| dns\_project | The project where DNS A records will be configured. | string | `""` | no |
191-
| dns\_record\_type | The type of records to create in the managed zone. (e.g. "A") | string | `"A"` | no |
192-
| dns\_reverse\_zone | The name of the managed zone to create PTR records within. This managed zone must exist in the host project. | string | `""` | no |
193-
| dns\_short\_names | A list of DNS short names to register within Cloud DNS. Names corresponding to addresses must align by their list index position in the two input variables, `names` and `dns_short_names`. If an empty list, no domain names are registered. Multiple names may be registered to the same address by passing a single element list to names and multiple elements to dns_short_names. (e.g. ["gusw1-dev-fooapp-fe-0001-a-001"]) | list | `<list>` | no |
194-
| dns\_ttl | The DNS TTL in seconds for records created in Cloud DNS. The default value should be used unless the application demands special handling. | string | `"300"` | no |
195-
| enable\_cloud\_dns | If a value is set, register records in Cloud DNS. | string | `""` | no |
196-
| enable\_reverse\_dns | If a value is set, register reverse DNS PTR records in Cloud DNS in the managed zone specified by dns_reverse_zone | string | `""` | no |
197-
| global | The scope in which the address should live. If set to true, the IP address will be globally scoped. Defaults to false, i.e. regionally scoped. When set to true, do not provide a subnetwork. | string | `"false"` | no |
198-
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | list | `<list>` | no |
199-
| project\_id | The project ID to create the address in | string | n/a | yes |
200-
| region | The region to create the address in | string | n/a | yes |
201-
| subnetwork | The subnet containing the address. For EXTERNAL addresses use the empty string, "". (e.g. "projects/<project-name>/regions/<region-name>/subnetworks/<subnetwork-name>") | string | `""` | no |
184+
|------|-------------|------|---------|:--------:|
185+
| address\_type | The type of address to reserve, either "INTERNAL" or "EXTERNAL". If unspecified, defaults to "INTERNAL". | `string` | `"INTERNAL"` | no |
186+
| addresses | A list of IP addresses to create. GCP will reserve unreserved addresses if given the value "". If multiple names are given the default value is sufficient to have multiple addresses automatically picked for each name. | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
187+
| dns\_domain | The domain to append to DNS short names when registering in Cloud DNS. | `string` | `""` | no |
188+
| dns\_managed\_zone | The name of the managed zone to create records within. This managed zone must exist in the host project. | `string` | `""` | no |
189+
| dns\_project | The project where DNS A records will be configured. | `string` | `""` | no |
190+
| dns\_record\_type | The type of records to create in the managed zone. (e.g. "A") | `string` | `"A"` | no |
191+
| dns\_reverse\_zone | The name of the managed zone to create PTR records within. This managed zone must exist in the host project. | `string` | `""` | no |
192+
| dns\_short\_names | A list of DNS short names to register within Cloud DNS. Names corresponding to addresses must align by their list index position in the two input variables, `names` and `dns_short_names`. If an empty list, no domain names are registered. Multiple names may be registered to the same address by passing a single element list to names and multiple elements to dns\_short\_names. (e.g. ["gusw1-dev-fooapp-fe-0001-a-001"]) | `list(string)` | `[]` | no |
193+
| dns\_ttl | The DNS TTL in seconds for records created in Cloud DNS. The default value should be used unless the application demands special handling. | `number` | `300` | no |
194+
| enable\_cloud\_dns | If a value is set, register records in Cloud DNS. | `bool` | `false` | no |
195+
| enable\_reverse\_dns | If a value is set, register reverse DNS PTR records in Cloud DNS in the managed zone specified by dns\_reverse\_zone | `bool` | `false` | no |
196+
| global | The scope in which the address should live. If set to true, the IP address will be globally scoped. Defaults to false, i.e. regionally scoped. When set to true, do not provide a subnetwork. | `bool` | `false` | no |
197+
| ip\_version | The IP Version that will be used by this address. | `string` | `"IPV4"` | no |
198+
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | `list(string)` | `[]` | no |
199+
| network\_tier | The networking tier used for configuring this address. | `string` | `"PREMIUM"` | no |
200+
| prefix\_length | The prefix length of the IP range. | `number` | `16` | no |
201+
| project\_id | The project ID to create the address in | `string` | n/a | yes |
202+
| purpose | The purpose of the resource(GCE\_ENDPOINT, SHARED\_LOADBALANCER\_VIP, VPC\_PEERING). | `string` | `"GCE_ENDPOINT"` | no |
203+
| region | The region to create the address in | `string` | n/a | yes |
204+
| subnetwork | The subnet containing the address. For EXTERNAL addresses use the empty string, "". (e.g. "projects/<project-name>/regions/<region-name>/subnetworks/<subnetwork-name>") | `string` | `""` | no |
202205

203206
## Outputs
204207

@@ -208,7 +211,7 @@ Terraform may change this fact, but this is the current limitation.
208211
| dns\_fqdns | List of DNS fully qualified domain names registered in Cloud DNS. (e.g. ["gusw1-dev-fooapp-fe-0001-a-001.example.com", "gusw1-dev-fooapp-fe-0001-a-0002.example.com"]) |
209212
| names | List of address resource names managed by this module (e.g. ["gusw1-dev-fooapp-fe-0001-a-0001-ip"]) |
210213
| reverse\_dns\_fqdns | List of reverse DNS PTR records registered in Cloud DNS. (e.g. ["1.2.11.10.in-addr.arpa", "2.2.11.10.in-addr.arpa"]) |
211-
| self\_links | List of URIs of the created address resources (e.g. ["https://www.googleapis.com/compute/v1/projects/project-abcde/regions/europe-west1/addresses/gusw1-dev-fooapp-fe-0001-a-0001-ip"] |
214+
| self\_links | List of URIs of the created address resources |
212215

213216
[^]: (autogen_docs_end)
214217

examples/dns_forward_and_reverse/README.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ time, and how to enable the Google Cloud DNS registration functionality for
55
both forward and reverse DNS lookup zones.
66

77
[^]: (autogen_docs_start)
8-
98
## Inputs
109

1110
| Name | Description | Type | Default | Required |
12-
|------|-------------|:----:|:-----:|:-----:|
13-
| dns\_domain | The name of the domain to be registered with Cloud DNS | string | n/a | yes |
14-
| dns\_managed\_zone | The name of the managed zone to create records within. This managed zone must exist in the host project. | string | n/a | yes |
15-
| dns\_project | The project where DNS A records will be configured. | string | n/a | yes |
16-
| dns\_reverse\_zone | The name of the managed zone to create PTR records within. This managed zone must exist in the host project. | string | n/a | yes |
17-
| dns\_short\_names | A list of DNS short names to register within Cloud DNS. Names corresponding to addresses must align by their list index position in the two input variables, `names` and `dns_short_names`. If an empty list, no domain names are registered. Multiple names may be registered to the same address by passing a single element list to names and multiple elements to dns_short_names. (e.g. ["gusw1-dev-fooapp-fe-0001-a-001"]) | list | n/a | yes |
18-
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | list | n/a | yes |
19-
| project\_id | The project ID to deploy to | string | n/a | yes |
20-
| region | The region to deploy to | string | n/a | yes |
21-
| subnetwork | The subnet containing the address. For EXTERNAL addresses use the empty string, "". (e.g. "projects/<project-name>/regions/<region-name>/subnetworks/<subnetwork-name>") | string | n/a | yes |
11+
|------|-------------|------|---------|:--------:|
12+
| dns\_domain | The name of the domain to be registered with Cloud DNS | `string` | n/a | yes |
13+
| dns\_managed\_zone | The name of the managed zone to create records within. This managed zone must exist in the host project. | `string` | n/a | yes |
14+
| dns\_project | The project where DNS A records will be configured. | `string` | n/a | yes |
15+
| dns\_reverse\_zone | The name of the managed zone to create PTR records within. This managed zone must exist in the host project. | `string` | n/a | yes |
16+
| dns\_short\_names | A list of DNS short names to register within Cloud DNS. Names corresponding to addresses must align by their list index position in the two input variables, `names` and `dns_short_names`. If an empty list, no domain names are registered. Multiple names may be registered to the same address by passing a single element list to names and multiple elements to dns\_short\_names. (e.g. ["gusw1-dev-fooapp-fe-0001-a-001"]) | `list(string)` | n/a | yes |
17+
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | `list(string)` | n/a | yes |
18+
| project\_id | The project ID to deploy to | `string` | n/a | yes |
19+
| region | The region to deploy to | `string` | n/a | yes |
20+
| subnetwork | The subnet containing the address. For EXTERNAL addresses use the empty string, "". (e.g. "projects/<project-name>/regions/<region-name>/subnetworks/<subnetwork-name>") | `string` | n/a | yes |
2221

2322
## Outputs
2423

examples/dns_forward_example/README.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ will register the IP addresses and their corresponding DNS names with Google
66
Cloud DNS.
77

88
[^]: (autogen_docs_start)
9-
109
## Inputs
1110

1211
| Name | Description | Type | Default | Required |
13-
|------|-------------|:----:|:-----:|:-----:|
14-
| dns\_domain | The name of the domain to be registered with Cloud DNS | string | n/a | yes |
15-
| dns\_managed\_zone | The name of the managed zone to create records within. This managed zone must exist in the host project. | string | n/a | yes |
16-
| dns\_project | The project where DNS A records will be configured. | string | n/a | yes |
17-
| dns\_short\_names | A list of DNS short names to register within Cloud DNS. Names corresponding to addresses must align by their list index position in the two input variables, `names` and `dns_short_names`. If an empty list, no domain names are registered. Multiple names may be registered to the same address by passing a single element list to names and multiple elements to dns_short_names. (e.g. ["gusw1-dev-fooapp-fe-0001-a-001"]) | list | n/a | yes |
18-
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | list | n/a | yes |
19-
| project\_id | The project ID to deploy to | string | n/a | yes |
20-
| region | The region to deploy to | string | n/a | yes |
21-
| subnetwork | The subnet containing the address. For EXTERNAL addresses use the empty string, "". (e.g. "projects/<project-name>/regions/<region-name>/subnetworks/<subnetwork-name>") | string | n/a | yes |
12+
|------|-------------|------|---------|:--------:|
13+
| dns\_domain | The name of the domain to be registered with Cloud DNS | `string` | n/a | yes |
14+
| dns\_managed\_zone | The name of the managed zone to create records within. This managed zone must exist in the host project. | `string` | n/a | yes |
15+
| dns\_project | The project where DNS A records will be configured. | `string` | n/a | yes |
16+
| dns\_short\_names | A list of DNS short names to register within Cloud DNS. Names corresponding to addresses must align by their list index position in the two input variables, `names` and `dns_short_names`. If an empty list, no domain names are registered. Multiple names may be registered to the same address by passing a single element list to names and multiple elements to dns\_short\_names. (e.g. ["gusw1-dev-fooapp-fe-0001-a-001"]) | `list(string)` | n/a | yes |
17+
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | `list(string)` | n/a | yes |
18+
| project\_id | The project ID to deploy to | `string` | n/a | yes |
19+
| region | The region to deploy to | `string` | n/a | yes |
20+
| subnetwork | The subnet containing the address. For EXTERNAL addresses use the empty string, "". (e.g. "projects/<project-name>/regions/<region-name>/subnetworks/<subnetwork-name>") | `string` | n/a | yes |
2221

2322
## Outputs
2423

examples/ip_address_only/README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ dynamically assigned by GCP. Outputs have been provided to list the address
55
itself as well as the resource name that corresponds.
66

77
[^]: (autogen_docs_start)
8-
98
## Inputs
109

1110
| Name | Description | Type | Default | Required |
12-
|------|-------------|:----:|:-----:|:-----:|
13-
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | list | n/a | yes |
14-
| project\_id | The project ID to deploy to | string | n/a | yes |
15-
| region | The region to deploy to | string | n/a | yes |
16-
| subnetwork | The subnetwork on which the IP address will be reserved | string | n/a | yes |
11+
|------|-------------|------|---------|:--------:|
12+
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | `list(string)` | n/a | yes |
13+
| project\_id | The project ID to deploy to | `string` | n/a | yes |
14+
| region | The region to deploy to | `string` | n/a | yes |
15+
| subnetwork | The subnetwork on which the IP address will be reserved | `string` | n/a | yes |
1716

1817
## Outputs
1918

examples/ip_address_with_specific_ip/README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ This example illustrates how to reserve a specific IP address (instead of
44
allowing GCP to dynamically assign it from the subnet provided).
55

66
[^]: (autogen_docs_start)
7-
87
## Inputs
98

109
| Name | Description | Type | Default | Required |
11-
|------|-------------|:----:|:-----:|:-----:|
12-
| addresses | A list of IP addresses to create. GCP will reserve unreserved addresses if given the value "". If multiple names are given the default value is sufficient to have multiple addresses automatically picked for each name. | list | n/a | yes |
13-
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | list | n/a | yes |
14-
| project\_id | The project ID to deploy to | string | n/a | yes |
15-
| region | The region to deploy to | string | n/a | yes |
16-
| subnetwork | The subnetwork on which the IP address will be reserved | string | n/a | yes |
10+
|------|-------------|------|---------|:--------:|
11+
| addresses | A list of IP addresses to create. GCP will reserve unreserved addresses if given the value "". If multiple names are given the default value is sufficient to have multiple addresses automatically picked for each name. | `list(string)` | n/a | yes |
12+
| names | A list of IP address resource names to create. This is the GCP resource name and not the associated hostname of the IP address. Existing resource names may be found with `gcloud compute addresses list` (e.g. ["gusw1-dev-fooapp-fe-0001-a-001-ip"]) | `list(string)` | n/a | yes |
13+
| project\_id | The project ID to deploy to | `string` | n/a | yes |
14+
| region | The region to deploy to | `string` | n/a | yes |
15+
| subnetwork | The subnetwork on which the IP address will be reserved | `string` | n/a | yes |
1716

1817
## Outputs
1918

main.tf

+12-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ locals {
3838
google_compute_global_address.global_ip.*.self_link,
3939
)
4040
dns_ptr_fqdns = data.template_file.ptrs.*.rendered
41+
prefix_length = var.address_type == "EXTERNAL" || (var.address_type == "INTERNAL" && var.purpose == "PRIVATE_SERVICE_CONNECT") ? null : var.prefix_length
4142
}
4243

4344
resource "null_resource" "dns_args_missing" {
@@ -83,12 +84,20 @@ resource "google_compute_address" "ip" {
8384
address = element(var.addresses, count.index)
8485
subnetwork = var.subnetwork
8586
address_type = var.address_type
87+
purpose = var.address_type == "INTERNAL" ? var.purpose : null
88+
network_tier = var.address_type == "INTERNAL" ? null : var.network_tier
8689
}
8790

8891
resource "google_compute_global_address" "global_ip" {
89-
count = local.global_addresses_count
90-
project = var.project_id
91-
name = var.names[count.index]
92+
count = local.global_addresses_count
93+
project = var.project_id
94+
name = var.names[count.index]
95+
address_type = var.address_type
96+
address = element(var.addresses, count.index)
97+
network = var.address_type == "EXTERNAL" ? null : var.subnetwork
98+
purpose = var.global && var.address_type == "INTERNAL" ? "VPC_PEERING" : null
99+
prefix_length = local.prefix_length
100+
ip_version = var.ip_version
92101
}
93102

94103
/******************************************

variables.tf

+23
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,26 @@ variable "enable_reverse_dns" {
106106
default = false
107107
}
108108

109+
variable "purpose" {
110+
type = string
111+
description = "The purpose of the resource(GCE_ENDPOINT, SHARED_LOADBALANCER_VIP, VPC_PEERING)."
112+
default = "GCE_ENDPOINT"
113+
}
114+
115+
variable "network_tier" {
116+
type = string
117+
description = "The networking tier used for configuring this address."
118+
default = "PREMIUM"
119+
}
120+
121+
variable "prefix_length" {
122+
type = number
123+
description = "The prefix length of the IP range."
124+
default = 16
125+
}
126+
127+
variable "ip_version" {
128+
type = string
129+
description = "The IP Version that will be used by this address."
130+
default = "IPV4"
131+
}

0 commit comments

Comments
 (0)