Merge pull request #4288 from troytoman/gce-network-uri

enable support for Google Compute XPN
This commit is contained in:
Matthew Hooker 2016-12-15 12:03:46 -08:00 committed by GitHub
commit c61c7765ec
5 changed files with 15 additions and 5 deletions

View File

@ -37,6 +37,7 @@ type Config struct {
MachineType string `mapstructure:"machine_type"` MachineType string `mapstructure:"machine_type"`
Metadata map[string]string `mapstructure:"metadata"` Metadata map[string]string `mapstructure:"metadata"`
Network string `mapstructure:"network"` Network string `mapstructure:"network"`
NetworkProjectId string `mapstructure:"network_project_id"`
OmitExternalIP bool `mapstructure:"omit_external_ip"` OmitExternalIP bool `mapstructure:"omit_external_ip"`
Preemptible bool `mapstructure:"preemptible"` Preemptible bool `mapstructure:"preemptible"`
RawStateTimeout string `mapstructure:"state_timeout"` RawStateTimeout string `mapstructure:"state_timeout"`

View File

@ -67,6 +67,7 @@ type InstanceConfig struct {
Metadata map[string]string Metadata map[string]string
Name string Name string
Network string Network string
NetworkProjectId string
OmitExternalIP bool OmitExternalIP bool
Preemptible bool Preemptible bool
Region string Region string

View File

@ -14,6 +14,8 @@ import (
"strings" "strings"
"time" "time"
"google.golang.org/api/compute/v1"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/version" "github.com/mitchellh/packer/version"
@ -21,7 +23,6 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/google" "golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt" "golang.org/x/oauth2/jwt"
"google.golang.org/api/compute/v1"
) )
// driverGCE is a Driver implementation that actually talks to GCE. // driverGCE is a Driver implementation that actually talks to GCE.
@ -297,8 +298,11 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
// TODO(mitchellh): deprecation warnings // TODO(mitchellh): deprecation warnings
// Get the network // Get the network
if c.NetworkProjectId == "" {
c.NetworkProjectId = d.projectId
}
d.ui.Message(fmt.Sprintf("Loading network: %s", c.Network)) d.ui.Message(fmt.Sprintf("Loading network: %s", c.Network))
network, err := d.service.Networks.Get(d.projectId, c.Network).Do() network, err := d.service.Networks.Get(c.NetworkProjectId, c.Network).Do()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -315,7 +319,7 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
subnetworkSelfLink := "" subnetworkSelfLink := ""
if c.Subnetwork != "" { if c.Subnetwork != "" {
d.ui.Message(fmt.Sprintf("Loading subnetwork: %s for region: %s", c.Subnetwork, c.Region)) 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() subnetwork, err := d.service.Subnetworks.Get(c.NetworkProjectId, c.Region, c.Subnetwork).Do()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -108,6 +108,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
Metadata: metadata, Metadata: metadata,
Name: name, Name: name,
Network: c.Network, Network: c.Network,
NetworkProjectId: c.NetworkProjectId,
OmitExternalIP: c.OmitExternalIP, OmitExternalIP: c.OmitExternalIP,
Preemptible: c.Preemptible, Preemptible: c.Preemptible,
Region: c.Region, Region: c.Region,

View File

@ -172,6 +172,9 @@ builder.
- `network` (string) - The Google Compute network to use for the - `network` (string) - The Google Compute network to use for the
launched instance. Defaults to `"default"`. launched instance. Defaults to `"default"`.
- 'network_project_id' (string) - The project ID for the network and subnetwork
to use for launched instance. Defaults to `project_id`.
- `omit_external_ip` (boolean) - If true, the instance will not have an external IP. - `omit_external_ip` (boolean) - If true, the instance will not have an external IP.
`use_internal_ip` must be true if this property is true. `use_internal_ip` must be true if this property is true.
@ -192,13 +195,13 @@ builder.
- `source_image_project_id` (string) - The project ID of the - `source_image_project_id` (string) - The project ID of the
project containing the source image. project containing the source image.
- `startup_script_file` (string) - The filepath to a startup script to run on - `startup_script_file` (string) - The filepath to a startup script to run on
the VM from which the image will be made. the VM from which the image will be made.
- `state_timeout` (string) - The time to wait for instance state changes. - `state_timeout` (string) - The time to wait for instance state changes.
Defaults to `"5m"`. Defaults to `"5m"`.
- `subnetwork` (string) - The Google Compute subnetwork to use for the launced - `subnetwork` (string) - The Google Compute subnetwork to use for the launched
instance. Only required if the `network` has been created with custom instance. Only required if the `network` has been created with custom
subnetting. subnetting.
Note, the region of the subnetwork must match the `region` or `zone` in Note, the region of the subnetwork must match the `region` or `zone` in