mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-05 17:52:38 +00:00
Merge pull request #980 from BashtonLtd/gce_instance_template_network_update
Update Instance Template network definition to match changes to Instance.
This commit is contained in:
commit
90c5bf8f0e
|
@ -48,7 +48,6 @@ func resourceComputeInstanceTemplate() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: Constraint either source or other disk params
|
|
||||||
"disk": &schema.Schema{
|
"disk": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
@ -131,22 +130,30 @@ func resourceComputeInstanceTemplate() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"network": &schema.Schema{
|
"network_interface": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Required: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Elem: &schema.Resource{
|
Elem: &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"source": &schema.Schema{
|
"network": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ForceNew: true,
|
|
||||||
Required: true,
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"address": &schema.Schema{
|
"access_config": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeList,
|
||||||
ForceNew: true,
|
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"nat_ip": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -284,31 +291,35 @@ func buildDisks(d *schema.ResourceData, meta interface{}) []*compute.AttachedDis
|
||||||
|
|
||||||
func buildNetworks(d *schema.ResourceData, meta interface{}) (error, []*compute.NetworkInterface) {
|
func buildNetworks(d *schema.ResourceData, meta interface{}) (error, []*compute.NetworkInterface) {
|
||||||
// Build up the list of networks
|
// Build up the list of networks
|
||||||
networksCount := d.Get("network.#").(int)
|
networksCount := d.Get("network_interface.#").(int)
|
||||||
networks := make([]*compute.NetworkInterface, 0, networksCount)
|
networkInterfaces := make([]*compute.NetworkInterface, 0, networksCount)
|
||||||
for i := 0; i < networksCount; i++ {
|
for i := 0; i < networksCount; i++ {
|
||||||
prefix := fmt.Sprintf("network.%d", i)
|
prefix := fmt.Sprintf("network_interface.%d", i)
|
||||||
|
|
||||||
source := "global/networks/default"
|
source := "global/networks/default"
|
||||||
if v, ok := d.GetOk(prefix + ".source"); ok {
|
if v, ok := d.GetOk(prefix + ".network"); ok {
|
||||||
if v.(string) != "default" {
|
if v.(string) != "default" {
|
||||||
source = v.(string)
|
source = v.(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the interface
|
// Build the networkInterface
|
||||||
var iface compute.NetworkInterface
|
var iface compute.NetworkInterface
|
||||||
iface.AccessConfigs = []*compute.AccessConfig{
|
|
||||||
&compute.AccessConfig{
|
|
||||||
Type: "ONE_TO_ONE_NAT",
|
|
||||||
NatIP: d.Get(prefix + ".address").(string),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
iface.Network = source
|
iface.Network = source
|
||||||
|
|
||||||
networks = append(networks, &iface)
|
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(acPrefix + ".nat_ip").(string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
networkInterfaces = append(networkInterfaces, &iface)
|
||||||
}
|
}
|
||||||
return nil, networks
|
return nil, networkInterfaces
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
|
@ -214,8 +214,8 @@ resource "google_compute_instance_template" "foobar" {
|
||||||
boot = true
|
boot = true
|
||||||
}
|
}
|
||||||
|
|
||||||
network {
|
network_interface {
|
||||||
source = "default"
|
network = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
|
@ -241,9 +241,11 @@ resource "google_compute_instance_template" "foobar" {
|
||||||
source_image = "debian-7-wheezy-v20140814"
|
source_image = "debian-7-wheezy-v20140814"
|
||||||
}
|
}
|
||||||
|
|
||||||
network {
|
network_interface {
|
||||||
source = "default"
|
network = "default"
|
||||||
address = "${google_compute_address.foo.address}"
|
access_config {
|
||||||
|
nat_ip = "${google_compute_address.foo.address}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
|
@ -276,8 +278,8 @@ resource "google_compute_instance_template" "foobar" {
|
||||||
boot = false
|
boot = false
|
||||||
}
|
}
|
||||||
|
|
||||||
network {
|
network_interface {
|
||||||
source = "default"
|
network = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user