Skip to content

Commit

Permalink
Adding pdpScope field to PAP resource (#12803)
Browse files Browse the repository at this point in the history
[upstream:327e1af82951d97c4f6e4a8eb06792141c6a036b]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician committed Jan 21, 2025
1 parent d0dacfb commit 0d6b840
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/12803.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `pdp_scope` field to `google_compute_public_advertised_prefix` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
"github.com/hashicorp/terraform-provider-google/google/verify"
)

func ResourceComputePublicAdvertisedPrefix() *schema.Resource {
Expand Down Expand Up @@ -80,6 +81,14 @@ except the last character, which cannot be a dash.`,
ForceNew: true,
Description: `An optional description of this resource.`,
},
"pdp_scope": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"GLOBAL", "REGIONAL", ""}),
Description: `Specifies how child public delegated prefix will be scoped. pdpScope
must be one of: GLOBAL, REGIONAL Possible values: ["GLOBAL", "REGIONAL"]`,
},
"shared_secret": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -132,6 +141,12 @@ func resourceComputePublicAdvertisedPrefixCreate(d *schema.ResourceData, meta in
} else if v, ok := d.GetOkExists("ip_cidr_range"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipCidrRangeProp)) && (ok || !reflect.DeepEqual(v, ipCidrRangeProp)) {
obj["ipCidrRange"] = ipCidrRangeProp
}
pdpScopeProp, err := expandComputePublicAdvertisedPrefixPdpScope(d.Get("pdp_scope"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("pdp_scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(pdpScopeProp)) && (ok || !reflect.DeepEqual(v, pdpScopeProp)) {
obj["pdpScope"] = pdpScopeProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/publicAdvertisedPrefixes")
if err != nil {
Expand Down Expand Up @@ -243,6 +258,9 @@ func resourceComputePublicAdvertisedPrefixRead(d *schema.ResourceData, meta inte
if err := d.Set("ip_cidr_range", flattenComputePublicAdvertisedPrefixIpCidrRange(res["ipCidrRange"], d, config)); err != nil {
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err)
}
if err := d.Set("pdp_scope", flattenComputePublicAdvertisedPrefixPdpScope(res["pdpScope"], d, config)); err != nil {
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err)
}
if err := d.Set("shared_secret", flattenComputePublicAdvertisedPrefixSharedSecret(res["sharedSecret"], d, config)); err != nil {
return fmt.Errorf("Error reading PublicAdvertisedPrefix: %s", err)
}
Expand Down Expand Up @@ -345,6 +363,10 @@ func flattenComputePublicAdvertisedPrefixIpCidrRange(v interface{}, d *schema.Re
return v
}

func flattenComputePublicAdvertisedPrefixPdpScope(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputePublicAdvertisedPrefixSharedSecret(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand All @@ -364,3 +386,7 @@ func expandComputePublicAdvertisedPrefixDnsVerificationIp(v interface{}, d tpgre
func expandComputePublicAdvertisedPrefixIpCidrRange(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputePublicAdvertisedPrefixPdpScope(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ 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,
"delegated_prefix": testAccComputePublicDelegatedPrefix_publicDelegatedPrefixesBasicTest,
"advertised_prefix": testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesBasicTest,
"advertised_prefix_pdp_scope": testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeTest,
}

for name, tc := range testCases {
Expand All @@ -34,6 +35,41 @@ func TestAccComputePublicPrefixes(t *testing.T) {
}
}

func testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeTest(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: testAccCheckComputePublicAdvertisedPrefixDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeExample(context),
},
{
ResourceName: "google_compute_public_advertised_prefix.prefix",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesPdpScopeExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_public_advertised_prefix" "prefix" {
name = "tf-test-my-prefix%{random_suffix}"
description = "%{description}"
dns_verification_ip = "127.127.0.0"
ip_cidr_range = "127.127.0.0/16"
pdp_scope = "REGIONAL"
}
`, context)
}

func testAccComputePublicAdvertisedPrefix_publicAdvertisedPrefixesBasicTest(t *testing.T) {
t.Parallel()

Expand Down
18 changes: 18 additions & 0 deletions website/docs/r/compute_public_advertised_prefix.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ resource "google_compute_public_advertised_prefix" "prefixes" {
ip_cidr_range = "127.127.0.0/16"
}
```
## Example Usage - Public Advertised Prefixes Pdp Scope


```hcl
resource "google_compute_public_advertised_prefix" "prefixes" {
name = "my-pap"
description = "description"
dns_verification_ip = "127.127.0.0"
ip_cidr_range = "127.127.0.0/16"
pdp_scope = "REGIONAL"
}
```

## Argument Reference

Expand Down Expand Up @@ -70,6 +82,12 @@ The following arguments are supported:
(Optional)
An optional description of this resource.

* `pdp_scope` -
(Optional)
Specifies how child public delegated prefix will be scoped. pdpScope
must be one of: GLOBAL, REGIONAL
Possible values are: `GLOBAL`, `REGIONAL`.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down

0 comments on commit 0d6b840

Please sign in to comment.