2014-08-25 23:57:17 +02:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
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
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic_deprecated_network,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic,
|
|
|
|
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"),
|
2014-09-02 15:52:49 +02:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", 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
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic2,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_basic3(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic3,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-08-26 00:47:21 +02:00
|
|
|
func TestAccComputeInstance_IP(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_ip,
|
|
|
|
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
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:52:49 +02:00
|
|
|
func TestAccComputeInstance_disks(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_disks,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2014-11-20 14:30:02 +01:00
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2014-09-02 15:52:49 +02:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test-disk", false, false),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-12 03:40:37 +02:00
|
|
|
func TestAccComputeInstance_local_ssd(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_local_ssd,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.local-ssd", &instance),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
|
|
|
|
var instance compute.Instance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic_deprecated_network,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_update_deprecated_network,
|
|
|
|
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
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_forceNewAndChangeMetadata,
|
|
|
|
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
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_update,
|
|
|
|
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
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_service_account,
|
|
|
|
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
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_scheduling,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_basic_deprecated_network = fmt.Sprintf(`
|
2014-08-25 23:57:17 +02:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2014-08-25 23:57:17 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2014-10-07 18:24:13 +02:00
|
|
|
can_ip_forward = false
|
2014-08-26 00:10:30 +02:00
|
|
|
tags = ["foo", "bar"]
|
2014-08-25 23:57:17 +02:00
|
|
|
|
|
|
|
disk {
|
2014-08-26 06:35:23 +02:00
|
|
|
image = "debian-7-wheezy-v20140814"
|
2014-08-25 23:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
|
|
|
source = "default"
|
|
|
|
}
|
2014-08-26 00:25:45 +02:00
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2014-08-26 00:47:21 +02:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_update_deprecated_network = fmt.Sprintf(`
|
2014-08-26 22:48:49 +02:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2014-08-26 22:48:49 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2014-08-26 22:52:18 +02:00
|
|
|
tags = ["baz"]
|
2014-08-26 22:48:49 +02:00
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
|
|
|
source = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2014-08-26 22:48:49 +02:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_basic = fmt.Sprintf(`
|
2015-02-06 09:21:22 +01:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2015-02-06 09:21:22 +01:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
2015-04-14 02:04:10 +02:00
|
|
|
baz = "qux"
|
|
|
|
}
|
2015-07-02 03:24:34 +02:00
|
|
|
|
|
|
|
metadata_startup_script = "echo Hello"
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2015-02-06 09:21:22 +01:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_basic2 = fmt.Sprintf(`
|
2015-01-30 02:00:02 +01:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2015-01-30 02:00:02 +01:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-cloud/debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
2015-02-10 09:25:45 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
2015-01-30 02:00:02 +01:00
|
|
|
}
|
|
|
|
|
2015-02-10 09:25:45 +01:00
|
|
|
|
2015-01-30 02:00:02 +01:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2015-01-30 02:00:02 +01:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_basic3 = fmt.Sprintf(`
|
2015-01-30 02:00:02 +01:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2015-01-30 02:00:02 +01:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
2015-02-10 09:25:45 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
2015-01-30 02:00:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
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-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_forceNewAndChangeMetadata = fmt.Sprintf(`
|
2015-04-14 01:56:48 +02:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2015-04-14 01:56:48 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
zone = "us-central1-b"
|
|
|
|
tags = ["baz"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
qux = "true"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2015-04-14 01:56:48 +02:00
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
// Update metadata, tags, and network_interface
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_update = fmt.Sprintf(`
|
2014-08-26 22:48:49 +02:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2014-08-26 22:48:49 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2014-08-26 22:52:18 +02:00
|
|
|
tags = ["baz"]
|
2014-08-26 22:48:49 +02:00
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config { }
|
2014-08-26 22:48:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2014-08-26 22:48:49 +02:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_ip = fmt.Sprintf(`
|
2014-08-26 00:47:21 +02:00
|
|
|
resource "google_compute_address" "foo" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2014-08-26 00:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2014-08-26 00:47:21 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
2014-08-26 06:35:23 +02:00
|
|
|
image = "debian-7-wheezy-v20140814"
|
2014-08-26 00:47:21 +02:00
|
|
|
}
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
nat_ip = "${google_compute_address.foo.address}"
|
|
|
|
}
|
2014-08-26 00:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
2014-09-02 15:52:49 +02:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_disks = fmt.Sprintf(`
|
2014-11-20 14:30:02 +01:00
|
|
|
resource "google_compute_disk" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2014-11-20 14:30:02 +01:00
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:52:49 +02:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2014-09-02 15:52:49 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
|
|
|
disk {
|
2014-11-20 14:30:02 +01:00
|
|
|
disk = "${google_compute_disk.foobar.name}"
|
2014-09-02 15:52:49 +02:00
|
|
|
auto_delete = false
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
2014-09-02 15:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
2015-05-01 03:21:21 +02:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_local_ssd = fmt.Sprintf(`
|
2015-05-12 03:40:37 +02:00
|
|
|
resource "google_compute_instance" "local-ssd" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2015-05-12 03:40:37 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
|
|
|
disk {
|
|
|
|
type = "local-ssd"
|
|
|
|
scratch = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2015-05-12 03:40:37 +02:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_service_account = fmt.Sprintf(`
|
2015-05-01 03:21:21 +02:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2015-05-01 03:21:21 +02:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_account {
|
|
|
|
scopes = [
|
|
|
|
"userinfo-email",
|
|
|
|
"compute-ro",
|
|
|
|
"storage-ro",
|
|
|
|
]
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2015-10-26 21:16:06 +01:00
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccComputeInstance_scheduling = fmt.Sprintf(`
|
2015-10-26 21:16:06 +01:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "instance-test-%s"
|
2015-10-26 21:16:06 +01:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20140814"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|