2014-08-25 21:57:17 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-09-07 14:04:26 +00:00
|
|
|
"strconv"
|
2014-09-02 13:52:49 +00:00
|
|
|
"strings"
|
2014-09-09 20:43:03 +00:00
|
|
|
"testing"
|
2017-12-11 22:07:52 +00:00
|
|
|
"time"
|
2014-08-25 21:57:17 +00:00
|
|
|
|
2016-01-05 21:47:10 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2014-08-25 21:57:17 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2015-03-18 17:10:39 +00:00
|
|
|
"google.golang.org/api/compute/v1"
|
2014-08-25 21:57:17 +00:00
|
|
|
)
|
|
|
|
|
2015-10-14 17:17:08 +00:00
|
|
|
func TestAccComputeInstance_basic1(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-08-25 21:57:17 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2014-08-25 21:57:17 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_basic(instanceName),
|
2014-08-25 21:57:17 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2017-09-13 23:18:08 +00:00
|
|
|
testAccCheckComputeInstanceHasInstanceId(&instance, "google_compute_instance.foobar"),
|
2014-08-25 22:25:45 +00:00
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
2017-06-19 22:00:34 +00:00
|
|
|
testAccCheckComputeInstanceLabel(&instance, "my_key", "my_value"),
|
2014-08-25 22:25:45 +00:00
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
2015-04-14 00:04:10 +00:00
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "baz", "qux"),
|
2016-01-06 00:49:06 +00:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2014-08-25 21:57:17 +00:00
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params", "create_timeout"},
|
|
|
|
},
|
2014-08-25 21:57:17 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-10 08:25:45 +00:00
|
|
|
func TestAccComputeInstance_basic2(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-02-10 08:25:45 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-02-10 08:25:45 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_basic2(instanceName),
|
2015-02-10 08:25:45 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
2016-01-06 00:49:06 +00:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2015-02-10 08:25:45 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_basic3(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-02-10 08:25:45 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-02-10 08:25:45 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_basic3(instanceName),
|
2015-02-10 08:25:45 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceTag(&instance, "foo"),
|
|
|
|
testAccCheckComputeInstanceMetadata(&instance, "foo", "bar"),
|
2016-01-06 00:49:06 +00:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, instanceName, true, true),
|
2015-02-10 08:25:45 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-15 21:29:58 +00:00
|
|
|
func TestAccComputeInstance_basic4(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-08-15 21:29:58 +00:00
|
|
|
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) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-08-15 21:29:58 +00:00
|
|
|
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-25 22:47:21 +00:00
|
|
|
func TestAccComputeInstance_IP(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-08-25 22:47:21 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var ipName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2014-08-25 22:47:21 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_ip(ipName, instanceName),
|
2014-08-25 22:47:21 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2015-02-06 08:21:22 +00:00
|
|
|
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
2014-08-25 22:47:21 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-11 20:33:58 +00:00
|
|
|
func TestAccComputeInstance_GenerateIP(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_generateIp(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceAccessConfigHasIP(&instance),
|
|
|
|
testAccCheckComputeInstanceHasAssignedIP,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-18 13:49:48 +00:00
|
|
|
func TestAccComputeInstance_diskEncryption(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-01-18 13:49:48 +00:00
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2017-09-07 14:04:26 +00:00
|
|
|
bootEncryptionKey := "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0="
|
|
|
|
bootEncryptionKeyHash := "esTuF7d4eatX4cnc4JsiEiaI+Rff78JgPhA/v1zxX9E="
|
|
|
|
diskNameToEncryptionKey := map[string]*compute.CustomerEncryptionKey{
|
|
|
|
fmt.Sprintf("instance-testd-%s", acctest.RandString(10)): {
|
|
|
|
RawKey: "Ym9vdDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=",
|
|
|
|
Sha256: "awJ7p57H+uVZ9axhJjl1D3lfC2MgA/wnt/z88Ltfvss=",
|
|
|
|
},
|
|
|
|
fmt.Sprintf("instance-testd-%s", acctest.RandString(10)): {
|
|
|
|
RawKey: "c2Vjb25kNzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=",
|
|
|
|
Sha256: "7TpIwUdtCOJpq2m+3nt8GFgppu6a2Xsj1t0Gexk13Yc=",
|
|
|
|
},
|
|
|
|
fmt.Sprintf("instance-testd-%s", acctest.RandString(10)): {
|
|
|
|
RawKey: "dGhpcmQ2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=",
|
|
|
|
Sha256: "b3pvaS7BjDbCKeLPPTx7yXBuQtxyMobCHN1QJR43xeM=",
|
|
|
|
},
|
|
|
|
}
|
2017-01-18 13:49:48 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-09-07 14:04:26 +00:00
|
|
|
Config: testAccComputeInstance_disks_encryption(bootEncryptionKey, diskNameToEncryptionKey, instanceName),
|
2017-01-18 13:49:48 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2017-09-07 14:04:26 +00:00
|
|
|
testAccCheckComputeInstanceDiskEncryptionKey("google_compute_instance.foobar", &instance, bootEncryptionKeyHash, diskNameToEncryptionKey),
|
2017-01-18 13:49:48 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-25 20:20:02 +00:00
|
|
|
func TestAccComputeInstance_attachedDisk(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-04-25 20:20:02 +00:00
|
|
|
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_attachedDisk(diskName, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
2017-10-23 19:53:41 +00:00
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
2017-04-25 20:20:02 +00:00
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-04-25 20:20:02 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:26:59 +00:00
|
|
|
func TestAccComputeInstance_attachedDisk_sourceUrl(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
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_attachedDisk_sourceUrl(diskName, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-10-23 20:26:59 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:08:02 +00:00
|
|
|
func TestAccComputeInstance_attachedDiskUpdate(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
|
|
|
var diskName2 = 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_attachedDisk(diskName, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
// check attaching
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_addAttachedDisk(diskName, diskName2, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName2, false, false),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
// check detaching
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_detachDisk(diskName, diskName2, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
// check updating
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_updateAttachedDiskEncryptionKey(diskName, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceDisk(&instance, diskName, false, false),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-28 22:36:00 +00:00
|
|
|
func TestAccComputeInstance_bootDisk_source(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-06-28 22:36:00 +00:00
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var diskName = 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_bootDisk_source(diskName, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceBootDisk(&instance, diskName),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
},
|
2017-06-28 22:36:00 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:26:59 +00:00
|
|
|
func TestAccComputeInstance_bootDisk_sourceUrl(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var diskName = 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_bootDisk_sourceUrl(diskName, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceBootDisk(&instance, diskName),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-10-23 20:26:59 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:39:32 +00:00
|
|
|
func TestAccComputeInstance_bootDisk_type(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-01 22:39:32 +00:00
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var diskType = "pd-ssd"
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_bootDisk_type(instanceName, diskType),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceBootDiskType(instanceName, diskType),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-28 22:43:58 +00:00
|
|
|
func TestAccComputeInstance_scratchDisk(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-06-28 22:43:58 +00:00
|
|
|
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_scratchDisk(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.scratch", &instance),
|
|
|
|
testAccCheckComputeInstanceScratchDisk(&instance, []string{"NVME", "SCSI"}),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-06-28 22:43:58 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-13 23:56:48 +00:00
|
|
|
func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-04-13 23:56:48 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-04-13 23:56:48 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_basic(instanceName),
|
2015-04-13 23:56:48 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_forceNewAndChangeMetadata(instanceName),
|
2015-04-13 23:56:48 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceMetadata(
|
|
|
|
&instance, "qux", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-08-26 20:48:49 +00:00
|
|
|
func TestAccComputeInstance_update(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-08-26 20:48:49 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2014-08-26 20:48:49 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_basic(instanceName),
|
2014-08-26 20:48:49 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_update(instanceName),
|
2014-08-26 20:48:49 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceMetadata(
|
|
|
|
&instance, "bar", "baz"),
|
2017-06-19 22:00:34 +00:00
|
|
|
testAccCheckComputeInstanceLabel(&instance, "only_me", "nothing_else"),
|
2014-08-26 20:52:18 +00:00
|
|
|
testAccCheckComputeInstanceTag(&instance, "baz"),
|
2015-02-06 08:21:22 +00:00
|
|
|
testAccCheckComputeInstanceAccessConfig(&instance),
|
2014-08-26 20:48:49 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-01 01:21:21 +00:00
|
|
|
func TestAccComputeInstance_service_account(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-05-01 01:21:21 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-05-01 01:21:21 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_service_account(instanceName),
|
2015-05-01 01:21:21 +00: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"),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2015-05-01 01:21:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:16:06 +00:00
|
|
|
func TestAccComputeInstance_scheduling(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-10-26 20:16:06 +00:00
|
|
|
var instance compute.Instance
|
2016-01-06 00:49:06 +00:00
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2015-10-26 20:16:06 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeInstance_scheduling(instanceName),
|
2015-10-26 20:16:06 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2015-10-26 20:16:06 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
func TestAccComputeInstance_subnet_auto(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2016-02-17 11:09:46 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_subnet_custom(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2016-02-17 11:09:46 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-27 15:25:58 +00:00
|
|
|
func TestAccComputeInstance_subnet_xpn(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-10-27 15:25:58 +00:00
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
2017-12-11 22:07:52 +00:00
|
|
|
org := getTestOrgFromEnv(t)
|
|
|
|
billingId := getTestBillingAccountFromEnv(t)
|
|
|
|
projectName := fmt.Sprintf("tf-xpntest-%d", time.Now().Unix())
|
2016-10-27 15:25:58 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-12-11 22:07:52 +00:00
|
|
|
Config: testAccComputeInstance_subnet_xpn(org, billingId, projectName, instanceName),
|
2016-10-27 15:25:58 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-12-11 22:07:52 +00:00
|
|
|
testAccCheckComputeInstanceExistsInProject(
|
|
|
|
"google_compute_instance.foobar", fmt.Sprintf("%s-service", projectName),
|
|
|
|
&instance),
|
2016-10-27 15:25:58 +00:00
|
|
|
testAccCheckComputeInstanceHasSubnet(&instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-08 01:01:31 +00:00
|
|
|
func TestAccComputeInstance_address_auto(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-08-08 01:01:31 +00:00
|
|
|
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) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-08-08 01:01:31 +00:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-11-01 21:00:12 +00:00
|
|
|
|
|
|
|
func TestAccComputeInstance_private_image_family(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-11-01 21:00:12 +00:00
|
|
|
var instance compute.Instance
|
|
|
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
|
|
|
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
|
|
|
var imageName = fmt.Sprintf("instance-testi-%s", acctest.RandString(10))
|
|
|
|
var familyName = fmt.Sprintf("instance-testf-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_private_image_family(diskName, imageName, familyName, instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists(
|
|
|
|
"google_compute_instance.foobar", &instance),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-03 11:50:57 +00:00
|
|
|
func TestAccComputeInstance_forceChangeMachineTypeManually(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-02-03 11:50:57 +00:00
|
|
|
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_basic(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists("google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceUpdateMachineType("google_compute_instance.foobar"),
|
|
|
|
),
|
|
|
|
ExpectNonEmptyPlan: true,
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params", "create_timeout"},
|
|
|
|
},
|
2017-02-03 11:50:57 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-04 21:18:07 +00:00
|
|
|
func TestAccComputeInstance_multiNic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-04 21:18:07 +00:00
|
|
|
var instance compute.Instance
|
|
|
|
instanceName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
|
|
|
networkName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
|
|
|
subnetworkName := fmt.Sprintf("terraform-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_multiNic(instanceName, networkName, subnetworkName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceExists("google_compute_instance.foobar", &instance),
|
|
|
|
testAccCheckComputeInstanceHasMultiNic(&instance),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-central1-a", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-08-04 21:18:07 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-22 19:49:43 +00:00
|
|
|
func TestAccComputeInstance_guestAccelerator(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
Add Alias IP and Guest Accelerator support to Instance Templates (#639)
* Move AliasIpRange helpers into utils
To reflect the fact they'll be used by multiple resources.
* Pass Config to build helpers, not meta
It's the only thing meta is used for.
* Refactor getNetwork util methods to return early for the happy path.
* Update compute APIs
compute.Instance.MinCpuPlatform is now GA.
* Fix panic in TestComputeInstanceMigrateState
This seemed to be a pre-existing issue, i.e. I could repro it in master.
--- FAIL: TestComputeInstanceMigrateState (0.00s)
panic: interface conversion: interface {} is nil, not *google.Config [recovered]
panic: interface conversion: interface {} is nil, not *google.Config
goroutine 85 [running]:
testing.tRunner.func1(0xc4205d60f0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:711 +0x2d2
panic(0x203acc0, 0xc4205d2080)
/usr/local/Cellar/go/1.9.1/libexec/src/runtime/panic.go:491 +0x283
github.com/terraform-providers/terraform-provider-google/google.migrateStateV3toV4(0xc4205f2000, 0x0, 0x0, 0x0, 0x48, 0xc4205f2000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:182 +0x2405
github.com/terraform-providers/terraform-provider-google/google.resourceComputeInstanceMigrateState(0x2, 0xc4205f2000, 0x0, 0x0, 0x0, 0x0, 0xe0000000000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:48 +0x21a
github.com/terraform-providers/terraform-provider-google/google.runInstanceMigrateTest(0xc4205d60f0, 0x2260816, 0x8, 0x227d23a, 0x20, 0x2, 0xc4205ec0f0, 0xc4205ec120, 0x0,
0x0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:803 +0xc1
github.com/terraform-providers/terraform-provider-google/google.TestComputeInstanceMigrateState(0xc4205d60f0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:71 +0xc84
testing.tRunner(0xc4205d60f0, 0x22d81c0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:789 +0x2de
FAIL github.com/terraform-providers/terraform-provider-google/google 0.035s
* Use only the v1 API for resource_compute_instance
Alias IP ranges, Accelerators, and min CPU platform are now GA.
* Move common instance code into utils.go
Methods used by both resource_compute_instance and
resource_compute_instance_template are currently spread between their respective
files, and utils.go.
This commit moves them all into utils.go for the sake of consistency. It may be
worth considering an instance_common.go file or similar.
* Unify compute_instance and compute_instance_template network_interface and service_account code
This has the side effect of enabling Alias IP range support for
compute_instance_templates.
* Add tests for compute instance template Alias IP ranges
* Mark instance template region as computed
We compute it from the subnet its network interfaces are in. Note this
is not new behaviour - I believe it was erroneously missing the computed
flag.
* Support guest accelerators for instance templates
Since most of the code is already there.
* Add a test for using 'address' rather than 'network_ip' for instance templates
* Don't mark assigned_nat_ip as deprecated
* Remove network_interface schema fields that don't make sense for a compute instance template
* Add newline after count in instance template docs
* Don't try to dedupe guest accelerator expansion code
The API calls to Google to create guest accelerators take different values
for instances and instance templates. Instance templates don't have a zone
and can thus *only* be passed a guest accelerator name.
* Use ParseNetworkFieldValue instead of getNetworkLink
* Add support for parsing regional fields, and subnetworks specifically
Currently unused because subnetworks may have a separate project from that
of the instance using them, which complicates looking up the project field.
* Fall back to provider region when parsing regional field values
Also slightly refactors getXFromSchema field helper functions for readability.
* Revert to assigned_nat_ip in compute instance docs
* Add beta scaffolding to compute instance and compute instance template
Note these resources don't currently use beta features - this is futureproofing.
* Fix indentation in comment about instance template alias IP ranges
* Consolidate metadata helper functions in metadata.go
* Move compute instance (and template) related helpers into their own file
2017-11-28 18:01:27 +00:00
|
|
|
var instance compute.Instance
|
2017-08-22 19:49:43 +00:00
|
|
|
instanceName := fmt.Sprintf("terraform-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_guestAccelerator(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
Add Alias IP and Guest Accelerator support to Instance Templates (#639)
* Move AliasIpRange helpers into utils
To reflect the fact they'll be used by multiple resources.
* Pass Config to build helpers, not meta
It's the only thing meta is used for.
* Refactor getNetwork util methods to return early for the happy path.
* Update compute APIs
compute.Instance.MinCpuPlatform is now GA.
* Fix panic in TestComputeInstanceMigrateState
This seemed to be a pre-existing issue, i.e. I could repro it in master.
--- FAIL: TestComputeInstanceMigrateState (0.00s)
panic: interface conversion: interface {} is nil, not *google.Config [recovered]
panic: interface conversion: interface {} is nil, not *google.Config
goroutine 85 [running]:
testing.tRunner.func1(0xc4205d60f0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:711 +0x2d2
panic(0x203acc0, 0xc4205d2080)
/usr/local/Cellar/go/1.9.1/libexec/src/runtime/panic.go:491 +0x283
github.com/terraform-providers/terraform-provider-google/google.migrateStateV3toV4(0xc4205f2000, 0x0, 0x0, 0x0, 0x48, 0xc4205f2000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:182 +0x2405
github.com/terraform-providers/terraform-provider-google/google.resourceComputeInstanceMigrateState(0x2, 0xc4205f2000, 0x0, 0x0, 0x0, 0x0, 0xe0000000000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:48 +0x21a
github.com/terraform-providers/terraform-provider-google/google.runInstanceMigrateTest(0xc4205d60f0, 0x2260816, 0x8, 0x227d23a, 0x20, 0x2, 0xc4205ec0f0, 0xc4205ec120, 0x0,
0x0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:803 +0xc1
github.com/terraform-providers/terraform-provider-google/google.TestComputeInstanceMigrateState(0xc4205d60f0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:71 +0xc84
testing.tRunner(0xc4205d60f0, 0x22d81c0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:789 +0x2de
FAIL github.com/terraform-providers/terraform-provider-google/google 0.035s
* Use only the v1 API for resource_compute_instance
Alias IP ranges, Accelerators, and min CPU platform are now GA.
* Move common instance code into utils.go
Methods used by both resource_compute_instance and
resource_compute_instance_template are currently spread between their respective
files, and utils.go.
This commit moves them all into utils.go for the sake of consistency. It may be
worth considering an instance_common.go file or similar.
* Unify compute_instance and compute_instance_template network_interface and service_account code
This has the side effect of enabling Alias IP range support for
compute_instance_templates.
* Add tests for compute instance template Alias IP ranges
* Mark instance template region as computed
We compute it from the subnet its network interfaces are in. Note this
is not new behaviour - I believe it was erroneously missing the computed
flag.
* Support guest accelerators for instance templates
Since most of the code is already there.
* Add a test for using 'address' rather than 'network_ip' for instance templates
* Don't mark assigned_nat_ip as deprecated
* Remove network_interface schema fields that don't make sense for a compute instance template
* Add newline after count in instance template docs
* Don't try to dedupe guest accelerator expansion code
The API calls to Google to create guest accelerators take different values
for instances and instance templates. Instance templates don't have a zone
and can thus *only* be passed a guest accelerator name.
* Use ParseNetworkFieldValue instead of getNetworkLink
* Add support for parsing regional fields, and subnetworks specifically
Currently unused because subnetworks may have a separate project from that
of the instance using them, which complicates looking up the project field.
* Fall back to provider region when parsing regional field values
Also slightly refactors getXFromSchema field helper functions for readability.
* Revert to assigned_nat_ip in compute instance docs
* Add beta scaffolding to compute instance and compute instance template
Note these resources don't currently use beta features - this is futureproofing.
* Fix indentation in comment about instance template alias IP ranges
* Consolidate metadata helper functions in metadata.go
* Move compute instance (and template) related helpers into their own file
2017-11-28 18:01:27 +00:00
|
|
|
testAccCheckComputeInstanceExists("google_compute_instance.foobar", &instance),
|
2017-08-22 19:49:43 +00:00
|
|
|
testAccCheckComputeInstanceHasGuestAccelerator(&instance, "nvidia-tesla-k80", 1),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-08-22 19:49:43 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-30 21:25:31 +00:00
|
|
|
func TestAccComputeInstance_minCpuPlatform(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
Add Alias IP and Guest Accelerator support to Instance Templates (#639)
* Move AliasIpRange helpers into utils
To reflect the fact they'll be used by multiple resources.
* Pass Config to build helpers, not meta
It's the only thing meta is used for.
* Refactor getNetwork util methods to return early for the happy path.
* Update compute APIs
compute.Instance.MinCpuPlatform is now GA.
* Fix panic in TestComputeInstanceMigrateState
This seemed to be a pre-existing issue, i.e. I could repro it in master.
--- FAIL: TestComputeInstanceMigrateState (0.00s)
panic: interface conversion: interface {} is nil, not *google.Config [recovered]
panic: interface conversion: interface {} is nil, not *google.Config
goroutine 85 [running]:
testing.tRunner.func1(0xc4205d60f0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:711 +0x2d2
panic(0x203acc0, 0xc4205d2080)
/usr/local/Cellar/go/1.9.1/libexec/src/runtime/panic.go:491 +0x283
github.com/terraform-providers/terraform-provider-google/google.migrateStateV3toV4(0xc4205f2000, 0x0, 0x0, 0x0, 0x48, 0xc4205f2000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:182 +0x2405
github.com/terraform-providers/terraform-provider-google/google.resourceComputeInstanceMigrateState(0x2, 0xc4205f2000, 0x0, 0x0, 0x0, 0x0, 0xe0000000000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:48 +0x21a
github.com/terraform-providers/terraform-provider-google/google.runInstanceMigrateTest(0xc4205d60f0, 0x2260816, 0x8, 0x227d23a, 0x20, 0x2, 0xc4205ec0f0, 0xc4205ec120, 0x0,
0x0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:803 +0xc1
github.com/terraform-providers/terraform-provider-google/google.TestComputeInstanceMigrateState(0xc4205d60f0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:71 +0xc84
testing.tRunner(0xc4205d60f0, 0x22d81c0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:789 +0x2de
FAIL github.com/terraform-providers/terraform-provider-google/google 0.035s
* Use only the v1 API for resource_compute_instance
Alias IP ranges, Accelerators, and min CPU platform are now GA.
* Move common instance code into utils.go
Methods used by both resource_compute_instance and
resource_compute_instance_template are currently spread between their respective
files, and utils.go.
This commit moves them all into utils.go for the sake of consistency. It may be
worth considering an instance_common.go file or similar.
* Unify compute_instance and compute_instance_template network_interface and service_account code
This has the side effect of enabling Alias IP range support for
compute_instance_templates.
* Add tests for compute instance template Alias IP ranges
* Mark instance template region as computed
We compute it from the subnet its network interfaces are in. Note this
is not new behaviour - I believe it was erroneously missing the computed
flag.
* Support guest accelerators for instance templates
Since most of the code is already there.
* Add a test for using 'address' rather than 'network_ip' for instance templates
* Don't mark assigned_nat_ip as deprecated
* Remove network_interface schema fields that don't make sense for a compute instance template
* Add newline after count in instance template docs
* Don't try to dedupe guest accelerator expansion code
The API calls to Google to create guest accelerators take different values
for instances and instance templates. Instance templates don't have a zone
and can thus *only* be passed a guest accelerator name.
* Use ParseNetworkFieldValue instead of getNetworkLink
* Add support for parsing regional fields, and subnetworks specifically
Currently unused because subnetworks may have a separate project from that
of the instance using them, which complicates looking up the project field.
* Fall back to provider region when parsing regional field values
Also slightly refactors getXFromSchema field helper functions for readability.
* Revert to assigned_nat_ip in compute instance docs
* Add beta scaffolding to compute instance and compute instance template
Note these resources don't currently use beta features - this is futureproofing.
* Fix indentation in comment about instance template alias IP ranges
* Consolidate metadata helper functions in metadata.go
* Move compute instance (and template) related helpers into their own file
2017-11-28 18:01:27 +00:00
|
|
|
var instance compute.Instance
|
2017-08-30 21:25:31 +00:00
|
|
|
instanceName := fmt.Sprintf("terraform-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_minCpuPlatform(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
Add Alias IP and Guest Accelerator support to Instance Templates (#639)
* Move AliasIpRange helpers into utils
To reflect the fact they'll be used by multiple resources.
* Pass Config to build helpers, not meta
It's the only thing meta is used for.
* Refactor getNetwork util methods to return early for the happy path.
* Update compute APIs
compute.Instance.MinCpuPlatform is now GA.
* Fix panic in TestComputeInstanceMigrateState
This seemed to be a pre-existing issue, i.e. I could repro it in master.
--- FAIL: TestComputeInstanceMigrateState (0.00s)
panic: interface conversion: interface {} is nil, not *google.Config [recovered]
panic: interface conversion: interface {} is nil, not *google.Config
goroutine 85 [running]:
testing.tRunner.func1(0xc4205d60f0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:711 +0x2d2
panic(0x203acc0, 0xc4205d2080)
/usr/local/Cellar/go/1.9.1/libexec/src/runtime/panic.go:491 +0x283
github.com/terraform-providers/terraform-provider-google/google.migrateStateV3toV4(0xc4205f2000, 0x0, 0x0, 0x0, 0x48, 0xc4205f2000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:182 +0x2405
github.com/terraform-providers/terraform-provider-google/google.resourceComputeInstanceMigrateState(0x2, 0xc4205f2000, 0x0, 0x0, 0x0, 0x0, 0xe0000000000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:48 +0x21a
github.com/terraform-providers/terraform-provider-google/google.runInstanceMigrateTest(0xc4205d60f0, 0x2260816, 0x8, 0x227d23a, 0x20, 0x2, 0xc4205ec0f0, 0xc4205ec120, 0x0,
0x0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:803 +0xc1
github.com/terraform-providers/terraform-provider-google/google.TestComputeInstanceMigrateState(0xc4205d60f0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:71 +0xc84
testing.tRunner(0xc4205d60f0, 0x22d81c0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:789 +0x2de
FAIL github.com/terraform-providers/terraform-provider-google/google 0.035s
* Use only the v1 API for resource_compute_instance
Alias IP ranges, Accelerators, and min CPU platform are now GA.
* Move common instance code into utils.go
Methods used by both resource_compute_instance and
resource_compute_instance_template are currently spread between their respective
files, and utils.go.
This commit moves them all into utils.go for the sake of consistency. It may be
worth considering an instance_common.go file or similar.
* Unify compute_instance and compute_instance_template network_interface and service_account code
This has the side effect of enabling Alias IP range support for
compute_instance_templates.
* Add tests for compute instance template Alias IP ranges
* Mark instance template region as computed
We compute it from the subnet its network interfaces are in. Note this
is not new behaviour - I believe it was erroneously missing the computed
flag.
* Support guest accelerators for instance templates
Since most of the code is already there.
* Add a test for using 'address' rather than 'network_ip' for instance templates
* Don't mark assigned_nat_ip as deprecated
* Remove network_interface schema fields that don't make sense for a compute instance template
* Add newline after count in instance template docs
* Don't try to dedupe guest accelerator expansion code
The API calls to Google to create guest accelerators take different values
for instances and instance templates. Instance templates don't have a zone
and can thus *only* be passed a guest accelerator name.
* Use ParseNetworkFieldValue instead of getNetworkLink
* Add support for parsing regional fields, and subnetworks specifically
Currently unused because subnetworks may have a separate project from that
of the instance using them, which complicates looking up the project field.
* Fall back to provider region when parsing regional field values
Also slightly refactors getXFromSchema field helper functions for readability.
* Revert to assigned_nat_ip in compute instance docs
* Add beta scaffolding to compute instance and compute instance template
Note these resources don't currently use beta features - this is futureproofing.
* Fix indentation in comment about instance template alias IP ranges
* Consolidate metadata helper functions in metadata.go
* Move compute instance (and template) related helpers into their own file
2017-11-28 18:01:27 +00:00
|
|
|
testAccCheckComputeInstanceExists("google_compute_instance.foobar", &instance),
|
2017-08-30 21:25:31 +00:00
|
|
|
testAccCheckComputeInstanceHasMinCpuPlatform(&instance, "Intel Haswell"),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-08-30 21:25:31 +00:00
|
|
|
},
|
|
|
|
})
|
2017-09-07 20:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_primaryAliasIpRange(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-09-27 23:12:21 +00:00
|
|
|
var instance compute.Instance
|
2017-09-07 20:43:00 +00:00
|
|
|
instanceName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
2017-08-30 21:25:31 +00:00
|
|
|
|
2017-09-07 20:43:00 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstance_primaryAliasIpRange(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-09-27 23:12:21 +00:00
|
|
|
testAccCheckComputeInstanceExists("google_compute_instance.foobar", &instance),
|
2017-09-07 20:43:00 +00:00
|
|
|
testAccCheckComputeInstanceHasAliasIpRange(&instance, "", "/24"),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-09-07 20:43:00 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstance_secondaryAliasIpRange(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-09-27 23:12:21 +00:00
|
|
|
var instance compute.Instance
|
2017-09-07 20:43:00 +00:00
|
|
|
instanceName := fmt.Sprintf("terraform-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_secondaryAliasIpRange(instanceName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-09-27 23:12:21 +00:00
|
|
|
testAccCheckComputeInstanceExists("google_compute_instance.foobar", &instance),
|
2017-09-07 20:43:00 +00:00
|
|
|
testAccCheckComputeInstanceHasAliasIpRange(&instance, "inst-test-secondary", "172.16.0.0/24"),
|
|
|
|
),
|
|
|
|
},
|
2017-12-19 22:33:30 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateId: fmt.Sprintf("%s/%s/%s", getTestProjectFromEnv(), "us-east1-d", instanceName),
|
|
|
|
ImportStateVerifyIgnore: []string{"boot_disk.0.initialize_params"},
|
|
|
|
},
|
2017-09-07 20:43:00 +00:00
|
|
|
},
|
|
|
|
})
|
2017-08-30 21:25:31 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 11:50:57 +00:00
|
|
|
func testAccCheckComputeInstanceUpdateMachineType(n 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")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
op, err := config.clientCompute.Instances.Stop(config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Could not stop instance: %s", err)
|
|
|
|
}
|
2017-10-13 22:36:03 +00:00
|
|
|
err = computeOperationWait(config.clientCompute, op, config.Project, "Waiting on stop")
|
2017-02-03 11:50:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Could not stop instance: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
machineType := compute.InstancesSetMachineTypeRequest{
|
|
|
|
MachineType: "zones/us-central1-a/machineTypes/f1-micro",
|
|
|
|
}
|
|
|
|
|
|
|
|
op, err = config.clientCompute.Instances.SetMachineType(
|
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID, &machineType).Do()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Could not change machine type: %s", err)
|
|
|
|
}
|
2017-10-13 22:36:03 +00:00
|
|
|
err = computeOperationWait(config.clientCompute, op, config.Project, "Waiting machine type change")
|
2017-02-03 11:50:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Could not change machine type: %s", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-25 21:57:17 +00:00
|
|
|
func testAccCheckComputeInstanceDestroy(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
2014-09-17 00:16:53 +00:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-08-25 21:57:17 +00:00
|
|
|
if rs.Type != "google_compute_instance" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := config.clientCompute.Instances.Get(
|
2014-09-17 00:16:53 +00:00
|
|
|
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
2014-08-25 21:57:17 +00:00
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Instance still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceExists(n string, instance *compute.Instance) resource.TestCheckFunc {
|
2017-12-11 22:07:52 +00:00
|
|
|
return testAccCheckComputeInstanceExistsInProject(n, getTestProjectFromEnv(), instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceExistsInProject(n, p string, instance *compute.Instance) resource.TestCheckFunc {
|
2014-08-25 21:57:17 +00:00
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 00:16:53 +00:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-08-25 21:57:17 +00:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 00:16:53 +00:00
|
|
|
if rs.Primary.ID == "" {
|
2014-08-25 21:57:17 +00:00
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
found, err := config.clientCompute.Instances.Get(
|
2017-12-11 22:07:52 +00:00
|
|
|
p, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
|
2014-08-25 21:57:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-09-17 00:16:53 +00:00
|
|
|
if found.Name != rs.Primary.ID {
|
2014-08-25 21:57:17 +00:00
|
|
|
return fmt.Errorf("Instance not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*instance = *found
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-25 22:25:45 +00: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 14:06:25 +00:00
|
|
|
if item.Value != nil && v == *item.Value {
|
2014-08-25 22:25:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:06:25 +00:00
|
|
|
return fmt.Errorf("bad value for %s: %s", k, *item.Value)
|
2014-08-25 22:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("metadata not found: %s", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 08:21:22 +00: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-25 22:47:21 +00: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 13:52:49 +00: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 {
|
2017-06-28 22:43:58 +00:00
|
|
|
if strings.HasSuffix(disk.Source, "/"+source) && disk.AutoDelete == delete && disk.Boot == boot {
|
2014-09-02 13:52:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Disk not found: %s", source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 23:18:08 +00:00
|
|
|
func testAccCheckComputeInstanceHasInstanceId(instance *compute.Instance, n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
remote := fmt.Sprintf("%d", instance.Id)
|
|
|
|
local := rs.Primary.Attributes["instance_id"]
|
|
|
|
|
|
|
|
if remote != local {
|
|
|
|
return fmt.Errorf("Instance id stored does not match: remote has %#v but local has %#v", remote,
|
|
|
|
local)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-28 22:36:00 +00:00
|
|
|
func testAccCheckComputeInstanceBootDisk(instance *compute.Instance, source string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instance.Disks == nil {
|
|
|
|
return fmt.Errorf("no disks")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, disk := range instance.Disks {
|
|
|
|
if disk.Boot == true {
|
|
|
|
if strings.HasSuffix(disk.Source, source) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Boot disk not found with source %q", source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:39:32 +00:00
|
|
|
func testAccCheckComputeInstanceBootDiskType(instanceName string, diskType string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
// boot disk is named the same as the Instance
|
|
|
|
disk, err := config.clientCompute.Disks.Get(config.Project, "us-central1-a", instanceName).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if strings.Contains(disk.Type, diskType) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Boot disk not found with type %q", diskType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-28 22:43:58 +00:00
|
|
|
func testAccCheckComputeInstanceScratchDisk(instance *compute.Instance, interfaces []string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instance.Disks == nil {
|
|
|
|
return fmt.Errorf("no disks")
|
|
|
|
}
|
|
|
|
|
|
|
|
i := 0
|
|
|
|
for _, disk := range instance.Disks {
|
|
|
|
if disk.Type == "SCRATCH" {
|
|
|
|
if i >= len(interfaces) {
|
|
|
|
return fmt.Errorf("Expected %d scratch disks, found more", len(interfaces))
|
|
|
|
}
|
|
|
|
if disk.Interface != interfaces[i] {
|
|
|
|
return fmt.Errorf("Mismatched interface on scratch disk #%d, expected: %q, found: %q",
|
|
|
|
i, interfaces[i], disk.Interface)
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if i != len(interfaces) {
|
|
|
|
return fmt.Errorf("Expected %d scratch disks, found %d", len(interfaces), i)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 14:04:26 +00:00
|
|
|
func testAccCheckComputeInstanceDiskEncryptionKey(n string, instance *compute.Instance, bootDiskEncryptionKey string, diskNameToEncryptionKey map[string]*compute.CustomerEncryptionKey) resource.TestCheckFunc {
|
2017-01-18 13:49:48 +00:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, disk := range instance.Disks {
|
2017-09-07 14:04:26 +00:00
|
|
|
if disk.Boot {
|
|
|
|
attr := rs.Primary.Attributes["boot_disk.0.disk_encryption_key_sha256"]
|
|
|
|
if attr != bootDiskEncryptionKey {
|
|
|
|
return fmt.Errorf("Boot disk has wrong encryption key in state.\nExpected: %s\nActual: %s", bootDiskEncryptionKey, attr)
|
|
|
|
}
|
|
|
|
if disk.DiskEncryptionKey == nil && attr != "" {
|
|
|
|
return fmt.Errorf("Disk %d has mismatched encryption key.\nTF State: %+v\nGCP State: <empty>", i, attr)
|
|
|
|
}
|
|
|
|
if disk.DiskEncryptionKey != nil && attr != disk.DiskEncryptionKey.Sha256 {
|
|
|
|
return fmt.Errorf("Disk %d has mismatched encryption key.\nTF State: %+v\nGCP State: %+v",
|
|
|
|
i, attr, disk.DiskEncryptionKey.Sha256)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if disk.DiskEncryptionKey != nil {
|
|
|
|
sourceUrl := strings.Split(disk.Source, "/")
|
|
|
|
expectedKey := diskNameToEncryptionKey[sourceUrl[len(sourceUrl)-1]].Sha256
|
|
|
|
if disk.DiskEncryptionKey.Sha256 != expectedKey {
|
|
|
|
return fmt.Errorf("Disk %d has unexpected encryption key in GCP.\nExpected: %s\nActual: %s", i, expectedKey, disk.DiskEncryptionKey.Sha256)
|
|
|
|
}
|
|
|
|
}
|
2017-07-14 17:57:23 +00:00
|
|
|
}
|
2017-09-07 14:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
numAttachedDisks, err := strconv.Atoi(rs.Primary.Attributes["attached_disk.#"])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error converting value of attached_disk.#")
|
|
|
|
}
|
|
|
|
for i := 0; i < numAttachedDisks; i++ {
|
|
|
|
diskSourceUrl := strings.Split(rs.Primary.Attributes[fmt.Sprintf("attached_disk.%d.source", i)], "/")
|
|
|
|
diskName := diskSourceUrl[len(diskSourceUrl)-1]
|
|
|
|
encryptionKey := rs.Primary.Attributes[fmt.Sprintf("attached_disk.%d.disk_encryption_key_sha256", i)]
|
|
|
|
if key, ok := diskNameToEncryptionKey[diskName]; ok {
|
|
|
|
expectedEncryptionKey := key.Sha256
|
|
|
|
if encryptionKey != expectedEncryptionKey {
|
|
|
|
return fmt.Errorf("Attached disk %d has unexpected encryption key in state.\nExpected: %s\nActual: %s", i, expectedEncryptionKey, encryptionKey)
|
|
|
|
}
|
2017-01-18 13:49:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-25 22:25:45 +00:00
|
|
|
func testAccCheckComputeInstanceTag(instance *compute.Instance, n string) resource.TestCheckFunc {
|
2014-08-25 22:10:30 +00: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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 22:00:34 +00:00
|
|
|
func testAccCheckComputeInstanceLabel(instance *compute.Instance, key string, value string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instance.Labels == nil {
|
|
|
|
return fmt.Errorf("no labels found on instance %s", instance.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
v, ok := instance.Labels[key]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("No label found with key %s on instance %s", key, instance.Name)
|
|
|
|
}
|
|
|
|
if v != value {
|
|
|
|
return fmt.Errorf("Expected value '%s' but found value '%s' for label '%s' on instance %s", value, v, key, instance.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 01:21:21 +00: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 11:09:46 +00: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 01:01:31 +00: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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 21:18:07 +00:00
|
|
|
func testAccCheckComputeInstanceHasMultiNic(instance *compute.Instance) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if len(instance.NetworkInterfaces) < 2 {
|
|
|
|
return fmt.Errorf("only saw %d nics", len(instance.NetworkInterfaces))
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add Alias IP and Guest Accelerator support to Instance Templates (#639)
* Move AliasIpRange helpers into utils
To reflect the fact they'll be used by multiple resources.
* Pass Config to build helpers, not meta
It's the only thing meta is used for.
* Refactor getNetwork util methods to return early for the happy path.
* Update compute APIs
compute.Instance.MinCpuPlatform is now GA.
* Fix panic in TestComputeInstanceMigrateState
This seemed to be a pre-existing issue, i.e. I could repro it in master.
--- FAIL: TestComputeInstanceMigrateState (0.00s)
panic: interface conversion: interface {} is nil, not *google.Config [recovered]
panic: interface conversion: interface {} is nil, not *google.Config
goroutine 85 [running]:
testing.tRunner.func1(0xc4205d60f0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:711 +0x2d2
panic(0x203acc0, 0xc4205d2080)
/usr/local/Cellar/go/1.9.1/libexec/src/runtime/panic.go:491 +0x283
github.com/terraform-providers/terraform-provider-google/google.migrateStateV3toV4(0xc4205f2000, 0x0, 0x0, 0x0, 0x48, 0xc4205f2000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:182 +0x2405
github.com/terraform-providers/terraform-provider-google/google.resourceComputeInstanceMigrateState(0x2, 0xc4205f2000, 0x0, 0x0, 0x0, 0x0, 0xe0000000000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:48 +0x21a
github.com/terraform-providers/terraform-provider-google/google.runInstanceMigrateTest(0xc4205d60f0, 0x2260816, 0x8, 0x227d23a, 0x20, 0x2, 0xc4205ec0f0, 0xc4205ec120, 0x0,
0x0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:803 +0xc1
github.com/terraform-providers/terraform-provider-google/google.TestComputeInstanceMigrateState(0xc4205d60f0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:71 +0xc84
testing.tRunner(0xc4205d60f0, 0x22d81c0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:789 +0x2de
FAIL github.com/terraform-providers/terraform-provider-google/google 0.035s
* Use only the v1 API for resource_compute_instance
Alias IP ranges, Accelerators, and min CPU platform are now GA.
* Move common instance code into utils.go
Methods used by both resource_compute_instance and
resource_compute_instance_template are currently spread between their respective
files, and utils.go.
This commit moves them all into utils.go for the sake of consistency. It may be
worth considering an instance_common.go file or similar.
* Unify compute_instance and compute_instance_template network_interface and service_account code
This has the side effect of enabling Alias IP range support for
compute_instance_templates.
* Add tests for compute instance template Alias IP ranges
* Mark instance template region as computed
We compute it from the subnet its network interfaces are in. Note this
is not new behaviour - I believe it was erroneously missing the computed
flag.
* Support guest accelerators for instance templates
Since most of the code is already there.
* Add a test for using 'address' rather than 'network_ip' for instance templates
* Don't mark assigned_nat_ip as deprecated
* Remove network_interface schema fields that don't make sense for a compute instance template
* Add newline after count in instance template docs
* Don't try to dedupe guest accelerator expansion code
The API calls to Google to create guest accelerators take different values
for instances and instance templates. Instance templates don't have a zone
and can thus *only* be passed a guest accelerator name.
* Use ParseNetworkFieldValue instead of getNetworkLink
* Add support for parsing regional fields, and subnetworks specifically
Currently unused because subnetworks may have a separate project from that
of the instance using them, which complicates looking up the project field.
* Fall back to provider region when parsing regional field values
Also slightly refactors getXFromSchema field helper functions for readability.
* Revert to assigned_nat_ip in compute instance docs
* Add beta scaffolding to compute instance and compute instance template
Note these resources don't currently use beta features - this is futureproofing.
* Fix indentation in comment about instance template alias IP ranges
* Consolidate metadata helper functions in metadata.go
* Move compute instance (and template) related helpers into their own file
2017-11-28 18:01:27 +00:00
|
|
|
func testAccCheckComputeInstanceHasGuestAccelerator(instance *compute.Instance, acceleratorType string, acceleratorCount int64) resource.TestCheckFunc {
|
2017-08-22 19:49:43 +00:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if len(instance.GuestAccelerators) != 1 {
|
|
|
|
return fmt.Errorf("Expected only one guest accelerator")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasSuffix(instance.GuestAccelerators[0].AcceleratorType, acceleratorType) {
|
|
|
|
return fmt.Errorf("Wrong accelerator type: expected %v, got %v", acceleratorType, instance.GuestAccelerators[0].AcceleratorType)
|
|
|
|
}
|
|
|
|
|
|
|
|
if instance.GuestAccelerators[0].AcceleratorCount != acceleratorCount {
|
|
|
|
return fmt.Errorf("Wrong accelerator acceleratorCount: expected %d, got %d", acceleratorCount, instance.GuestAccelerators[0].AcceleratorCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add Alias IP and Guest Accelerator support to Instance Templates (#639)
* Move AliasIpRange helpers into utils
To reflect the fact they'll be used by multiple resources.
* Pass Config to build helpers, not meta
It's the only thing meta is used for.
* Refactor getNetwork util methods to return early for the happy path.
* Update compute APIs
compute.Instance.MinCpuPlatform is now GA.
* Fix panic in TestComputeInstanceMigrateState
This seemed to be a pre-existing issue, i.e. I could repro it in master.
--- FAIL: TestComputeInstanceMigrateState (0.00s)
panic: interface conversion: interface {} is nil, not *google.Config [recovered]
panic: interface conversion: interface {} is nil, not *google.Config
goroutine 85 [running]:
testing.tRunner.func1(0xc4205d60f0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:711 +0x2d2
panic(0x203acc0, 0xc4205d2080)
/usr/local/Cellar/go/1.9.1/libexec/src/runtime/panic.go:491 +0x283
github.com/terraform-providers/terraform-provider-google/google.migrateStateV3toV4(0xc4205f2000, 0x0, 0x0, 0x0, 0x48, 0xc4205f2000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:182 +0x2405
github.com/terraform-providers/terraform-provider-google/google.resourceComputeInstanceMigrateState(0x2, 0xc4205f2000, 0x0, 0x0, 0x0, 0x0, 0xe0000000000)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate.go:48 +0x21a
github.com/terraform-providers/terraform-provider-google/google.runInstanceMigrateTest(0xc4205d60f0, 0x2260816, 0x8, 0x227d23a, 0x20, 0x2, 0xc4205ec0f0, 0xc4205ec120, 0x0,
0x0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:803 +0xc1
github.com/terraform-providers/terraform-provider-google/google.TestComputeInstanceMigrateState(0xc4205d60f0)
/Users/negz/control/go/src/github.com/terraform-providers/terraform-provider-google/google/resource_compute_instance_migrate_test.go:71 +0xc84
testing.tRunner(0xc4205d60f0, 0x22d81c0)
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
/usr/local/Cellar/go/1.9.1/libexec/src/testing/testing.go:789 +0x2de
FAIL github.com/terraform-providers/terraform-provider-google/google 0.035s
* Use only the v1 API for resource_compute_instance
Alias IP ranges, Accelerators, and min CPU platform are now GA.
* Move common instance code into utils.go
Methods used by both resource_compute_instance and
resource_compute_instance_template are currently spread between their respective
files, and utils.go.
This commit moves them all into utils.go for the sake of consistency. It may be
worth considering an instance_common.go file or similar.
* Unify compute_instance and compute_instance_template network_interface and service_account code
This has the side effect of enabling Alias IP range support for
compute_instance_templates.
* Add tests for compute instance template Alias IP ranges
* Mark instance template region as computed
We compute it from the subnet its network interfaces are in. Note this
is not new behaviour - I believe it was erroneously missing the computed
flag.
* Support guest accelerators for instance templates
Since most of the code is already there.
* Add a test for using 'address' rather than 'network_ip' for instance templates
* Don't mark assigned_nat_ip as deprecated
* Remove network_interface schema fields that don't make sense for a compute instance template
* Add newline after count in instance template docs
* Don't try to dedupe guest accelerator expansion code
The API calls to Google to create guest accelerators take different values
for instances and instance templates. Instance templates don't have a zone
and can thus *only* be passed a guest accelerator name.
* Use ParseNetworkFieldValue instead of getNetworkLink
* Add support for parsing regional fields, and subnetworks specifically
Currently unused because subnetworks may have a separate project from that
of the instance using them, which complicates looking up the project field.
* Fall back to provider region when parsing regional field values
Also slightly refactors getXFromSchema field helper functions for readability.
* Revert to assigned_nat_ip in compute instance docs
* Add beta scaffolding to compute instance and compute instance template
Note these resources don't currently use beta features - this is futureproofing.
* Fix indentation in comment about instance template alias IP ranges
* Consolidate metadata helper functions in metadata.go
* Move compute instance (and template) related helpers into their own file
2017-11-28 18:01:27 +00:00
|
|
|
func testAccCheckComputeInstanceHasMinCpuPlatform(instance *compute.Instance, minCpuPlatform string) resource.TestCheckFunc {
|
2017-08-30 21:25:31 +00:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instance.MinCpuPlatform != minCpuPlatform {
|
|
|
|
return fmt.Errorf("Wrong minimum CPU platform: expected %s, got %s", minCpuPlatform, instance.MinCpuPlatform)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 23:12:21 +00:00
|
|
|
func testAccCheckComputeInstanceHasAliasIpRange(instance *compute.Instance, subnetworkRangeName, iPCidrRange string) resource.TestCheckFunc {
|
2017-09-07 20:43:00 +00:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, networkInterface := range instance.NetworkInterfaces {
|
|
|
|
for _, aliasIpRange := range networkInterface.AliasIpRanges {
|
|
|
|
if aliasIpRange.SubnetworkRangeName == subnetworkRangeName && (aliasIpRange.IpCidrRange == iPCidrRange || ipCidrRangeDiffSuppress("ip_cidr_range", aliasIpRange.IpCidrRange, iPCidrRange, nil)) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Alias ip range with name %s and cidr %s not present", subnetworkRangeName, iPCidrRange)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 20:33:58 +00:00
|
|
|
func testAccCheckComputeInstanceHasAssignedIP(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_compute_instance" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ip := rs.Primary.Attributes["network_interface.0.access_config.0.assigned_nat_ip"]
|
|
|
|
if ip == "" {
|
|
|
|
return fmt.Errorf("No assigned NatIP for instance %s", rs.Primary.Attributes["name"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeInstance_basic(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2015-02-06 08:21:22 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-02-06 08:21:22 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
baz = "qux"
|
|
|
|
}
|
2015-07-02 01:24:34 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
create_timeout = 5
|
2016-11-13 02:01:32 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata_startup_script = "echo Hello"
|
2017-06-19 22:00:34 +00:00
|
|
|
|
|
|
|
labels {
|
|
|
|
my_key = "my_value"
|
|
|
|
my_other_key = "my_other_value"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
`, instance)
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-02-06 08:21:22 +00:00
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeInstance_basic2(instance string) string {
|
2016-08-15 21:29:58 +00:00
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2016-08-15 21:29:58 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2016-08-15 21:29:58 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
2016-08-15 21:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_basic3(instance string) string {
|
2016-01-06 00:49:06 +00:00
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-cloud/debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2015-01-30 01:00:02 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-01-30 01:00:02 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-02-10 08:25:45 +00:00
|
|
|
|
2016-08-15 21:29:58 +00:00
|
|
|
func testAccComputeInstance_basic4(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-cloud/debian-8"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2016-08-15 21:29:58 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2016-08-15 21:29:58 +00:00
|
|
|
|
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
2016-08-15 21:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_basic5(instance string) string {
|
2016-01-06 00:49:06 +00:00
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2015-01-30 01:00:02 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-01-30 01:00:02 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-01-30 01:00:02 +00:00
|
|
|
|
2015-04-13 23:56:48 +00:00
|
|
|
// Update zone to ForceNew, and change metadata k/v entirely
|
|
|
|
// Generates diff mismatch
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeInstance_forceNewAndChangeMetadata(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-b"
|
|
|
|
tags = ["baz"]
|
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2015-04-13 23:56:48 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config { }
|
|
|
|
}
|
2015-04-13 23:56:48 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
qux = "true"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-04-13 23:56:48 +00:00
|
|
|
|
2015-02-06 08:21:22 +00:00
|
|
|
// Update metadata, tags, and network_interface
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeInstance_update(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
2017-06-19 22:00:34 +00:00
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["baz"]
|
2017-06-16 23:42:08 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2014-08-26 20:48:49 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config { }
|
|
|
|
}
|
2014-08-26 20:48:49 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
2017-06-19 22:00:34 +00:00
|
|
|
|
|
|
|
create_timeout = 5
|
|
|
|
|
|
|
|
metadata_startup_script = "echo Hello"
|
|
|
|
|
|
|
|
labels {
|
|
|
|
only_me = "nothing_else"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
`, instance)
|
2014-08-25 22:47:21 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeInstance_ip(ip, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_address" "foo" {
|
|
|
|
name = "%s"
|
|
|
|
}
|
2014-08-25 22:47:21 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
tags = ["foo", "bar"]
|
2016-01-06 00:49:06 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2014-08-25 22:47:21 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
nat_ip = "${google_compute_address.foo.address}"
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2014-09-02 13:52:49 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, ip, instance)
|
2014-11-20 13:30:02 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 20:33:58 +00:00
|
|
|
func testAccComputeInstance_generateIp(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
// generate ephemeral IP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
|
|
|
}
|
|
|
|
|
2017-09-07 14:04:26 +00:00
|
|
|
func testAccComputeInstance_disks_encryption(bootEncryptionKey string, diskNameToEncryptionKey map[string]*compute.CustomerEncryptionKey, instance string) string {
|
|
|
|
diskNames := []string{}
|
|
|
|
for k, _ := range diskNameToEncryptionKey {
|
|
|
|
diskNames = append(diskNames, k)
|
|
|
|
}
|
2017-01-18 13:49:48 +00:00
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
2017-09-07 14:04:26 +00:00
|
|
|
|
|
|
|
disk_encryption_key_raw = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_disk" "foobar2" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk_encryption_key_raw = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_disk" "foobar3" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
disk_encryption_key_raw = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_disk" "foobar4" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2017-01-18 13:49:48 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2017-01-18 13:49:48 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-09-07 14:04:26 +00:00
|
|
|
disk_encryption_key_raw = "%s"
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2017-01-18 13:49:48 +00:00
|
|
|
|
2017-09-29 00:22:29 +00:00
|
|
|
attached_disk {
|
2017-09-29 11:54:24 +00:00
|
|
|
source = "${google_compute_disk.foobar.self_link}"
|
2017-09-07 14:04:26 +00:00
|
|
|
disk_encryption_key_raw = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar2.self_link}"
|
|
|
|
disk_encryption_key_raw = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar4.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar3.self_link}"
|
|
|
|
disk_encryption_key_raw = "%s"
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2017-01-18 13:49:48 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2017-01-18 13:49:48 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
2017-09-07 14:04:26 +00:00
|
|
|
`, diskNames[0], diskNameToEncryptionKey[diskNames[0]].RawKey,
|
|
|
|
diskNames[1], diskNameToEncryptionKey[diskNames[1]].RawKey,
|
|
|
|
diskNames[2], diskNameToEncryptionKey[diskNames[2]].RawKey,
|
|
|
|
"instance-testd-"+acctest.RandString(10),
|
|
|
|
instance, bootEncryptionKey,
|
|
|
|
diskNameToEncryptionKey[diskNames[0]].RawKey, diskNameToEncryptionKey[diskNames[1]].RawKey, diskNameToEncryptionKey[diskNames[2]].RawKey)
|
2017-01-18 13:49:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 20:20:02 +00:00
|
|
|
func testAccComputeInstance_attachedDisk(disk, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
2017-04-25 20:20:02 +00:00
|
|
|
|
2017-10-23 20:26:59 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, disk, instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_attachedDisk_sourceUrl(disk, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2017-04-25 20:20:02 +00:00
|
|
|
|
2017-10-23 19:53:41 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar.self_link}"
|
|
|
|
}
|
2017-04-25 20:20:02 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2017-11-02 20:08:02 +00:00
|
|
|
}
|
|
|
|
`, disk, instance)
|
|
|
|
}
|
2017-04-25 20:20:02 +00:00
|
|
|
|
2017-11-02 20:08:02 +00:00
|
|
|
func testAccComputeInstance_addAttachedDisk(disk, disk2, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_disk" "foobar2" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar2.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, disk, disk2, instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_detachDisk(disk, disk2, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_disk" "foobar2" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, disk, disk2, instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_updateAttachedDiskEncryptionKey(disk, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
disk_encryption_key_raw = "c2Vjb25kNzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attached_disk {
|
|
|
|
source = "${google_compute_disk.foobar.name}"
|
|
|
|
disk_encryption_key_raw = "c2Vjb25kNzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`, disk, instance)
|
2017-04-25 20:20:02 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 22:36:00 +00:00
|
|
|
func testAccComputeInstance_bootDisk_source(disk, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
source = "${google_compute_disk.foobar.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, disk, instance)
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:26:59 +00:00
|
|
|
func testAccComputeInstance_bootDisk_sourceUrl(disk, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
source = "${google_compute_disk.foobar.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, disk, instance)
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:39:32 +00:00
|
|
|
func testAccComputeInstance_bootDisk_type(instance string, diskType string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
type = "%s"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance, diskType)
|
|
|
|
}
|
|
|
|
|
2017-06-28 22:43:58 +00:00
|
|
|
func testAccComputeInstance_scratchDisk(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "scratch" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scratch_disk {
|
|
|
|
interface = "NVME"
|
|
|
|
}
|
|
|
|
|
|
|
|
scratch_disk {
|
|
|
|
interface = "SCSI"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
`, instance)
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeInstance_service_account(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2015-05-01 01:21:21 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2016-01-06 00:49:06 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2015-10-26 20:16:06 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
service_account {
|
|
|
|
scopes = [
|
|
|
|
"userinfo-email",
|
|
|
|
"compute-ro",
|
|
|
|
"storage-ro",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-10-26 20:16:06 +00:00
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeInstance_scheduling(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2015-10-26 20:16:06 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2015-10-26 20:16:06 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2016-01-06 00:49:06 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
scheduling {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, instance)
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2016-02-17 11:09:46 +00:00
|
|
|
|
|
|
|
func testAccComputeInstance_subnet_auto(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
auto_create_subnetworks = true
|
|
|
|
}
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "${google_compute_network.inst-test-network.name}"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
`, acctest.RandString(10), instance)
|
2016-02-17 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_subnet_custom(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
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}"
|
|
|
|
}
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
2017-08-04 18:00:45 +00:00
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}"
|
2017-06-16 23:42:08 +00:00
|
|
|
access_config { }
|
|
|
|
}
|
2016-02-17 11:09:46 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
`, acctest.RandString(10), acctest.RandString(10), instance)
|
2016-02-17 11:09:46 +00:00
|
|
|
}
|
2016-08-08 01:01:31 +00:00
|
|
|
|
2017-12-11 22:07:52 +00:00
|
|
|
func testAccComputeInstance_subnet_xpn(org, billingId, projectName, instance string) string {
|
2016-10-27 15:25:58 +00:00
|
|
|
return fmt.Sprintf(`
|
2017-12-11 22:07:52 +00:00
|
|
|
|
|
|
|
resource "google_project" "host_project" {
|
|
|
|
name = "Test Project XPN Host"
|
|
|
|
project_id = "%s-host"
|
|
|
|
org_id = "%s"
|
|
|
|
billing_account = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_project_service" "host_project" {
|
|
|
|
project = "${google_project.host_project.project_id}"
|
|
|
|
service = "compute.googleapis.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_shared_vpc_host_project" "host_project" {
|
|
|
|
project = "${google_project_service.host_project.project}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_project" "service_project" {
|
|
|
|
name = "Test Project XPN Service"
|
|
|
|
project_id = "%s-service"
|
|
|
|
org_id = "%s"
|
|
|
|
billing_account = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_project_service" "service_project" {
|
|
|
|
project = "${google_project.service_project.project_id}"
|
|
|
|
service = "compute.googleapis.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_shared_vpc_service_project" "service_project" {
|
|
|
|
host_project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
|
|
|
service_project = "${google_project_service.service_project.project}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "inst-test-network-%s"
|
2017-12-11 22:07:52 +00:00
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
2016-10-27 15:25:58 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
2016-10-27 15:25:58 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
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}"
|
2017-12-11 22:07:52 +00:00
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2016-10-27 15:25:58 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2017-12-11 22:07:52 +00:00
|
|
|
project = "${google_compute_shared_vpc_service_project.service_project.service_project}"
|
2016-10-27 15:25:58 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
subnetwork_project = "${google_compute_subnetwork.inst-test-subnetwork.project}"
|
|
|
|
access_config { }
|
|
|
|
}
|
2016-10-27 15:25:58 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2017-12-11 22:07:52 +00:00
|
|
|
`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), instance)
|
2016-10-27 15:25:58 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 01:01:31 +00:00
|
|
|
func testAccComputeInstance_address_auto(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
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"
|
2016-08-08 01:01:31 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
access_config { }
|
|
|
|
}
|
2016-08-08 01:01:31 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
|
|
|
`, acctest.RandString(10), acctest.RandString(10), instance)
|
2016-08-08 01:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_address_custom(instance, address string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
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"
|
2016-08-08 01:01:31 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2016-08-08 01:01:31 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
address = "%s"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
`, acctest.RandString(10), acctest.RandString(10), instance, address)
|
2016-08-08 01:01:31 +00:00
|
|
|
}
|
2016-11-01 21:00:12 +00:00
|
|
|
|
|
|
|
func testAccComputeInstance_private_image_family(disk, image, family, instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_disk" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
2016-11-01 21:00:12 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_image" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
source_disk = "${google_compute_disk.foobar.self_link}"
|
|
|
|
family = "%s"
|
|
|
|
}
|
2016-11-01 21:00:12 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
2016-11-01 21:00:12 +00:00
|
|
|
|
2017-07-14 17:57:23 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "${google_compute_image.foobar.family}"
|
|
|
|
}
|
2017-06-16 23:42:08 +00:00
|
|
|
}
|
2016-11-01 21:00:12 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
2016-11-01 21:00:12 +00:00
|
|
|
|
2017-06-16 23:42:08 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, disk, image, family, instance)
|
2016-11-01 21:00:12 +00:00
|
|
|
}
|
2016-11-08 00:00:42 +00:00
|
|
|
|
2017-08-04 21:18:07 +00:00
|
|
|
func testAccComputeInstance_multiNic(instance, network, subnetwork string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params{
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
|
|
|
access_config { }
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_network" "inst-test-network" {
|
|
|
|
name = "%s"
|
|
|
|
}
|
|
|
|
resource "google_compute_subnetwork" "inst-test-subnetwork" {
|
|
|
|
name = "%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.inst-test-network.self_link}"
|
|
|
|
}
|
|
|
|
`, instance, network, subnetwork)
|
|
|
|
}
|
2017-08-22 19:49:43 +00:00
|
|
|
|
|
|
|
func testAccComputeInstance_guestAccelerator(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-east1-d"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
# Instances with guest accelerators do not support live migration.
|
|
|
|
on_host_maintenance = "TERMINATE"
|
|
|
|
}
|
|
|
|
|
|
|
|
guest_accelerator {
|
|
|
|
count = 1
|
|
|
|
type = "nvidia-tesla-k80"
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
2017-08-30 21:25:31 +00:00
|
|
|
|
|
|
|
func testAccComputeInstance_minCpuPlatform(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-east1-d"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
min_cpu_platform = "Intel Haswell"
|
|
|
|
}`, instance)
|
|
|
|
}
|
2017-09-07 20:43:00 +00:00
|
|
|
|
|
|
|
func testAccComputeInstance_primaryAliasIpRange(instance string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-east1-d"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
|
|
|
|
alias_ip_range {
|
|
|
|
ip_cidr_range = "/24"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstance_secondaryAliasIpRange(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-east1"
|
|
|
|
network = "${google_compute_network.inst-test-network.self_link}"
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "inst-test-secondary"
|
|
|
|
ip_cidr_range = "172.16.0.0/20"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resource "google_compute_instance" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-east1-d"
|
|
|
|
|
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}"
|
|
|
|
|
|
|
|
alias_ip_range {
|
|
|
|
subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}"
|
|
|
|
ip_cidr_range = "172.16.0.0/24"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), instance)
|
|
|
|
}
|