Added support for GCE external static IPs
This commit is contained in:
parent
d507b18eb4
commit
069c3c21b1
|
@ -31,6 +31,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"`
|
||||||
|
Address string `mapstructure:"address"`
|
||||||
Preemptible bool `mapstructure:"preemptible"`
|
Preemptible bool `mapstructure:"preemptible"`
|
||||||
SourceImage string `mapstructure:"source_image"`
|
SourceImage string `mapstructure:"source_image"`
|
||||||
SourceImageProjectId string `mapstructure:"source_image_project_id"`
|
SourceImageProjectId string `mapstructure:"source_image_project_id"`
|
||||||
|
|
|
@ -47,6 +47,7 @@ type InstanceConfig struct {
|
||||||
Metadata map[string]string
|
Metadata map[string]string
|
||||||
Name string
|
Name string
|
||||||
Network string
|
Network string
|
||||||
|
Address string
|
||||||
Preemptible bool
|
Preemptible bool
|
||||||
Tags []string
|
Tags []string
|
||||||
Zone string
|
Zone string
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"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"
|
"google.golang.org/api/compute/v1"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// driverGCE is a Driver implementation that actually talks to GCE.
|
// driverGCE is a Driver implementation that actually talks to GCE.
|
||||||
|
@ -214,6 +215,23 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If given a regional ip, get it
|
||||||
|
accessconfig := compute.AccessConfig{
|
||||||
|
Name: "AccessConfig created by Packer",
|
||||||
|
Type: "ONE_TO_ONE_NAT",
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Address != "" {
|
||||||
|
d.ui.Message(fmt.Sprintf("Looking up address: %s", c.Address))
|
||||||
|
region_url := strings.Split(zone.Region, "/")
|
||||||
|
region := region_url[len(region_url)-1]
|
||||||
|
address, err := d.service.Addresses.Get(d.projectId, region, c.Address).Do()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
accessconfig.NatIP = address.Address
|
||||||
|
}
|
||||||
|
|
||||||
// Build up the metadata
|
// Build up the metadata
|
||||||
metadata := make([]*compute.MetadataItems, len(c.Metadata))
|
metadata := make([]*compute.MetadataItems, len(c.Metadata))
|
||||||
for k, v := range c.Metadata {
|
for k, v := range c.Metadata {
|
||||||
|
@ -247,10 +265,7 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
||||||
NetworkInterfaces: []*compute.NetworkInterface{
|
NetworkInterfaces: []*compute.NetworkInterface{
|
||||||
&compute.NetworkInterface{
|
&compute.NetworkInterface{
|
||||||
AccessConfigs: []*compute.AccessConfig{
|
AccessConfigs: []*compute.AccessConfig{
|
||||||
&compute.AccessConfig{
|
&accessconfig,
|
||||||
Name: "AccessConfig created by Packer",
|
|
||||||
Type: "ONE_TO_ONE_NAT",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Network: network.SelfLink,
|
Network: network.SelfLink,
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,6 +59,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
|
||||||
Metadata: config.getInstanceMetadata(sshPublicKey),
|
Metadata: config.getInstanceMetadata(sshPublicKey),
|
||||||
Name: name,
|
Name: name,
|
||||||
Network: config.Network,
|
Network: config.Network,
|
||||||
|
Address: config.Address,
|
||||||
Preemptible: config.Preemptible,
|
Preemptible: config.Preemptible,
|
||||||
Tags: config.Tags,
|
Tags: config.Tags,
|
||||||
Zone: config.Zone,
|
Zone: config.Zone,
|
||||||
|
|
Loading…
Reference in New Issue