Skip to content

Commit 365b396

Browse files
onspskGvantsats
authored andcommitted
Add IpCollection to the Address resource (GoogleCloudPlatform#16070)
1 parent 867061d commit 365b396

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

mmv1/products/compute/Address.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ async:
5151
collection_url_key: 'items'
5252
include_in_tgc_next: true
5353
custom_code:
54+
constants: 'templates/terraform/constants/compute_address.go.tmpl'
5455
post_create: 'templates/terraform/post_create/labels.tmpl'
5556
sweeper:
5657
url_substitutions:
@@ -91,6 +92,16 @@ examples:
9192
vars:
9293
address_name: 'test-address'
9394
network_name: 'test-network'
95+
- name: 'compute_address_enhanced_byoip'
96+
primary_resource_id: 'default'
97+
vars:
98+
address_name: 'test-address'
99+
sub_pdp_name: 'test-sub-pdp'
100+
sub_pdp_ip_cidr: '"136.124.3.120/32"'
101+
root_pdp_url: '"projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/tf-enhanced-pdp-136-124-3-120-29"'
102+
test_vars_overrides:
103+
sub_pdp_ip_cidr: 'fmt.Sprintf("136.124.3.%d/32", 120 + acctest.RandIntRange(t, 0, 7))'
104+
root_pdp_url: '"projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/tf-enhanced-pdp-136-124-3-120-29"'
94105
parameters:
95106
- name: 'region'
96107
type: ResourceRef
@@ -236,3 +247,15 @@ properties:
236247
enum_values:
237248
- 'VM'
238249
- 'NETLB'
250+
- name: ipCollection
251+
type: String
252+
diff_suppress_func: 'AddressIpCollectionDiffSuppress'
253+
description: |
254+
Reference to the source of external IPv4 addresses, like a PublicDelegatedPrefix(PDP) for BYOIP.
255+
The PDP must support enhanced IPv4 allocations.
256+
Use one of the following formats to specify a PDP when reserving an external IPv4 address using BYOIP.
257+
Full resource URL, as in:
258+
* `https://www.googleapis.com/compute/v1/projects/{{projectId}}/regions/{{region}}/publicDelegatedPrefixes/{{pdp-name}}`
259+
Partial URL, as in:
260+
* `projects/{{projectId}}/regions/region/publicDelegatedPrefixes/{{pdp-name}}`
261+
* `regions/{{region}}/publicDelegatedPrefixes/{{pdp-name}}`

mmv1/products/compute/PublicDelegatedPrefix.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ properties:
150150
enum_values:
151151
- 'EXTERNAL'
152152
- 'INTERNAL'
153+
- name: 'enableEnhancedIpv4Allocation'
154+
type: Boolean
155+
description: |
156+
Whether this PublicDelegatedPrefix supports enhanced IPv4 allocations.
157+
Applicable for IPv4 PDPs only.
158+
output: true
153159
- name: 'publicDelegatedSubPrefixs'
154160
type: Array
155161
output: true
@@ -216,6 +222,12 @@ properties:
216222
enum_values:
217223
- 'EXTERNAL'
218224
- 'INTERNAL'
225+
- name: 'enableEnhancedIpv4Allocation'
226+
type: Boolean
227+
description: |
228+
Whether this PublicDelegatedSubPrefix supports enhanced IPv4 allocations.
229+
Applicable for IPv4 sub-PDPs only.
230+
output: true
219231
- name: 'delegateeProject'
220232
type: String
221233
description: |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Compare only the relative path from 'regions' of two IP collection links
2+
func AddressIpCollectionDiffSuppress(_, old, new string, d *schema.ResourceData) bool {
3+
oldStripped, err := GetRelativePath(old)
4+
if err != nil {
5+
return false
6+
}
7+
8+
newStripped, err := GetRelativePath(new)
9+
if err != nil {
10+
return false
11+
}
12+
13+
if oldStripped == newStripped {
14+
return true
15+
}
16+
return false
17+
}
18+
19+
func GetRelativePath(resourceLink string) (string, error) {
20+
stringParts := strings.SplitAfterN(resourceLink, "regions/", 2)
21+
if len(stringParts) != 2 {
22+
return "", fmt.Errorf("String is not a valid link: %s", resourceLink)
23+
}
24+
25+
return "regions/" + stringParts[1], nil
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "google_compute_address" "{{$.PrimaryResourceId}}" {
2+
name = "{{index $.Vars "address_name"}}"
3+
region = "us-central1"
4+
ip_collection = google_compute_public_delegated_prefix.sub_pdp.self_link
5+
}
6+
7+
resource "google_compute_public_delegated_prefix" "sub_pdp" {
8+
name = "{{index $.Vars "sub_pdp_name"}}"
9+
region = "us-central1"
10+
ip_cidr_range = "{{index $.Vars "sub_pdp_ip_cidr"}}"
11+
parent_prefix = "{{index $.Vars "root_pdp_url"}}"
12+
}
13+

0 commit comments

Comments
 (0)