Skip to content

Commit

Permalink
Adding Mode & Allocatable Prefix Length to PDP for IPv6 Prefixes (#12804
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dhruv-23101998 authored Feb 3, 2025
1 parent 59b47aa commit 3bff238
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 7 deletions.
8 changes: 6 additions & 2 deletions mmv1/products/compute/PublicAdvertisedPrefix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ properties:
- name: 'ipCidrRange'
type: String
description:
The IPv4 address range, in CIDR format, represented by this public
advertised prefix.
The address range, in CIDR format, represented by this public advertised
prefix.
required: true
- name: 'pdpScope'
type: Enum
description: |
Specifies how child public delegated prefix will be scoped. pdpScope
must be one of: GLOBAL, REGIONAL
* REGIONAL: The public delegated prefix is regional only. The
provisioning will take a few minutes.
* GLOBAL: The public delegated prefix is global only. The provisioning
will take ~4 weeks.
enum_values:
- 'GLOBAL'
- 'REGIONAL'
Expand Down
32 changes: 30 additions & 2 deletions mmv1/products/compute/PublicDelegatedPrefix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ async:
result:
resource_inside_response: false
custom_code:
sweeper:
regions:
- us-central1
- us-west1
examples:
- name: 'public_delegated_prefixes_basic'
primary_resource_id: 'prefixes'
Expand All @@ -45,6 +49,16 @@ examples:
# PAPs have very low quota limits and a shared testing range so serialized tests exist in:
# resource_compute_public_advertised_prefix_test.go
exclude_test: true
- name: 'public_delegated_prefixes_ipv6'
vars:
pap_name: "ipv6-pap"
root_pdp_name: "ipv6-root-pdp"
sub_pdp_name: "ipv6-sub-pdp"
test_env_vars:
desc: 'PAP_DESCRIPTION'
# PAPs have very low quota limits and a shared testing range so serialized tests exist in:
# resource_compute_public_advertised_prefix_test.go
exclude_test: true
parameters:
properties:
- name: 'region'
Expand Down Expand Up @@ -75,9 +89,23 @@ properties:
PublicDelegatedPrefix.
required: true
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
- name: 'mode'
type: Enum
description: |
Specifies the mode of this IPv6 PDP. MODE must be one of: DELEGATION,
EXTERNAL_IPV6_FORWARDING_RULE_CREATION.
enum_values:
- 'DELEGATION'
- 'EXTERNAL_IPV6_FORWARDING_RULE_CREATION'
- name: 'allocatablePrefixLength'
type: Integer
description:
The allocatable prefix length supported by this public delegated prefix.
This field is optional and cannot be set for prefixes in DELEGATION mode.
It cannot be set for IPv4 prefixes either, and it always defaults to 32.
- name: 'ipCidrRange'
type: String
description:
The IPv4 address range, in CIDR format, represented by this public
advertised prefix.
The IP address range, in CIDR format, represented by this public
delegated prefix.
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "google_compute_public_advertised_prefix" "advertised" {
name = "{{index $.Vars "pap_name"}}"
description = "{{index $.TestEnvVars "desc"}}"
dns_verification_ip = "2001:db8::"
ip_cidr_range = "2001:db8::/32"
pdp_scope = "REGIONAL"
}

resource "google_compute_public_delegated_prefix" "prefix" {
name = "{{index $.Vars "root_pdp_name"}}"
description = "test-delegation-mode-pdp"
region = "us-west1"
ip_cidr_range = "2001:db8::/40"
parent_prefix = google_compute_public_advertised_prefix.advertised.id
mode = "DELEGATION"
}

resource "google_compute_public_delegated_prefix" "subprefix" {
name = "{{index $.Vars "sub_pdp_name"}}"
description = "test-forwarding-rule-mode-pdp"
region = "us-west1"
ip_cidr_range = "2001:db8::/48"
parent_prefix = google_compute_public_delegated_prefix.prefix.id
allocatable_prefix_length = 64
mode = "EXTERNAL_IPV6_FORWARDING_RULE_CREATION"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
// Since we only have access to one test prefix range we cannot run tests in parallel
func TestAccComputePublicPrefixes(t *testing.T) {
testCases := map[string]func(t *testing.T){
"delegated_prefix": testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesBasicTest,
"advertised_prefix": testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesBasicTest,
"advertised_prefix_pdp_scope": testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeTest,
"delegated_prefix": testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesBasicTest,
"advertised_prefix": testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesBasicTest,
"public_delegated_prefixes_ipv6": testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesIpv6Test,
"public_advertised_prefixes_pdp_scope": testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeTest,
}

for name, tc := range testCases {
Expand Down Expand Up @@ -155,6 +156,61 @@ resource "google_compute_public_delegated_prefix" "subprefix" {
`, context)
}

func testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesIpv6Test(t *testing.T) {
context := map[string]interface{}{
"description": envvar.GetTestPublicAdvertisedPrefixDescriptionFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputePublicDelegatedPrefixDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesIpv6Example(context),
},
{
ResourceName: "google_compute_public_delegated_prefix.prefix",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

func testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesIpv6Example(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_public_advertised_prefix" "advertised" {
name = "tf-test-ipv6-pap%{random_suffix}"
description = "%{description}"
dns_verification_ip = "2001:db8::"
ip_cidr_range = "2001:db8::/32"
pdp_scope = "REGIONAL"
}
resource "google_compute_public_delegated_prefix" "prefix" {
name = "tf-test-root-pdp%{random_suffix}"
description = "test-delegation-mode-pdp"
region = "us-west1"
ip_cidr_range = "2001:db8::/40"
parent_prefix = google_compute_public_advertised_prefix.advertised.id
mode = "DELEGATION"
}
resource "google_compute_public_delegated_prefix" "subprefix" {
name = "tf-test-sub-pdp%{random_suffix}"
description = "test-forwarding-rule-mode-pdp"
region = "us-west1"
ip_cidr_range = "2001:db8::/48"
parent_prefix = google_compute_public_delegated_prefix.prefix.id
allocatable_prefix_length = 64
mode = "EXTERNAL_IPV6_FORWARDING_RULE_CREATION"
}
`, context)
}

func testAccCheckComputePublicDelegatedPrefixDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down

0 comments on commit 3bff238

Please sign in to comment.