@@ -28,6 +28,7 @@ type ComputeUtil struct {
2828 project string
2929 diskTypeURL string
3030 address string
31+ networkProject string
3132 network string
3233 subnetwork string
3334 preemptible bool
@@ -60,13 +61,27 @@ func newComputeUtil(driver *Driver) (*ComputeUtil, error) {
6061 return nil , err
6162 }
6263
64+ var networkProject string
65+ if strings .Contains (driver .Network , "/projects/" ) {
66+ var splittedElements = strings .Split (driver .Network , "/" )
67+ for i , element := range splittedElements {
68+ if element == "projects" {
69+ networkProject = splittedElements [i + 1 ]
70+ break
71+ }
72+ }
73+ } else {
74+ networkProject = driver .Project
75+ }
76+
6377 return & ComputeUtil {
6478 zone : driver .Zone ,
6579 instanceName : driver .MachineName ,
6680 userName : driver .SSHUser ,
6781 project : driver .Project ,
6882 diskTypeURL : driver .DiskType ,
6983 address : driver .Address ,
84+ networkProject : networkProject ,
7085 network : driver .Network ,
7186 subnetwork : driver .Subnetwork ,
7287 preemptible : driver .Preemptible ,
@@ -137,7 +152,7 @@ func (c *ComputeUtil) region() string {
137152}
138153
139154func (c * ComputeUtil ) firewallRule () (* raw.Firewall , error ) {
140- return c .service .Firewalls .Get (c .project , firewallRule ).Do ()
155+ return c .service .Firewalls .Get (c .networkProject , firewallRule ).Do ()
141156}
142157
143158func missingOpenedPorts (rule * raw.Firewall , ports []string ) map [string ][]string {
@@ -185,15 +200,24 @@ func (c *ComputeUtil) openFirewallPorts(d *Driver) error {
185200 log .Infof ("Opening firewall ports" )
186201
187202 create := false
188- rule , _ := c .firewallRule ()
203+ rule , err := c .firewallRule ()
204+ if err != nil {
205+ return err
206+ }
189207 if rule == nil {
190208 create = true
209+ var net string
210+ if strings .Contains (d .Network , "/networks/" ) {
211+ net = d .Network
212+ } else {
213+ net = c .globalURL + "/networks/" + d .Network
214+ }
191215 rule = & raw.Firewall {
192216 Name : firewallRule ,
193217 Allowed : []* raw.FirewallAllowed {},
194218 SourceRanges : []string {"0.0.0.0/0" },
195219 TargetTags : []string {firewallTargetTag },
196- Network : c . globalURL + "/networks/" + d . Network ,
220+ Network : net ,
197221 }
198222 }
199223
@@ -215,9 +239,9 @@ func (c *ComputeUtil) openFirewallPorts(d *Driver) error {
215239
216240 var op * raw.Operation
217241 if create {
218- op , err = c .service .Firewalls .Insert (c .project , rule ).Do ()
242+ op , err = c .service .Firewalls .Insert (c .networkProject , rule ).Do ()
219243 } else {
220- op , err = c .service .Firewalls .Update (c .project , firewallRule , rule ).Do ()
244+ op , err = c .service .Firewalls .Update (c .networkProject , firewallRule , rule ).Do ()
221245 }
222246
223247 if err != nil {
@@ -277,7 +301,7 @@ func (c *ComputeUtil) createInstance(d *Driver) error {
277301 if strings .Contains (c .subnetwork , "/subnetworks/" ) {
278302 instance .NetworkInterfaces [0 ].Subnetwork = c .subnetwork
279303 } else if c .subnetwork != "" {
280- instance .NetworkInterfaces [0 ].Subnetwork = "projects/" + c .project + "/regions/" + c .region () + "/subnetworks/" + c .subnetwork
304+ instance .NetworkInterfaces [0 ].Subnetwork = "projects/" + c .networkProject + "/regions/" + c .region () + "/subnetworks/" + c .subnetwork
281305 }
282306
283307 if ! c .useInternalIPOnly {
0 commit comments