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
6 changes: 6 additions & 0 deletions .changelog/16070.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
compute: added `ip_collection` field to `google_compute_address` resource
```
```release-note:enhancement
compute: added `enable_enhanced_ipv4_allocation` field to `google_compute_public_delegated_prefix` resource
```
58 changes: 58 additions & 0 deletions google/services/compute/resource_compute_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ import (
"google.golang.org/api/googleapi"
)

// 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
}

var (
_ = bytes.Clone
_ = context.WithCancel
Expand Down Expand Up @@ -145,6 +172,20 @@ Note: if you set this argument's value as 'INTERNAL' you need to leave the 'netw
ForceNew: true,
Description: `An optional description of this resource.`,
},
"ip_collection": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: 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}}'`,
},
"ip_version": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -370,6 +411,12 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro
} else if v, ok := d.GetOkExists("ipv6_endpoint_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipv6EndpointTypeProp)) && (ok || !reflect.DeepEqual(v, ipv6EndpointTypeProp)) {
obj["ipv6EndpointType"] = ipv6EndpointTypeProp
}
ipCollectionProp, err := expandComputeAddressIpCollection(d.Get("ip_collection"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ip_collection"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipCollectionProp)) && (ok || !reflect.DeepEqual(v, ipCollectionProp)) {
obj["ipCollection"] = ipCollectionProp
}
effectiveLabelsProp, err := expandComputeAddressEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -586,6 +633,9 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("ipv6_endpoint_type", flattenComputeAddressIpv6EndpointType(res["ipv6EndpointType"], d, config)); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("ip_collection", flattenComputeAddressIpCollection(res["ipCollection"], d, config)); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
if err := d.Set("terraform_labels", flattenComputeAddressTerraformLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Address: %s", err)
}
Expand Down Expand Up @@ -847,6 +897,10 @@ func flattenComputeAddressIpv6EndpointType(v interface{}, d *schema.ResourceData
return v
}

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

func flattenComputeAddressTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -929,6 +983,10 @@ func expandComputeAddressIpv6EndpointType(v interface{}, d tpgresource.Terraform
return v, nil
}

func expandComputeAddressIpCollection(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeAddressEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fields:
- api_field: description
- field: effective_labels
provider_only: true
- api_field: ipCollection
- api_field: ipVersion
- api_field: ipv6EndpointType
- api_field: labelFingerprint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,50 @@ resource "google_compute_network" "network" {
`, context)
}

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

context := map[string]interface{}{
"root_pdp_url": "projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/tf-enhanced-pdp-136-124-3-120-29",
"sub_pdp_ip_cidr": fmt.Sprintf("136.124.3.%d/32", 120+acctest.RandIntRange(t, 0, 7)),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeAddressDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeAddress_computeAddressEnhancedByoipExample(context),
},
{
ResourceName: "google_compute_address.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "network", "region", "subnetwork", "terraform_labels"},
},
},
})
}

func testAccComputeAddress_computeAddressEnhancedByoipExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_address" "default" {
name = "tf-test-test-address%{random_suffix}"
region = "us-central1"
ip_collection = google_compute_public_delegated_prefix.sub_pdp.self_link
}

resource "google_compute_public_delegated_prefix" "sub_pdp" {
name = "tf-test-test-sub-pdp%{random_suffix}"
region = "us-central1"
ip_cidr_range = "%{sub_pdp_ip_cidr}"
parent_prefix = "%{root_pdp_url}"
}
`, context)
}

func testAccCheckComputeAddressDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ except the last character, which cannot be a dash.`,
* EXTERNAL_IPV6_FORWARDING_RULE_CREATION
* EXTERNAL_IPV6_SUBNETWORK_CREATION
* INTERNAL_IPV6_SUBNETWORK_CREATION Possible values: ["DELEGATION", "EXTERNAL_IPV6_FORWARDING_RULE_CREATION", "EXTERNAL_IPV6_SUBNETWORK_CREATION", "INTERNAL_IPV6_SUBNETWORK_CREATION"]`,
},
"enable_enhanced_ipv4_allocation": {
Type: schema.TypeBool,
Computed: true,
Description: `Whether this PublicDelegatedPrefix supports enhanced IPv4 allocations.
Applicable for IPv4 PDPs only.`,
},
"ipv6_access_type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -232,6 +238,12 @@ used to create addresses or further allocations.`,
ValidateFunc: verify.ValidateEnum([]string{"INITIALIZING", "READY_TO_ANNOUNCE", "ANNOUNCED", "DELETING", ""}),
Description: `The status of the sub public delegated prefix. Possible values: ["INITIALIZING", "READY_TO_ANNOUNCE", "ANNOUNCED", "DELETING"]`,
},
"enable_enhanced_ipv4_allocation": {
Type: schema.TypeBool,
Computed: true,
Description: `Whether this PublicDelegatedSubPrefix supports enhanced IPv4 allocations.
Applicable for IPv4 sub-PDPs only.`,
},
"ipv6_access_type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -434,6 +446,9 @@ func resourceComputePublicDelegatedPrefixRead(d *schema.ResourceData, meta inter
if err := d.Set("ipv6_access_type", flattenComputePublicDelegatedPrefixIpv6AccessType(res["ipv6AccessType"], d, config)); err != nil {
return fmt.Errorf("Error reading PublicDelegatedPrefix: %s", err)
}
if err := d.Set("enable_enhanced_ipv4_allocation", flattenComputePublicDelegatedPrefixEnableEnhancedIpv4Allocation(res["enableEnhancedIpv4Allocation"], d, config)); err != nil {
return fmt.Errorf("Error reading PublicDelegatedPrefix: %s", err)
}
if err := d.Set("public_delegated_sub_prefixs", flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixs(res["publicDelegatedSubPrefixs"], d, config)); err != nil {
return fmt.Errorf("Error reading PublicDelegatedPrefix: %s", err)
}
Expand Down Expand Up @@ -566,6 +581,10 @@ func flattenComputePublicDelegatedPrefixIpv6AccessType(v interface{}, d *schema.
return v
}

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

func flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand All @@ -579,16 +598,17 @@ func flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixs(v interface{},
continue
}
transformed = append(transformed, map[string]interface{}{
"name": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsName(original["name"], d, config),
"description": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsDescription(original["description"], d, config),
"region": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsRegion(original["region"], d, config),
"status": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsStatus(original["status"], d, config),
"ip_cidr_range": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsIpCidrRange(original["ipCidrRange"], d, config),
"is_address": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsIsAddress(original["isAddress"], d, config),
"mode": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsMode(original["mode"], d, config),
"allocatable_prefix_length": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsAllocatablePrefixLength(original["allocatablePrefixLength"], d, config),
"ipv6_access_type": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsIpv6AccessType(original["ipv6AccessType"], d, config),
"delegatee_project": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsDelegateeProject(original["delegateeProject"], d, config),
"name": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsName(original["name"], d, config),
"description": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsDescription(original["description"], d, config),
"region": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsRegion(original["region"], d, config),
"status": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsStatus(original["status"], d, config),
"ip_cidr_range": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsIpCidrRange(original["ipCidrRange"], d, config),
"is_address": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsIsAddress(original["isAddress"], d, config),
"mode": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsMode(original["mode"], d, config),
"allocatable_prefix_length": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsAllocatablePrefixLength(original["allocatablePrefixLength"], d, config),
"ipv6_access_type": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsIpv6AccessType(original["ipv6AccessType"], d, config),
"enable_enhanced_ipv4_allocation": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsEnableEnhancedIpv4Allocation(original["enableEnhancedIpv4Allocation"], d, config),
"delegatee_project": flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsDelegateeProject(original["delegateeProject"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -642,6 +662,10 @@ func flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsIpv6AccessType(
return v
}

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

func flattenComputePublicDelegatedPrefixPublicDelegatedSubPrefixsDelegateeProject(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ api_resource_type_kind: PublicDelegatedPrefix
fields:
- api_field: allocatablePrefixLength
- api_field: description
- api_field: enableEnhancedIpv4Allocation
- api_field: ipCidrRange
- api_field: ipv6AccessType
- api_field: isLiveMigration
Expand All @@ -16,6 +17,7 @@ fields:
- api_field: publicDelegatedSubPrefixs.allocatablePrefixLength
- api_field: publicDelegatedSubPrefixs.delegateeProject
- api_field: publicDelegatedSubPrefixs.description
- api_field: publicDelegatedSubPrefixs.enableEnhancedIpv4Allocation
- api_field: publicDelegatedSubPrefixs.ipCidrRange
- api_field: publicDelegatedSubPrefixs.ipv6AccessType
- api_field: publicDelegatedSubPrefixs.isAddress
Expand Down
33 changes: 33 additions & 0 deletions website/docs/r/compute_address.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ resource "google_compute_network" "network" {
auto_create_subnetworks = false
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=compute_address_enhanced_byoip&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Compute Address Enhanced Byoip


```hcl
resource "google_compute_address" "default" {
name = "test-address"
region = "us-central1"
ip_collection = google_compute_public_delegated_prefix.sub_pdp.self_link
}

resource "google_compute_public_delegated_prefix" "sub_pdp" {
name = "test-sub-pdp"
region = "us-central1"
ip_cidr_range = ""136.124.3.120/32""
parent_prefix = ""projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/tf-enhanced-pdp-136-124-3-120-29""
}
```

## Argument Reference

Expand Down Expand Up @@ -251,6 +273,17 @@ The following arguments are supported:
the external IPv6 address reservation.
Possible values are: `VM`, `NETLB`.

* `ip_collection` -
(Optional)
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}}`

* `region` -
(Optional)
The Region in which the created address should reside.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ In addition to the arguments listed above, the following computed attributes are
be used privately within Google Cloud. All children PDPs will have
access type as INTERNAL.

* `enable_enhanced_ipv4_allocation` -
Whether this PublicDelegatedPrefix supports enhanced IPv4 allocations.
Applicable for IPv4 PDPs only.

* `public_delegated_sub_prefixs` -
List of sub public delegated fixes for BYO IP functionality.
Each item in this array represents a sub prefix that can be
Expand Down Expand Up @@ -263,6 +267,11 @@ In addition to the arguments listed above, the following computed attributes are
be used privately within Google Cloud. All children PDPs will have
access type as INTERNAL.

* `enable_enhanced_ipv4_allocation` -
(Output)
Whether this PublicDelegatedSubPrefix supports enhanced IPv4 allocations.
Applicable for IPv4 sub-PDPs only.

* `delegatee_project` -
(Optional)
Name of the project scoping this PublicDelegatedSubPrefix.
Expand Down
Loading