|
|
|
|
@ -133,22 +133,30 @@ func resourceComputeInstanceTemplate() *schema.Resource {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"network": &schema.Schema{
|
|
|
|
|
"network_interface": &schema.Schema{
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Required: true,
|
|
|
|
|
Optional: true,
|
|
|
|
|
ForceNew: true,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"source": &schema.Schema{
|
|
|
|
|
"network": &schema.Schema{
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
ForceNew: true,
|
|
|
|
|
Required: true,
|
|
|
|
|
ForceNew: true,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"address": &schema.Schema{
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
ForceNew: true,
|
|
|
|
|
"access_config": &schema.Schema{
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"nat_ip": &schema.Schema{
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Optional: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -290,31 +298,35 @@ func buildDisks(d *schema.ResourceData, meta interface{}) []*compute.AttachedDis
|
|
|
|
|
|
|
|
|
|
func buildNetworks(d *schema.ResourceData, meta interface{}) (error, []*compute.NetworkInterface) {
|
|
|
|
|
// Build up the list of networks
|
|
|
|
|
networksCount := d.Get("network.#").(int)
|
|
|
|
|
networks := make([]*compute.NetworkInterface, 0, networksCount)
|
|
|
|
|
networksCount := d.Get("network_interface.#").(int)
|
|
|
|
|
networkInterfaces := make([]*compute.NetworkInterface, 0, networksCount)
|
|
|
|
|
for i := 0; i < networksCount; i++ {
|
|
|
|
|
prefix := fmt.Sprintf("network.%d", i)
|
|
|
|
|
prefix := fmt.Sprintf("network_interface.%d", i)
|
|
|
|
|
|
|
|
|
|
source := "global/networks/default"
|
|
|
|
|
if v, ok := d.GetOk(prefix + ".source"); ok {
|
|
|
|
|
if v, ok := d.GetOk(prefix + ".network"); ok {
|
|
|
|
|
if v.(string) != "default" {
|
|
|
|
|
source = v.(string)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build the interface
|
|
|
|
|
// Build the networkInterface
|
|
|
|
|
var iface compute.NetworkInterface
|
|
|
|
|
iface.AccessConfigs = []*compute.AccessConfig{
|
|
|
|
|
&compute.AccessConfig{
|
|
|
|
|
iface.Network = source
|
|
|
|
|
|
|
|
|
|
accessConfigsCount := d.Get(prefix + ".access_config.#").(int)
|
|
|
|
|
iface.AccessConfigs = make([]*compute.AccessConfig, accessConfigsCount)
|
|
|
|
|
for j := 0; j < accessConfigsCount; j++ {
|
|
|
|
|
acPrefix := fmt.Sprintf("%s.access_config.%d", prefix, j)
|
|
|
|
|
iface.AccessConfigs[j] = &compute.AccessConfig{
|
|
|
|
|
Type: "ONE_TO_ONE_NAT",
|
|
|
|
|
NatIP: d.Get(prefix + ".address").(string),
|
|
|
|
|
},
|
|
|
|
|
NatIP: d.Get(acPrefix + ".nat_ip").(string),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
iface.Network = source
|
|
|
|
|
|
|
|
|
|
networks = append(networks, &iface)
|
|
|
|
|
networkInterfaces = append(networkInterfaces, &iface)
|
|
|
|
|
}
|
|
|
|
|
return nil, networks
|
|
|
|
|
return nil, networkInterfaces
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
|
|