2014-08-25 23:57:17 +02:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-10-27 17:25:58 +02:00
|
|
|
"os"
|
2014-09-02 15:52:49 +02:00
|
|
|
"strings"
|
2014-09-09 22:43:03 +02:00
|
|
|
"testing"
|
2014-08-25 23:57:17 +02:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2014-08-25 23:57:17 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2015-03-18 18:10:39 +01:00
|
|
|
"google.golang.org/api/compute/v1"
|
2014-08-25 23:57:17 +02:00
|
|
|
)
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
func TestAccComputeInstance_basic_deprecated_network(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-02-06 09:21:22 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_basic_deprecated_network(instanceName),
|
2015-02-06 09:21:22 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
2016-01-06 01:49:06 +01:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2015-02-06 09:21:22 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-10-14 19:17:08 +02:00
|
|
|
func TestAccComputeInstance_basic1(t *testing.T) {
|
2014-08-25 23:57:17 +02:00
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2014-08-25 23:57:17 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_basic(instanceName),
|
2014-08-25 23:57:17 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2014-08-26 00:25:45 +02:00
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
2015-04-14 02:04:10 +02:00
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "baz", "qux"),
|
2016-01-06 01:49:06 +01:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2014-08-25 23:57:17 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-10 09:25:45 +01:00
|
|
|
func TestAccComputeInstance_basic2(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-02-10 09:25:45 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_basic2(instanceName),
|
2015-02-10 09:25:45 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
2016-01-06 01:49:06 +01:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2015-02-10 09:25:45 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_basic3(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-02-10 09:25:45 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_basic3(instanceName),
|
2015-02-10 09:25:45 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
2016-01-06 01:49:06 +01:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2015-02-10 09:25:45 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-15 23:29:58 +02:00
|
|
|
func TestAccComputeInstance_basic4(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic4(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_basic5(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic5(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-08-26 00:47:21 +02:00
|
|
|
func TestAccComputeInstance_IP(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var ipName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2014-08-26 00:47:21 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_ip(ipName, instanceName),
|
2014-08-26 00:47:21 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2015-02-06 09:21:22 +01:00
|
|
|
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
2014-08-26 00:47:21 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:57:04 +02:00
|
|
|
func TestAccComputeInstance_disksWithoutAutodelete(t *testing.T) {
|
2014-09-02 15:52:49 +02:00
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
2014-09-02 15:52:49 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-05-16 20:57:04 +02:00
|
|
|
Config: testAccComputeInstance_disks(diskName, instanceName, false),
|
2014-09-02 15:52:49 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2014-11-20 14:30:02 +01:00
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2016-01-06 01:49:06 +01:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
2014-09-02 15:52:49 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:57:04 +02:00
|
|
|
func TestAccComputeInstance_disksWithAutodelete(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_disks(diskName, instanceName, true),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, true, false),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-12 03:40:37 +02:00
|
|
|
func TestAccComputeInstance_local_ssd(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-05-12 03:40:37 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_local_ssd(instanceName),
|
2015-05-12 03:40:37 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.local-ssd", &instance),
|
2016-01-06 01:49:06 +01:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2015-05-12 03:40:37 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-02-06 09:21:22 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_basic_deprecated_network(instanceName),
|
2015-02-06 09:21:22 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_update_deprecated_network(instanceName),
|
2015-02-06 09:21:22 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceMetadata(
|
|
|
|
&instance, "bar", "baz"),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "baz"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-14 01:56:48 +02:00
|
|
|
func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-04-14 01:56:48 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_basic(instanceName),
|
2015-04-14 01:56:48 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_forceNewAndChangeMetadata(instanceName),
|
2015-04-14 01:56:48 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceMetadata(
|
|
|
|
&instance, "qux", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-08-26 22:48:49 +02:00
|
|
|
func TestAccComputeInstance_update(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2014-08-26 22:48:49 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_basic(instanceName),
|
2014-08-26 22:48:49 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_update(instanceName),
|
2014-08-26 22:48:49 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceMetadata(
|
|
|
|
&instance, "bar", "baz"),
|
2014-08-26 22:52:18 +02:00
|
|
|
testAccCheckComputeInstanceTag(&instance, "baz"),
|
2015-02-06 09:21:22 +01:00
|
|
|
testAccCheckComputeInstanceAccessConfig(&instance),
|
2014-08-26 22:48:49 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-01 03:21:21 +02:00
|
|
|
func TestAccComputeInstance_service_account(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-05-01 03:21:21 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_service_account(instanceName),
|
2015-05-01 03:21:21 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceServiceAccount(&instance,
|
|
|
|
"https://www.googleapis.com/auth/compute.readonly"),
|
|
|
|
testAccCheckComputeInstanceServiceAccount(&instance,
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only"),
|
|
|
|
testAccCheckComputeInstanceServiceAccount(&instance,
|
|
|
|
"https://www.googleapis.com/auth/userinfo.email"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-10-26 21:16:06 +01:00
|
|
|
func TestAccComputeInstance_scheduling(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
2016-01-06 01:49:06 +01:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-10-26 21:16:06 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 01:49:06 +01:00
|
|
|
Config: testAccComputeInstance_scheduling(instanceName),
|
2015-10-26 21:16:06 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-17 12:09:46 +01:00
|
|
|
func TestAccComputeInstance_subnet_auto(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_subnet_auto(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceHasSubnet(&instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_subnet_custom(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_subnet_custom(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceHasSubnet(&instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-27 17:25:58 +02:00
|
|
|
func TestAccComputeInstance_subnet_xpn(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var xpn_host = os.Getenv("GOOGLE_XPN_HOST_PROJECT")
|
|
|
|
if xpn_host == "" {
|
|
|
|
t.Fatal("GOOGLE_XPN_HOST_PROJECT must be set for TestAccComputeInstance_subnet_xpn test")
|
|
|
|
}
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_subnet_xpn(instanceName, xpn_host),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceHasSubnet(&instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-08 03:01:31 +02:00
|
|
|
func TestAccComputeInstance_address_auto(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_address_auto(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceHasAnyAddress(&instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_address_custom(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var address = "10.0.200.200"
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_address_custom(instanceName, address),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceHasAddress(&instance, address),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2014-08-25 23:57:17 +02:00
|
|
|
func testAccCheckComputeInstanceDestroy(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
2014-09-17 02:16:53 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-08-25 23:57:17 +02:00
|
|
|
if rs.Type != "google_compute_instance" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := config.clientCompute.Instances.Get(
|
2014-09-17 02:16:53 +02:00
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
2014-08-25 23:57:17 +02:00
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Instance still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceExists(n string, instance *compute.Instance) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 02:16:53 +02:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-08-25 23:57:17 +02:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:16:53 +02:00
|
|
|
if rs.Primary.ID == "" {
|
2014-08-25 23:57:17 +02:00
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
found, err := config.clientCompute.Instances.Get(
|
2014-09-17 02:16:53 +02:00
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
2014-08-25 23:57:17 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:16:53 +02:00
|
|
|
if found.Name != rs.Primary.ID {
|
2014-08-25 23:57:17 +02:00
|
|
|
return fmt.Errorf("Instance not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*instance = *found
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 00:25:45 +02:00
|
|
|
func testAccCheckComputeInstanceMetadata(
|
|
|
|
instance *compute.Instance,
|
|
|
|
k string, v string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instance.Metadata == nil {
|
|
|
|
return fmt.Errorf("no metadata")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range instance.Metadata.Items {
|
|
|
|
if k != item.Key {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-08-31 16:06:25 +02:00
|
|
|
if item.Value != nil && v == *item.Value {
|
2014-08-26 00:25:45 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-31 16:06:25 +02:00
|
|
|
return fmt.Errorf("bad value for %s: %s", k, *item.Value)
|
2014-08-26 00:25:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("metadata not found: %s", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
func testAccCheckComputeInstanceAccessConfig(instance *compute.Instance) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instance.NetworkInterfaces {
|
|
|
|
if len(i.AccessConfigs) == 0 {
|
|
|
|
return fmt.Errorf("no access_config")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceAccessConfigHasIP(instance *compute.Instance) resource.TestCheckFunc {
|
2014-08-26 00:47:21 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instance.NetworkInterfaces {
|
|
|
|
for _, c := range i.AccessConfigs {
|
|
|
|
if c.NatIP == "" {
|
|
|
|
return fmt.Errorf("no NAT IP")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:52:49 +02:00
|
|
|
func testAccCheckComputeInstanceDisk(instance *compute.Instance, source string, delete bool, boot bool) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instance.Disks == nil {
|
|
|
|
return fmt.Errorf("no disks")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, disk := range instance.Disks {
|
2015-10-08 14:48:04 +02:00
|
|
|
if strings.LastIndex(disk.Source, "/"+source) == len(disk.Source)-len(source)-1 && disk.AutoDelete == delete && disk.Boot == boot {
|
2014-09-02 15:52:49 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Disk not found: %s", source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 00:25:45 +02:00
|
|
|
func testAccCheckComputeInstanceTag(instance *compute.Instance, n string) resource.TestCheckFunc {
|
2014-08-26 00:10:30 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instance.Tags == nil {
|
|
|
|
return fmt.Errorf("no tags")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, k := range instance.Tags.Items {
|
|
|
|
if k == n {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("tag not found: %s", n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 03:21:21 +02:00
|
|
|
func testAccCheckComputeInstanceServiceAccount(instance *compute.Instance, scope string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if count := len(instance.ServiceAccounts); count != 1 {
|
|
|
|
return fmt.Errorf("Wrong number of ServiceAccounts: expected 1, got %d", count)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, val := range instance.ServiceAccounts[0].Scopes {
|
|
|
|
if val == scope {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Scope not found: %s", scope)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 12:09:46 +01:00
|
|
|
func testAccCheckComputeInstanceHasSubnet(instance *compute.Instance) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instance.NetworkInterfaces {
|
|
|
|
if i.Subnetwork == "" {
|
|
|
|
return fmt.Errorf("no subnet")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 03:01:31 +02:00
|
|
|
func testAccCheckComputeInstanceHasAnyAddress(instance *compute.Instance) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instance.NetworkInterfaces {
|
|
|
|
if i.NetworkIP == "" {
|
|
|
|
return fmt.Errorf("no address")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceHasAddress(instance *compute.Instance, address string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instance.NetworkInterfaces {
|
|
|
|
if i.NetworkIP != address {
|
|
|
|
return fmt.Errorf("Wrong address found: expected %v, got %v", address, i.NetworkIP)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_basic_deprecated_network(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2014-08-25 23:57:17 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network {
|
|
|
|
source = "default"
|
|
|
|
}
|
2014-08-25 23:57:17 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2014-08-26 00:25:45 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_update_deprecated_network(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
tags = ["baz"]
|
2014-08-26 00:47:21 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2014-08-26 22:48:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network {
|
|
|
|
source = "default"
|
|
|
|
}
|
2014-08-26 22:48:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2014-08-26 22:48:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_basic(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-02-06 09:21:22 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-02-06 09:21:22 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
baz = "qux"
|
|
|
|
}
|
2015-07-02 03:24:34 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata_startup_script = "echo Hello"
|
|
|
|
}`, instance)
|
|
|
|
}
|
2015-02-06 09:21:22 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_basic2(instance string) string {
|
2016-08-15 23:29:58 +02:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-8"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_basic3(instance string) string {
|
2016-01-06 01:49:06 +01:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-cloud/debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-01-30 02:00:02 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-01-30 02:00:02 +01:00
|
|
|
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2015-02-10 09:25:45 +01:00
|
|
|
|
2016-08-15 23:29:58 +02:00
|
|
|
func testAccComputeInstance_basic4(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-cloud/debian-8"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_basic5(instance string) string {
|
2016-01-06 01:49:06 +01:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-01-30 02:00:02 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-01-30 02:00:02 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2015-01-30 02:00:02 +01:00
|
|
|
|
2015-04-14 01:56:48 +02:00
|
|
|
// Update zone to ForceNew, and change metadata k/v entirely
|
|
|
|
// Generates diff mismatch
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_forceNewAndChangeMetadata(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
zone = "us-central1-b"
|
|
|
|
tags = ["baz"]
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-04-14 01:56:48 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config { }
|
|
|
|
}
|
2015-04-14 01:56:48 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
qux = "true"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2015-04-14 01:56:48 +02:00
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
// Update metadata, tags, and network_interface
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_update(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
tags = ["baz"]
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2014-08-26 22:48:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config { }
|
|
|
|
}
|
2014-08-26 22:48:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
}`, instance)
|
2014-08-26 00:47:21 +02:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_ip(ip, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_address" "foo" {
|
|
|
|
name = "%s"
|
2014-08-26 00:47:21 +02:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2015-02-06 09:21:22 +01:00
|
|
|
}
|
2014-08-26 00:47:21 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
nat_ip = "${google_compute_address.foo.address}"
|
|
|
|
}
|
|
|
|
}
|
2014-09-02 15:52:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, ip, instance)
|
2014-11-20 14:30:02 +01:00
|
|
|
}
|
|
|
|
|
2016-05-16 20:57:04 +02:00
|
|
|
func testAccComputeInstance_disks(disk, instance string, autodelete bool) string {
|
2016-01-06 01:49:06 +01:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
2014-09-02 15:52:49 +02:00
|
|
|
}
|
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2014-09-02 15:52:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2014-09-02 15:52:49 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
|
|
|
disk = "${google_compute_disk.foobar.name}"
|
2016-05-16 20:57:04 +02:00
|
|
|
auto_delete = %v
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-05-01 03:21:21 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-05-12 03:40:37 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-05-16 20:57:04 +02:00
|
|
|
}`, disk, instance, autodelete)
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-05-12 03:40:37 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_local_ssd(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "local-ssd" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2015-05-12 03:40:37 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-05-12 03:40:37 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
|
|
|
type = "local-ssd"
|
|
|
|
scratch = true
|
|
|
|
}
|
2015-05-12 03:40:37 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-05-01 03:21:21 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
}`, instance)
|
|
|
|
}
|
2015-05-01 03:21:21 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_service_account(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2015-05-01 03:21:21 +02:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-10-26 21:16:06 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
service_account {
|
|
|
|
scopes = [
|
|
|
|
"userinfo-email",
|
|
|
|
"compute-ro",
|
|
|
|
"storage-ro",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2015-10-26 21:16:06 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
func testAccComputeInstance_scheduling(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2015-10-26 21:16:06 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-01-06 01:49:06 +01:00
|
|
|
}
|
2015-10-26 21:16:06 +01:00
|
|
|
|
2016-01-06 01:49:06 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2016-02-17 12:09:46 +01:00
|
|
|
|
|
|
|
func testAccComputeInstance_subnet_auto(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
|
|
|
auto_create_subnetworks = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-02-17 12:09:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "${google_compute_network.inst-test-network.name}"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, acctest.RandString(10), instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_subnet_custom(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "inst-test-subnetwork" {
|
|
|
|
name = "inst-test-subnetwork-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.inst-test-network.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-02-17 12:09:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), instance)
|
|
|
|
}
|
2016-08-08 03:01:31 +02:00
|
|
|
|
2016-10-27 17:25:58 +02:00
|
|
|
func testAccComputeInstance_subnet_xpn(instance string, xpn_host string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
project = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "inst-test-subnetwork" {
|
|
|
|
name = "inst-test-subnetwork-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.inst-test-network.self_link}"
|
|
|
|
project = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
subnetwork_project = "${google_compute_subnetwork.inst-test-subnetwork.project}"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, acctest.RandString(10), xpn_host, acctest.RandString(10), xpn_host, instance)
|
|
|
|
}
|
|
|
|
|
2016-08-08 03:01:31 +02:00
|
|
|
func testAccComputeInstance_address_auto(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
|
|
|
}
|
|
|
|
resource "google_compute_subnetwork" "inst-test-subnetwork" {
|
|
|
|
name = "inst-test-subnetwork-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.inst-test-network.self_link}"
|
|
|
|
}
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-08-08 03:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_address_custom(instance, address string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
|
|
|
}
|
|
|
|
resource "google_compute_subnetwork" "inst-test-subnetwork" {
|
|
|
|
name = "inst-test-subnetwork-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.inst-test-network.self_link}"
|
|
|
|
}
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
2016-08-19 04:31:45 +02:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2016-08-08 03:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
address = "%s"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), instance, address)
|
|
|
|
}
|