@@ -25,6 +25,7 @@ import (
2525 "log"
2626 "net/http"
2727 "reflect"
28+ "strings"
2829 "time"
2930
3031 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
@@ -88,13 +89,6 @@ which means the first character must be a lowercase letter, and all
8889following characters must be a dash, lowercase letter, or digit,
8990except the last character, which cannot be a dash.` ,
9091 },
91- "network" : {
92- Type : schema .TypeString ,
93- Required : true ,
94- ForceNew : true ,
95- DiffSuppressFunc : tpgresource .CompareSelfLinkOrResourceName ,
96- Description : `A reference to the network to which this router belongs.` ,
97- },
9892 "bgp" : {
9993 Type : schema .TypeList ,
10094 Optional : true ,
@@ -204,6 +198,22 @@ Must be referenced by exactly one bgpPeer. Must comply with RFC1035.`,
204198 },
205199 },
206200 },
201+ "ncc_gateway" : {
202+ Type : schema .TypeString ,
203+ Optional : true ,
204+ ForceNew : true ,
205+ DiffSuppressFunc : tpgresource .CompareSelfLinkOrResourceName ,
206+ Description : `A URI of an NCC Gateway spoke` ,
207+ ConflictsWith : []string {"network" },
208+ },
209+ "network" : {
210+ Type : schema .TypeString ,
211+ Optional : true ,
212+ ForceNew : true ,
213+ DiffSuppressFunc : tpgresource .CompareSelfLinkOrResourceName ,
214+ Description : `A reference to the network to which this router belongs.` ,
215+ ConflictsWith : []string {"ncc_gateway" },
216+ },
207217 "params" : {
208218 Type : schema .TypeList ,
209219 Optional : true ,
@@ -313,6 +323,12 @@ func resourceComputeRouterCreate(d *schema.ResourceData, meta interface{}) error
313323 } else if v , ok := d .GetOkExists ("md5_authentication_keys" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (md5AuthenticationKeysProp )) && (ok || ! reflect .DeepEqual (v , md5AuthenticationKeysProp )) {
314324 obj ["md5AuthenticationKeys" ] = md5AuthenticationKeysProp
315325 }
326+ nccGatewayProp , err := expandComputeRouterNccGateway (d .Get ("ncc_gateway" ), d , config )
327+ if err != nil {
328+ return err
329+ } else if v , ok := d .GetOkExists ("ncc_gateway" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (nccGatewayProp )) && (ok || ! reflect .DeepEqual (v , nccGatewayProp )) {
330+ obj ["nccGateway" ] = nccGatewayProp
331+ }
316332 paramsProp , err := expandComputeRouterParams (d .Get ("params" ), d , config )
317333 if err != nil {
318334 return err
@@ -449,6 +465,9 @@ func resourceComputeRouterRead(d *schema.ResourceData, meta interface{}) error {
449465 if err := d .Set ("encrypted_interconnect_router" , flattenComputeRouterEncryptedInterconnectRouter (res ["encryptedInterconnectRouter" ], d , config )); err != nil {
450466 return fmt .Errorf ("Error reading Router: %s" , err )
451467 }
468+ if err := d .Set ("ncc_gateway" , flattenComputeRouterNccGateway (res ["nccGateway" ], d , config )); err != nil {
469+ return fmt .Errorf ("Error reading Router: %s" , err )
470+ }
452471 if err := d .Set ("region" , flattenComputeRouterRegion (res ["region" ], d , config )); err != nil {
453472 return fmt .Errorf ("Error reading Router: %s" , err )
454473 }
@@ -745,6 +764,13 @@ func flattenComputeRouterEncryptedInterconnectRouter(v interface{}, d *schema.Re
745764 return v
746765}
747766
767+ func flattenComputeRouterNccGateway (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
768+ if v == nil {
769+ return v
770+ }
771+ return tpgresource .ConvertSelfLinkToV1 (v .(string ))
772+ }
773+
748774func flattenComputeRouterRegion (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
749775 if v == nil {
750776 return v
@@ -927,6 +953,25 @@ func expandComputeRouterMd5AuthenticationKeysKey(v interface{}, d tpgresource.Te
927953 return v , nil
928954}
929955
956+ func expandComputeRouterNccGateway (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
957+ // This method returns a full self link from a partial self link.
958+ if v == nil || v .(string ) == "" {
959+ // It does not try to construct anything from empty.
960+ return "" , nil
961+ } else if strings .HasPrefix (v .(string ), "https://" ) {
962+ // Anything that starts with a URL scheme is assumed to be a self link worth using.
963+ return v , nil
964+ }
965+ // Anything else is assumed to be a regional resource, with a partial link that begins with the resource name.
966+ // This isn't very likely - it's a last-ditch effort to extract something useful here. We can do a better job
967+ // as soon as MultiResourceRefs are working since we'll know the types that this field is supposed to point to.
968+ url , err := tpgresource .ReplaceVars (d , config , "{{NetworkConnectivityBasePath}}" )
969+ if err != nil {
970+ return nil , err
971+ }
972+ return url + v .(string ), nil
973+ }
974+
930975func expandComputeRouterParams (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
931976 if v == nil {
932977 return nil , nil
0 commit comments