@@ -59,6 +59,24 @@ func PortRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
59
59
return old == new + "-" + new
60
60
}
61
61
62
+ // Compare only the relative path from 'regions' of two IP collection links
63
+ func IpCollectionDiffSuppress (_ , old , new string , d * schema.ResourceData ) bool {
64
+ oldStripped , err := GetRelativePathFromRegions (old )
65
+ if err != nil {
66
+ return false
67
+ }
68
+
69
+ newStripped , err := GetRelativePathFromRegions (new )
70
+ if err != nil {
71
+ return false
72
+ }
73
+
74
+ if oldStripped == newStripped {
75
+ return true
76
+ }
77
+ return false
78
+ }
79
+
62
80
// Suppresses diff for IPv4 and IPv6 different formats.
63
81
// It also suppresses diffs if an IP is changing to a reference.
64
82
func InternalIpDiffSuppress (_ , old , new string , _ * schema.ResourceData ) bool {
@@ -103,6 +121,15 @@ func InternalIpDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
103
121
return addr_equality && netmask_equality
104
122
}
105
123
124
+ func GetRelativePathFromRegions (resourceLink string ) (string , error ) {
125
+ stringParts := strings .SplitAfterN (resourceLink , "regions/" , 2 )
126
+ if len (stringParts ) != 2 {
127
+ return "" , fmt .Errorf ("String is not a valid link: %s" , resourceLink )
128
+ }
129
+
130
+ return "regions/" + stringParts [1 ], nil
131
+ }
132
+
106
133
func ResourceComputeForwardingRule () * schema.Resource {
107
134
return & schema.Resource {
108
135
Create : resourceComputeForwardingRuleCreate ,
@@ -266,6 +293,21 @@ must be omitted for all other load balancer types.`,
266
293
ForceNew : true ,
267
294
Description : `An optional description of this resource. Provide this property when
268
295
you create the resource.` ,
296
+ },
297
+ "ip_collection" : {
298
+ Type : schema .TypeString ,
299
+ Optional : true ,
300
+ ForceNew : true ,
301
+ DiffSuppressFunc : IpCollectionDiffSuppress ,
302
+ Description : `Resource reference of a PublicDelegatedPrefix. The PDP must be a sub-PDP
303
+ in EXTERNAL_IPV6_FORWARDING_RULE_CREATION mode.
304
+ Use one of the following formats to specify a sub-PDP when creating an
305
+ IPv6 NetLB forwarding rule using BYOIP:
306
+ Full resource URL, as in:
307
+ * 'https://www.googleapis.com/compute/v1/projects/{{projectId}}/regions/{{region}}/publicDelegatedPrefixes/{{sub-pdp-name}}'
308
+ Partial URL, as in:
309
+ * 'projects/{{projectId}}/regions/region/publicDelegatedPrefixes/{{sub-pdp-name}}'
310
+ * 'regions/{{region}}/publicDelegatedPrefixes/{{sub-pdp-name}}'` ,
269
311
},
270
312
"ip_version" : {
271
313
Type : schema .TypeString ,
@@ -723,6 +765,12 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{
723
765
} else if v , ok := d .GetOkExists ("ip_version" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (ipVersionProp )) && (ok || ! reflect .DeepEqual (v , ipVersionProp )) {
724
766
obj ["ipVersion" ] = ipVersionProp
725
767
}
768
+ ipCollectionProp , err := expandComputeForwardingRuleIpCollection (d .Get ("ip_collection" ), d , config )
769
+ if err != nil {
770
+ return err
771
+ } else if v , ok := d .GetOkExists ("ip_collection" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (ipCollectionProp )) && (ok || ! reflect .DeepEqual (v , ipCollectionProp )) {
772
+ obj ["ipCollection" ] = ipCollectionProp
773
+ }
726
774
labelsProp , err := expandComputeForwardingRuleEffectiveLabels (d .Get ("effective_labels" ), d , config )
727
775
if err != nil {
728
776
return err
@@ -990,6 +1038,9 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{})
990
1038
if err := d .Set ("ip_version" , flattenComputeForwardingRuleIpVersion (res ["ipVersion" ], d , config )); err != nil {
991
1039
return fmt .Errorf ("Error reading ForwardingRule: %s" , err )
992
1040
}
1041
+ if err := d .Set ("ip_collection" , flattenComputeForwardingRuleIpCollection (res ["ipCollection" ], d , config )); err != nil {
1042
+ return fmt .Errorf ("Error reading ForwardingRule: %s" , err )
1043
+ }
993
1044
if err := d .Set ("terraform_labels" , flattenComputeForwardingRuleTerraformLabels (res ["labels" ], d , config )); err != nil {
994
1045
return fmt .Errorf ("Error reading ForwardingRule: %s" , err )
995
1046
}
@@ -1491,6 +1542,10 @@ func flattenComputeForwardingRuleIpVersion(v interface{}, d *schema.ResourceData
1491
1542
return v
1492
1543
}
1493
1544
1545
+ func flattenComputeForwardingRuleIpCollection (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1546
+ return v
1547
+ }
1548
+
1494
1549
func flattenComputeForwardingRuleTerraformLabels (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1495
1550
if v == nil {
1496
1551
return v
@@ -1704,6 +1759,10 @@ func expandComputeForwardingRuleIpVersion(v interface{}, d tpgresource.Terraform
1704
1759
return v , nil
1705
1760
}
1706
1761
1762
+ func expandComputeForwardingRuleIpCollection (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1763
+ return v , nil
1764
+ }
1765
+
1707
1766
func expandComputeForwardingRuleEffectiveLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
1708
1767
if v == nil {
1709
1768
return map [string ]string {}, nil
0 commit comments