Skip to content

Commit f84cf65

Browse files
Compute public delagated sub prefix list support (#14264)
1 parent 0005201 commit f84cf65

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

mmv1/products/compute/PublicDelegatedPrefix.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,58 @@ properties:
122122
The IP address range, in CIDR format, represented by this public
123123
delegated prefix.
124124
required: true
125+
- name: 'publicDelegatedSubPrefixs'
126+
type: Array
127+
output: true
128+
description: |
129+
List of sub public delegated fixes for BYO IP functionality.
130+
Each item in this array represents a sub prefix that can be
131+
used to create addresses or further allocations.
132+
item_type:
133+
type: NestedObject
134+
properties:
135+
- name: 'name'
136+
type: String
137+
description: |
138+
The name of the sub public delegated prefix.
139+
- name: 'description'
140+
type: String
141+
description: |
142+
An optional description of this sub public delegated prefix.
143+
- name: 'region'
144+
type: String
145+
description: |
146+
Output-only. The region of the sub public delegated prefix if it is regional. If absent, the sub prefix is global.
147+
- name: 'status'
148+
type: Enum
149+
description: |
150+
The status of the sub public delegated prefix.
151+
enum_values:
152+
- 'INITIALIZING'
153+
- 'READY_TO_ANNOUNCE'
154+
- 'ANNOUNCED'
155+
- 'DELETING'
156+
- name: 'ipCidrRange'
157+
type: String
158+
description: |
159+
The IP address range in the CIDR format represented by this sub prefix.
160+
- name: 'isAddress'
161+
type: Boolean
162+
description: |
163+
Whether the sub prefix is delegated for address creation.
164+
- name: 'mode'
165+
type: Enum
166+
description: |
167+
The PublicDelegatedSubPrefix mode for IPv6 only.
168+
enum_values:
169+
- 'DELEGATION'
170+
- 'EXTERNAL_IPV6_FORWARDING_RULE_CREATION'
171+
- 'EXTERNAL_IPV6_SUBNETWORK_CREATION'
172+
- name: 'allocatablePrefixLength'
173+
type: Integer
174+
description: |
175+
The allocatable prefix length supported by this PublicDelegatedSubPrefix.
176+
- name: 'delegatee_project'
177+
type: String
178+
description: |
179+
Name of the project scoping this PublicDelegatedSubPrefix.

mmv1/third_party/terraform/services/compute/resource_compute_public_advertised_prefix_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func TestAccComputePublicPrefixes(t *testing.T) {
2121
"public_delegated_prefixes_ipv6": testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesIpv6Test,
2222
"public_advertised_prefixes_pdp_scope": testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeTest,
2323
"public_delegated_prefix_ipv6_subnet_mode": testAccComputePublicDelegatedPrefix_publicDelegatedPrefixIpv6SubnetModeTest,
24+
"public_delgated_prefix_with_sub_prefix": TestAccComputePublicDelegatedPrefix_computePublicDelegatedPrefixWithSubPrefixExample,
2425
}
2526

2627
for name, tc := range testCases {
@@ -35,6 +36,84 @@ func TestAccComputePublicPrefixes(t *testing.T) {
3536
}
3637
}
3738

39+
func TestAccComputePublicDelegatedPrefix_computePublicDelegatedPrefixWithSubPrefixExample(t *testing.T) {
40+
t.Parallel()
41+
subPrefixResourceName := "google_compute_public_delegated_prefix.subprefix"
42+
parentProject := "tf-static-byoip"
43+
parentRegion := "us-central1"
44+
parentName := "tf-test-delegation-mode-sub-pdp"
45+
46+
context := map[string]interface{}{
47+
"parent_pdp_id": "projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/tf-test-delegation-mode-sub-pdp",
48+
"project": "tf-static-byoip",
49+
"random_suffix": acctest.RandString(t, 10),
50+
}
51+
52+
acctest.VcrTest(t, resource.TestCase{
53+
PreCheck: func() { acctest.AccTestPreCheck(t) },
54+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
55+
CheckDestroy: testAccCheckComputePublicDelegatedPrefixDestroyProducer(t),
56+
Steps: []resource.TestStep{
57+
{
58+
Config: testAccComputePublicDelegatedPrefix_computePublicDelegatedPrefixWithSubPrefixExample(context),
59+
Check: resource.ComposeTestCheckFunc(
60+
// First, a basic check that the sub-prefix was created
61+
resource.TestCheckResourceAttrSet(subPrefixResourceName, "id"),
62+
63+
// Now, the custom check function
64+
testAccCheckParentHasSubPrefix(t, parentProject, parentRegion, parentName, subPrefixResourceName),
65+
),
66+
},
67+
{
68+
ResourceName: "google_compute_public_delegated_prefix.subprefix",
69+
ImportState: true,
70+
ImportStateVerify: true,
71+
ImportStateVerifyIgnore: []string{"region"},
72+
},
73+
},
74+
})
75+
}
76+
77+
func testAccComputePublicDelegatedPrefix_computePublicDelegatedPrefixWithSubPrefixExample(context map[string]interface{}) string {
78+
return acctest.Nprintf(`
79+
80+
resource "google_compute_public_delegated_prefix" "subprefix" {
81+
name = "tf-test-sub-prefix-1%{random_suffix}"
82+
description = "A nested address"
83+
region = "us-central1"
84+
ip_cidr_range = "2600:1901:4500:2::/64"
85+
parent_prefix = "%{parent_pdp_id}"
86+
mode = "DELEGATION"
87+
}
88+
`, context)
89+
}
90+
91+
func testAccCheckParentHasSubPrefix(t *testing.T, project, region, parentName, subPrefixResourceName string) resource.TestCheckFunc {
92+
return func(s *terraform.State) error {
93+
rs, ok := s.RootModule().Resources[subPrefixResourceName]
94+
if !ok {
95+
return fmt.Errorf("Not found: %s", subPrefixResourceName)
96+
}
97+
newSubPrefixName := rs.Primary.Attributes["name"]
98+
99+
config := acctest.GoogleProviderConfig(t)
100+
computeService := config.NewComputeClient(config.UserAgent)
101+
102+
parent, err := computeService.PublicDelegatedPrefixes.Get(project, region, parentName).Do()
103+
if err != nil {
104+
return err
105+
}
106+
107+
for _, sub := range parent.PublicDelegatedSubPrefixs {
108+
if sub.Name == newSubPrefixName {
109+
return nil
110+
}
111+
}
112+
113+
return fmt.Errorf("Sub-Prefix %q not found in parent %q's sub-prefix list", newSubPrefixName, parentName)
114+
}
115+
}
116+
38117
func testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeTest(t *testing.T) {
39118
context := map[string]interface{}{
40119
"description": envvar.GetTestPublicAdvertisedPrefixDescriptionFromEnv(t),

0 commit comments

Comments
 (0)