@@ -83,6 +83,12 @@ func resourceServiceNetworkingConnectionCreate(d *schema.ResourceData, meta inte
8383 ReservedPeeringRanges : convertStringArr (d .Get ("reserved_peering_ranges" ).([]interface {})),
8484 }
8585
86+ networkFieldValue , err := ParseNetworkFieldValue (network , d , config )
87+ if err != nil {
88+ return errwrap .Wrapf ("Failed to retrieve network field value, err: {{err}}" , err )
89+ }
90+ project := networkFieldValue .Project
91+
8692 parentService := formatParentService (d .Get ("service" ).(string ))
8793 // We use Patch instead of Create, because we're getting
8894 // "Error waiting for Create Service Networking Connection:
@@ -98,12 +104,22 @@ func resourceServiceNetworkingConnectionCreate(d *schema.ResourceData, meta inte
98104 // The API docs don't specify that you can do connections/-,
99105 // but that's what gcloud does, and it's easier than grabbing
100106 // the connection name.
101- op , err := config .NewServiceNetworkingClient (userAgent ).Services .Connections .Patch (parentService + "/connections/-" , connection ).UpdateMask ("reservedPeeringRanges" ).Force (true ).Do ()
107+
108+ // err == nil indicates that the billing_project value was found
109+ if bp , err := getBillingProject (d , config ); err == nil {
110+ project = bp
111+ }
112+
113+ createCall := config .NewServiceNetworkingClient (userAgent ).Services .Connections .Patch (parentService + "/connections/-" , connection ).UpdateMask ("reservedPeeringRanges" ).Force (true )
114+ if config .UserProjectOverride {
115+ createCall .Header ().Add ("X-Goog-User-Project" , project )
116+ }
117+ op , err := createCall .Do ()
102118 if err != nil {
103119 return err
104120 }
105121
106- if err := serviceNetworkingOperationWaitTime (config , op , "Create Service Networking Connection" , userAgent , d .Timeout (schema .TimeoutCreate )); err != nil {
122+ if err := serviceNetworkingOperationWaitTime (config , op , "Create Service Networking Connection" , userAgent , project , d .Timeout (schema .TimeoutCreate )); err != nil {
107123 return err
108124 }
109125
@@ -133,9 +149,24 @@ func resourceServiceNetworkingConnectionRead(d *schema.ResourceData, meta interf
133149 return errwrap .Wrapf ("Failed to find Service Networking Connection, err: {{err}}" , err )
134150 }
135151
152+ network := d .Get ("network" ).(string )
153+ networkFieldValue , err := ParseNetworkFieldValue (network , d , config )
154+ if err != nil {
155+ return errwrap .Wrapf ("Failed to retrieve network field value, err: {{err}}" , err )
156+ }
157+ project := networkFieldValue .Project
158+
159+ // err == nil indicates that the billing_project value was found
160+ if bp , err := getBillingProject (d , config ); err == nil {
161+ project = bp
162+ }
163+
136164 parentService := formatParentService (connectionId .Service )
137- response , err := config .NewServiceNetworkingClient (userAgent ).Services .Connections .List (parentService ).
138- Network (serviceNetworkingNetworkName ).Do ()
165+ readCall := config .NewServiceNetworkingClient (userAgent ).Services .Connections .List (parentService ).Network (serviceNetworkingNetworkName )
166+ if config .UserProjectOverride {
167+ readCall .Header ().Add ("X-Goog-User-Project" , project )
168+ }
169+ response , err := readCall .Do ()
139170 if err != nil {
140171 return err
141172 }
@@ -195,13 +226,29 @@ func resourceServiceNetworkingConnectionUpdate(d *schema.ResourceData, meta inte
195226 ReservedPeeringRanges : convertStringArr (d .Get ("reserved_peering_ranges" ).([]interface {})),
196227 }
197228
229+ networkFieldValue , err := ParseNetworkFieldValue (network , d , config )
230+ if err != nil {
231+ return errwrap .Wrapf ("Failed to retrieve network field value, err: {{err}}" , err )
232+ }
233+ project := networkFieldValue .Project
234+
198235 // The API docs don't specify that you can do connections/-, but that's what gcloud does,
199236 // and it's easier than grabbing the connection name.
200- op , err := config .NewServiceNetworkingClient (userAgent ).Services .Connections .Patch (parentService + "/connections/-" , connection ).UpdateMask ("reservedPeeringRanges" ).Force (true ).Do ()
237+
238+ // err == nil indicates that the billing_project value was found
239+ if bp , err := getBillingProject (d , config ); err == nil {
240+ project = bp
241+ }
242+
243+ patchCall := config .NewServiceNetworkingClient (userAgent ).Services .Connections .Patch (parentService + "/connections/-" , connection ).UpdateMask ("reservedPeeringRanges" ).Force (true )
244+ if config .UserProjectOverride {
245+ patchCall .Header ().Add ("X-Goog-User-Project" , project )
246+ }
247+ op , err := patchCall .Do ()
201248 if err != nil {
202249 return err
203250 }
204- if err := serviceNetworkingOperationWaitTime (config , op , "Update Service Networking Connection" , userAgent , d .Timeout (schema .TimeoutUpdate )); err != nil {
251+ if err := serviceNetworkingOperationWaitTime (config , op , "Update Service Networking Connection" , userAgent , project , d .Timeout (schema .TimeoutUpdate )); err != nil {
205252 return err
206253 }
207254 }
@@ -322,7 +369,17 @@ func retrieveServiceNetworkingNetworkName(d *schema.ResourceData, config *Config
322369 return "" , fmt .Errorf ("Could not determine project" )
323370 }
324371 log .Printf ("[DEBUG] Retrieving project number by doing a GET with the project id, as required by service networking" )
325- project , err := config .NewResourceManagerClient (userAgent ).Projects .Get (pid ).Do ()
372+ // err == nil indicates that the billing_project value was found
373+ billingProject := pid
374+ if bp , err := getBillingProject (d , config ); err == nil {
375+ billingProject = bp
376+ }
377+
378+ getProjectCall := config .NewResourceManagerClient (userAgent ).Projects .Get (pid )
379+ if config .UserProjectOverride {
380+ getProjectCall .Header ().Add ("X-Goog-User-Project" , billingProject )
381+ }
382+ project , err := getProjectCall .Do ()
326383 if err != nil {
327384 // note: returning a wrapped error is part of this method's contract!
328385 // https://blog.golang.org/go1.13-errors
0 commit comments