Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions mmv1/products/compute/Address.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
collection_url_key: 'items'
include_in_tgc_next: true
custom_code:
constants: 'templates/terraform/constants/compute_address.go.tmpl'
post_create: 'templates/terraform/post_create/labels.tmpl'
sweeper:
url_substitutions:
Expand Down Expand Up @@ -78,7 +79,7 @@
primary_resource_id: 'internal_with_shared_loadbalancer_vip'
vars:
address_name: 'my-internal-address'
# It is almost identical to internal_with_gce_endpoint

Check warning on line 82 in mmv1/products/compute/Address.yaml

View workflow job for this annotation

GitHub Actions / lint-yaml

82:2 [comments-indentation] comment not indented like content
exclude_docs: true
# TODO: Remove this example when instance is supported
- name: 'instance_with_ip'
Expand All @@ -91,6 +92,16 @@
vars:
address_name: 'test-address'
network_name: 'test-network'
- name: 'compute_address_enhanced_byoip'
primary_resource_id: 'default'
vars:
address_name: 'test-address'
sub_pdp_name: 'test-sub-pdp'
sub_pdp_ip_cidr: '"136.124.3.120/32"'
root_pdp_url: '"projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/tf-enhanced-pdp-136-124-3-120-29"'
test_vars_overrides:
sub_pdp_ip_cidr: 'fmt.Sprintf("136.124.3.%d/32", 120 + acctest.RandIntRange(t, 0, 7))'
root_pdp_url: '"projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/tf-enhanced-pdp-136-124-3-120-29"'
parameters:
- name: 'region'
type: ResourceRef
Expand Down Expand Up @@ -236,3 +247,15 @@
enum_values:
- 'VM'
- 'NETLB'
- name: ipCollection
type: String
diff_suppress_func: 'AddressIpCollectionDiffSuppress'
description: |
Reference to the source of external IPv4 addresses, like a PublicDelegatedPrefix(PDP) for BYOIP.
The PDP must support enhanced IPv4 allocations.
Use one of the following formats to specify a PDP when reserving an external IPv4 address using BYOIP.
Full resource URL, as in:
* `https://www.googleapis.com/compute/v1/projects/{{projectId}}/regions/{{region}}/publicDelegatedPrefixes/{{pdp-name}}`
Partial URL, as in:
* `projects/{{projectId}}/regions/region/publicDelegatedPrefixes/{{pdp-name}}`
* `regions/{{region}}/publicDelegatedPrefixes/{{pdp-name}}`
12 changes: 12 additions & 0 deletions mmv1/products/compute/PublicDelegatedPrefix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ properties:
enum_values:
- 'EXTERNAL'
- 'INTERNAL'
- name: 'enableEnhancedIpv4Allocation'
type: Boolean
description: |
Whether this PublicDelegatedPrefix supports enhanced IPv4 allocations.
Applicable for IPv4 PDPs only.
output: true
- name: 'publicDelegatedSubPrefixs'
type: Array
output: true
Expand Down Expand Up @@ -216,6 +222,12 @@ properties:
enum_values:
- 'EXTERNAL'
- 'INTERNAL'
- name: 'enableEnhancedIpv4Allocation'
type: Boolean
description: |
Whether this PublicDelegatedSubPrefix supports enhanced IPv4 allocations.
Applicable for IPv4 sub-PDPs only.
output: true
- name: 'delegateeProject'
type: String
description: |
Expand Down
26 changes: 26 additions & 0 deletions mmv1/templates/terraform/constants/compute_address.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Compare only the relative path from 'regions' of two IP collection links
func AddressIpCollectionDiffSuppress(_, old, new string, d *schema.ResourceData) bool {
oldStripped, err := GetRelativePath(old)
if err != nil {
return false
}

newStripped, err := GetRelativePath(new)
if err != nil {
return false
}

if oldStripped == newStripped {
return true
}
return false
}

func GetRelativePath(resourceLink string) (string, error) {
stringParts := strings.SplitAfterN(resourceLink, "regions/", 2)
if len(stringParts) != 2 {
return "", fmt.Errorf("String is not a valid link: %s", resourceLink)
}

return "regions/" + stringParts[1], nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "google_compute_address" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "address_name"}}"
region = "us-central1"
ip_collection = google_compute_public_delegated_prefix.sub_pdp.self_link
}

resource "google_compute_public_delegated_prefix" "sub_pdp" {
name = "{{index $.Vars "sub_pdp_name"}}"
region = "us-central1"
ip_cidr_range = "{{index $.Vars "sub_pdp_ip_cidr"}}"
parent_prefix = "{{index $.Vars "root_pdp_url"}}"
}

Loading