mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-08 19:18:30 +00:00
Merge remote-tracking branch 'upstream' into feature/additional_zones
This commit is contained in:
commit
18d14b5b71
|
@ -242,7 +242,11 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
|
|||
d.Set("instance_group", manager.InstanceGroup)
|
||||
d.Set("target_size", manager.TargetSize)
|
||||
d.Set("self_link", manager.SelfLink)
|
||||
d.Set("update_strategy", "RESTART") //this field doesn't match the manager api, set to default value
|
||||
update_strategy, ok := d.GetOk("update_strategy")
|
||||
if !ok {
|
||||
update_strategy = "RESTART"
|
||||
}
|
||||
d.Set("update_strategy", update_strategy.(string))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -112,6 +112,29 @@ func TestAccInstanceGroupManager_updateLifecycle(t *testing.T) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccInstanceGroupManager_updateStrategy(t *testing.T) {
|
||||
var manager compute.InstanceGroupManager
|
||||
igm := fmt.Sprintf("igm-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceGroupManagerDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceGroupManager_updateStrategy(igm),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckInstanceGroupManagerExists(
|
||||
"google_compute_instance_group_manager.igm-update-strategy", &manager),
|
||||
testAccCheckInstanceGroupManagerUpdateStrategy(
|
||||
"google_compute_instance_group_manager.igm-update-strategy", "NONE"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckInstanceGroupManagerDestroy(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
|
@ -268,6 +291,25 @@ func testAccCheckInstanceGroupManagerTemplateTags(n string, tags []string) resou
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckInstanceGroupManagerUpdateStrategy(n, strategy string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", n)
|
||||
}
|
||||
|
||||
if rs.Primary.ID == "" {
|
||||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
|
||||
if rs.Primary.Attributes["update_strategy"] != strategy {
|
||||
return fmt.Errorf("Expected strategy to be %s, got %s",
|
||||
strategy, rs.Primary.Attributes["update_strategy"])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccInstanceGroupManager_basic(template, target, igm1, igm2 string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance_template" "igm-basic" {
|
||||
|
@ -488,6 +530,47 @@ func testAccInstanceGroupManager_updateLifecycle(tag, igm string) string {
|
|||
}`, tag, igm)
|
||||
}
|
||||
|
||||
func testAccInstanceGroupManager_updateStrategy(igm string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance_template" "igm-update-strategy" {
|
||||
machine_type = "n1-standard-1"
|
||||
can_ip_forward = false
|
||||
tags = ["terraform-testing"]
|
||||
|
||||
disk {
|
||||
source_image = "debian-cloud/debian-8-jessie-v20160803"
|
||||
auto_delete = true
|
||||
boot = true
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network = "default"
|
||||
}
|
||||
|
||||
service_account {
|
||||
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance_group_manager" "igm-update-strategy" {
|
||||
description = "Terraform test instance group manager"
|
||||
name = "%s"
|
||||
instance_template = "${google_compute_instance_template.igm-update-strategy.self_link}"
|
||||
base_instance_name = "igm-update-strategy"
|
||||
zone = "us-central1-c"
|
||||
target_size = 2
|
||||
update_strategy = "NONE"
|
||||
named_port {
|
||||
name = "customhttp"
|
||||
port = 8080
|
||||
}
|
||||
}`, igm)
|
||||
}
|
||||
|
||||
func resourceSplitter(resource string) string {
|
||||
splits := strings.Split(resource, "/")
|
||||
|
||||
|
|
|
@ -203,6 +203,12 @@ func resourceComputeInstanceTemplate() *schema.Resource {
|
|||
ForceNew: true,
|
||||
},
|
||||
|
||||
"subnetwork_project": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"access_config": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
|
@ -406,14 +412,16 @@ func buildNetworks(d *schema.ResourceData, meta interface{}) ([]*compute.Network
|
|||
for i := 0; i < networksCount; i++ {
|
||||
prefix := fmt.Sprintf("network_interface.%d", i)
|
||||
|
||||
var networkName, subnetworkName string
|
||||
var networkName, subnetworkName, subnetworkProject string
|
||||
if v, ok := d.GetOk(prefix + ".network"); ok {
|
||||
networkName = v.(string)
|
||||
}
|
||||
if v, ok := d.GetOk(prefix + ".subnetwork"); ok {
|
||||
subnetworkName = v.(string)
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk(prefix + ".subnetwork_project"); ok {
|
||||
subnetworkProject = v.(string)
|
||||
}
|
||||
if networkName == "" && subnetworkName == "" {
|
||||
return nil, fmt.Errorf("network or subnetwork must be provided")
|
||||
}
|
||||
|
@ -435,8 +443,11 @@ func buildNetworks(d *schema.ResourceData, meta interface{}) ([]*compute.Network
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if subnetworkProject == "" {
|
||||
subnetworkProject = project
|
||||
}
|
||||
subnetwork, err := config.clientCompute.Subnetworks.Get(
|
||||
project, region, subnetworkName).Do()
|
||||
subnetworkProject, region, subnetworkName).Do()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Error referencing subnetwork '%s' in region '%s': %s",
|
||||
|
@ -639,6 +650,7 @@ func flattenNetworkInterfaces(networkInterfaces []*compute.NetworkInterface) ([]
|
|||
subnetworkUrl := strings.Split(networkInterface.Subnetwork, "/")
|
||||
networkInterfaceMap["subnetwork"] = subnetworkUrl[len(subnetworkUrl)-1]
|
||||
region = subnetworkUrl[len(subnetworkUrl)-3]
|
||||
networkInterfaceMap["subnetwork_project"] = subnetworkUrl[len(subnetworkUrl)-5]
|
||||
}
|
||||
|
||||
if networkInterface.AccessConfigs != nil {
|
||||
|
|
|
@ -2,6 +2,7 @@ package google
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -115,6 +116,27 @@ func TestAccComputeInstanceTemplate_subnet_custom(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstanceTemplate_subnet_xpn(t *testing.T) {
|
||||
var instanceTemplate compute.InstanceTemplate
|
||||
var xpn_host = os.Getenv("GOOGLE_XPN_HOST_PROJECT")
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstanceTemplate_subnet_xpn(xpn_host),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeInstanceTemplateExists(
|
||||
"google_compute_instance_template.foobar", &instanceTemplate),
|
||||
testAccCheckComputeInstanceTemplateSubnetwork(&instanceTemplate),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstanceTemplate_metadata_startup_script(t *testing.T) {
|
||||
var instanceTemplate compute.InstanceTemplate
|
||||
|
||||
|
@ -467,6 +489,45 @@ resource "google_compute_instance_template" "foobar" {
|
|||
}
|
||||
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
||||
|
||||
func testAccComputeInstanceTemplate_subnet_xpn(xpn_host string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_network" "network" {
|
||||
name = "network-%s"
|
||||
auto_create_subnetworks = false
|
||||
project = "%s"
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "subnetwork" {
|
||||
name = "subnetwork-%s"
|
||||
ip_cidr_range = "10.0.0.0/24"
|
||||
region = "us-central1"
|
||||
network = "${google_compute_network.network.self_link}"
|
||||
project = "%s"
|
||||
}
|
||||
|
||||
resource "google_compute_instance_template" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
machine_type = "n1-standard-1"
|
||||
region = "us-central1"
|
||||
|
||||
disk {
|
||||
source_image = "debian-8-jessie-v20160803"
|
||||
auto_delete = true
|
||||
disk_size_gb = 10
|
||||
boot = true
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnetwork = "${google_compute_subnetwork.subnetwork.name}"
|
||||
subnetwork_project = "${google_compute_subnetwork.subnetwork.project}"
|
||||
}
|
||||
|
||||
metadata {
|
||||
foo = "bar"
|
||||
}
|
||||
}`, acctest.RandString(10), xpn_host, acctest.RandString(10), xpn_host, acctest.RandString(10))
|
||||
}
|
||||
|
||||
var testAccComputeInstanceTemplate_startup_script = fmt.Sprintf(`
|
||||
resource "google_compute_instance_template" "foobar" {
|
||||
name = "instance-test-%s"
|
||||
|
|
Loading…
Reference in New Issue
Block a user