|
|
|
|
@ -215,6 +215,25 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subnetwork
|
|
|
|
|
// Validate Subnetwork config now that we have some info about the network
|
|
|
|
|
if !network.AutoCreateSubnetworks && len(network.Subnetworks) > 0 {
|
|
|
|
|
// Network appears to be in "custom" mode, so a subnetwork is required
|
|
|
|
|
if c.Subnetwork == "" {
|
|
|
|
|
return nil, fmt.Errorf("a subnetwork must be specified")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Get the subnetwork
|
|
|
|
|
subnetworkSelfLink := ""
|
|
|
|
|
if c.Subnetwork != "" {
|
|
|
|
|
d.ui.Message(fmt.Sprintf("Loading subnetwork: %s for region: %s", c.Subnetwork, c.Region))
|
|
|
|
|
subnetwork, err := d.service.Subnetworks.Get(d.projectId, c.Region, c.Subnetwork).Do()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
subnetworkSelfLink = subnetwork.SelfLink
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If given a regional ip, get it
|
|
|
|
|
accessconfig := compute.AccessConfig{
|
|
|
|
|
Name: "AccessConfig created by Packer",
|
|
|
|
|
@ -235,9 +254,10 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
|
|
|
|
// Build up the metadata
|
|
|
|
|
metadata := make([]*compute.MetadataItems, len(c.Metadata))
|
|
|
|
|
for k, v := range c.Metadata {
|
|
|
|
|
vCopy := v
|
|
|
|
|
metadata = append(metadata, &compute.MetadataItems{
|
|
|
|
|
Key: k,
|
|
|
|
|
Value: &v,
|
|
|
|
|
Value: &vCopy,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -268,6 +288,7 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
|
|
|
|
&accessconfig,
|
|
|
|
|
},
|
|
|
|
|
Network: network.SelfLink,
|
|
|
|
|
Subnetwork: subnetworkSelfLink,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Scheduling: &compute.Scheduling{
|
|
|
|
|
|