diff --git a/mmv1/products/compute/Address.yaml b/mmv1/products/compute/Address.yaml index 733646524c91..f50fa3a37baa 100644 --- a/mmv1/products/compute/Address.yaml +++ b/mmv1/products/compute/Address.yaml @@ -51,6 +51,7 @@ async: 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: @@ -91,6 +92,16 @@ examples: 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 @@ -236,3 +247,15 @@ properties: 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}}` diff --git a/mmv1/products/compute/PublicDelegatedPrefix.yaml b/mmv1/products/compute/PublicDelegatedPrefix.yaml index e01d4727958c..6c20e15cdf0a 100644 --- a/mmv1/products/compute/PublicDelegatedPrefix.yaml +++ b/mmv1/products/compute/PublicDelegatedPrefix.yaml @@ -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 @@ -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: | diff --git a/mmv1/templates/terraform/constants/compute_address.go.tmpl b/mmv1/templates/terraform/constants/compute_address.go.tmpl new file mode 100644 index 000000000000..176f4fd72d55 --- /dev/null +++ b/mmv1/templates/terraform/constants/compute_address.go.tmpl @@ -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 +} diff --git a/mmv1/templates/terraform/examples/compute_address_enhanced_byoip.tf.tmpl b/mmv1/templates/terraform/examples/compute_address_enhanced_byoip.tf.tmpl new file mode 100644 index 000000000000..88c88142582a --- /dev/null +++ b/mmv1/templates/terraform/examples/compute_address_enhanced_byoip.tf.tmpl @@ -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"}}" +} +