2015-02-10 10:29:49 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-04-19 00:28:46 +00:00
|
|
|
"strings"
|
2015-02-10 10:29:49 +00:00
|
|
|
"testing"
|
2017-12-11 22:07:52 +00:00
|
|
|
"time"
|
2015-02-10 10:29:49 +00:00
|
|
|
|
2016-01-05 21:47:10 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-02-10 10:29:49 +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"
|
2015-02-10 10:29:49 +00:00
|
|
|
)
|
|
|
|
|
2017-12-01 20:03:19 +00:00
|
|
|
const DEFAULT_MIN_CPU_TEST_VALUE = "Intel Haswell"
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
func TestAccComputeInstanceTemplate_basic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_basic(),
|
2015-02-10 10:29:49 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateTag(&instanceTemplate, "foo"),
|
|
|
|
testAccCheckComputeInstanceTemplateMetadata(&instanceTemplate, "foo", "bar"),
|
2017-04-26 20:24:40 +00:00
|
|
|
testAccCheckComputeInstanceTemplateDisk(&instanceTemplate, "projects/debian-cloud/global/images/debian-8-jessie-v20160803", true, true),
|
2017-10-09 17:17:15 +00:00
|
|
|
testAccCheckComputeInstanceTemplateContainsLabel(&instanceTemplate, "my_label", "foobar"),
|
2015-02-10 10:29:49 +00:00
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2015-02-10 10:29:49 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-09 19:25:16 +00:00
|
|
|
func TestAccComputeInstanceTemplate_preemptible(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-09 19:25:16 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_preemptible(),
|
2017-08-09 19:25:16 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateAutomaticRestart(&instanceTemplate, false),
|
|
|
|
testAccCheckComputeInstanceTemplatePreemptible(&instanceTemplate, true),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-08-09 19:25:16 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
func TestAccComputeInstanceTemplate_IP(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_ip(),
|
2015-02-10 10:29:49 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateNetwork(&instanceTemplate),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2015-02-10 10:29:49 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-06-05 19:35:44 +00:00
|
|
|
func TestAccComputeInstanceTemplate_networkTier(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_networkTier(),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-02 00:16:05 +00:00
|
|
|
func TestAccComputeInstanceTemplate_networkIP(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-05-02 00:16:05 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
networkIP := "10.128.0.2"
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_networkIP(networkIP),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateNetwork(&instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateNetworkIP(
|
|
|
|
"google_compute_instance_template.foobar", networkIP, &instanceTemplate),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-05-02 00:16:05 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
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 TestAccComputeInstanceTemplate_address(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
address := "10.128.0.2"
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_address(address),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateNetwork(&instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateAddress(
|
|
|
|
"google_compute_instance_template.foobar", address, &instanceTemplate),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-05-02 00:16:05 +00:00
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
func TestAccComputeInstanceTemplate_disks(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_disks(),
|
2015-02-10 10:29:49 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
2017-04-26 20:24:40 +00:00
|
|
|
testAccCheckComputeInstanceTemplateDisk(&instanceTemplate, "projects/debian-cloud/global/images/debian-8-jessie-v20160803", true, true),
|
2015-03-18 17:42:03 +00:00
|
|
|
testAccCheckComputeInstanceTemplateDisk(&instanceTemplate, "terraform-test-foobar", false, false),
|
2015-02-10 10:29:49 +00:00
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2015-02-10 10:29:49 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
func TestAccComputeInstanceTemplate_subnet_auto(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
network := "network-" + acctest.RandString(10)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_subnet_auto(network),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateNetworkName(&instanceTemplate, network),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2016-02-17 11:09:46 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeInstanceTemplate_subnet_custom(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_subnet_custom(),
|
2016-02-17 11:09:46 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateSubnetwork(&instanceTemplate),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2016-02-17 11:09:46 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:05:13 +00:00
|
|
|
func TestAccComputeInstanceTemplate_subnet_xpn(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-01-12 14:05:13 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
2017-12-11 22:07:52 +00:00
|
|
|
org := getTestOrgFromEnv(t)
|
|
|
|
billingId := getTestBillingAccountFromEnv(t)
|
|
|
|
projectName := fmt.Sprintf("tf-xpntest-%d", time.Now().Unix())
|
2017-01-12 14:05:13 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-12-11 22:07:52 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_subnet_xpn(org, billingId, projectName),
|
2017-01-12 14:05:13 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-12-11 22:07:52 +00:00
|
|
|
testAccCheckComputeInstanceTemplateExistsInProject(
|
|
|
|
"google_compute_instance_template.foobar", fmt.Sprintf("%s-service", projectName),
|
|
|
|
&instanceTemplate),
|
2017-01-12 14:05:13 +00:00
|
|
|
testAccCheckComputeInstanceTemplateSubnetwork(&instanceTemplate),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:40:55 +00:00
|
|
|
func TestAccComputeInstanceTemplate_metadata_startup_script(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-12-02 21:40:55 +00:00
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_startup_script(),
|
2016-12-02 21:40:55 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists(
|
|
|
|
"google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateStartupScript(&instanceTemplate, "echo 'Hello'"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
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 TestAccComputeInstanceTemplate_primaryAliasIpRange(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_primaryAliasIpRange(acctest.RandString(10)),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists("google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateHasAliasIpRange(&instanceTemplate, "", "/24"),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
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 TestAccComputeInstanceTemplate_secondaryAliasIpRange(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_secondaryAliasIpRange(acctest.RandString(10)),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists("google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateHasAliasIpRange(&instanceTemplate, "inst-test-secondary", "/24"),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
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 TestAccComputeInstanceTemplate_guestAccelerator(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2018-01-23 19:51:36 +00:00
|
|
|
Config: testAccComputeInstanceTemplate_guestAccelerator(acctest.RandString(10), 1),
|
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
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists("google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateHasGuestAccelerator(&instanceTemplate, "nvidia-tesla-k80", 1),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
2016-12-02 21:40:55 +00:00
|
|
|
|
2018-01-23 19:51:36 +00:00
|
|
|
func TestAccComputeInstanceTemplate_guestAcceleratorSkip(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_guestAccelerator(acctest.RandString(10), 0),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists("google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateLacksGuestAccelerator(&instanceTemplate),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-01 20:03:19 +00:00
|
|
|
func TestAccComputeInstanceTemplate_minCpuPlatform(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var instanceTemplate compute.InstanceTemplate
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeInstanceTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeInstanceTemplate_minCpuPlatform(acctest.RandString(10)),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeInstanceTemplateExists("google_compute_instance_template.foobar", &instanceTemplate),
|
|
|
|
testAccCheckComputeInstanceTemplateHasMinCpuPlatform(&instanceTemplate, DEFAULT_MIN_CPU_TEST_VALUE),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_instance_template.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-12-01 20:03:19 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateDestroy(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_compute_instance_template" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := config.clientCompute.InstanceTemplates.Get(
|
|
|
|
config.Project, rs.Primary.ID).Do()
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Instance template still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceTemplateExists(n string, instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
2017-12-11 22:07:52 +00:00
|
|
|
return testAccCheckComputeInstanceTemplateExistsInProject(n, getTestProjectFromEnv(), instanceTemplate)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceTemplateExistsInProject(n, p string, instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
2015-02-10 10:29:49 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
found, err := config.clientCompute.InstanceTemplates.Get(
|
2017-12-11 22:07:52 +00:00
|
|
|
p, rs.Primary.ID).Do()
|
2015-02-10 10:29:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if found.Name != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("Instance template not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*instanceTemplate = *found
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceTemplateMetadata(
|
|
|
|
instanceTemplate *compute.InstanceTemplate,
|
|
|
|
k string, v string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instanceTemplate.Properties.Metadata == nil {
|
|
|
|
return fmt.Errorf("no metadata")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range instanceTemplate.Properties.Metadata.Items {
|
|
|
|
if k != item.Key {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:06:25 +00:00
|
|
|
if item.Value != nil && v == *item.Value {
|
2015-02-10 10:29:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:06:25 +00:00
|
|
|
return fmt.Errorf("bad value for %s: %s", k, *item.Value)
|
2015-02-10 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("metadata not found: %s", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceTemplateNetwork(instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instanceTemplate.Properties.NetworkInterfaces {
|
|
|
|
for _, c := range i.AccessConfigs {
|
|
|
|
if c.NatIP == "" {
|
|
|
|
return fmt.Errorf("no NAT IP")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateNetworkName(instanceTemplate *compute.InstanceTemplate, network string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instanceTemplate.Properties.NetworkInterfaces {
|
|
|
|
if !strings.Contains(i.Network, network) {
|
|
|
|
return fmt.Errorf("Network doesn't match expected value, Expected: %s Actual: %s", network, i.Network[strings.LastIndex("/", i.Network)+1:])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateDisk(instanceTemplate *compute.InstanceTemplate, source string, delete bool, boot bool) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instanceTemplate.Properties.Disks == nil {
|
|
|
|
return fmt.Errorf("no disks")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, disk := range instanceTemplate.Properties.Disks {
|
|
|
|
if disk.InitializeParams == nil {
|
|
|
|
// Check disk source
|
|
|
|
if disk.Source == source {
|
|
|
|
if disk.AutoDelete == delete && disk.Boot == boot {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check source image
|
|
|
|
if disk.InitializeParams.SourceImage == source {
|
|
|
|
if disk.AutoDelete == delete && disk.Boot == boot {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Disk not found: %s", source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 11:09:46 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateSubnetwork(instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, i := range instanceTemplate.Properties.NetworkInterfaces {
|
|
|
|
if i.Subnetwork == "" {
|
|
|
|
return fmt.Errorf("no subnet")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateTag(instanceTemplate *compute.InstanceTemplate, n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instanceTemplate.Properties.Tags == nil {
|
|
|
|
return fmt.Errorf("no tags")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, k := range instanceTemplate.Properties.Tags.Items {
|
|
|
|
if k == n {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("tag not found: %s", n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 19:25:16 +00:00
|
|
|
func testAccCheckComputeInstanceTemplatePreemptible(instanceTemplate *compute.InstanceTemplate, preemptible bool) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instanceTemplate.Properties.Scheduling.Preemptible != preemptible {
|
|
|
|
return fmt.Errorf("Expected preemptible value %v, got %v", preemptible, instanceTemplate.Properties.Scheduling.Preemptible)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceTemplateAutomaticRestart(instanceTemplate *compute.InstanceTemplate, automaticRestart bool) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
ar := instanceTemplate.Properties.Scheduling.AutomaticRestart
|
|
|
|
if ar == nil {
|
|
|
|
return fmt.Errorf("Expected to see a value for AutomaticRestart, but got nil")
|
|
|
|
}
|
|
|
|
if *ar != automaticRestart {
|
|
|
|
return fmt.Errorf("Expected automatic restart value %v, got %v", automaticRestart, ar)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:40:55 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateStartupScript(instanceTemplate *compute.InstanceTemplate, n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instanceTemplate.Properties.Metadata == nil && n == "" {
|
|
|
|
return nil
|
|
|
|
} else if instanceTemplate.Properties.Metadata == nil && n != "" {
|
|
|
|
return fmt.Errorf("Expected metadata.startup-script to be '%s', metadata wasn't set at all", n)
|
|
|
|
}
|
|
|
|
for _, item := range instanceTemplate.Properties.Metadata.Items {
|
|
|
|
if item.Key != "startup-script" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if item.Value != nil && *item.Value == n {
|
|
|
|
return nil
|
|
|
|
} else if item.Value == nil && n == "" {
|
|
|
|
return nil
|
|
|
|
} else if item.Value == nil && n != "" {
|
|
|
|
return fmt.Errorf("Expected metadata.startup-script to be '%s', wasn't set", n)
|
|
|
|
} else if *item.Value != n {
|
|
|
|
return fmt.Errorf("Expected metadata.startup-script to be '%s', got '%s'", n, *item.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Errorf("This should never be reached.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-02 00:16:05 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateNetworkIP(n, networkIP string, instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
ip := instanceTemplate.Properties.NetworkInterfaces[0].NetworkIP
|
|
|
|
err := resource.TestCheckResourceAttr(n, "network_interface.0.network_ip", ip)(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return resource.TestCheckResourceAttr(n, "network_interface.0.network_ip", networkIP)(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 testAccCheckComputeInstanceTemplateAddress(n, address string, instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
ip := instanceTemplate.Properties.NetworkInterfaces[0].NetworkIP
|
|
|
|
err := resource.TestCheckResourceAttr(n, "network_interface.0.network_ip", ip)(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return resource.TestCheckResourceAttr(n, "network_interface.0.network_ip", address)(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-09 17:17:15 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateContainsLabel(instanceTemplate *compute.InstanceTemplate, key string, value string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
v, ok := instanceTemplate.Properties.Labels[key]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Expected label with key '%s' not found", key)
|
|
|
|
}
|
|
|
|
if v != value {
|
|
|
|
return fmt.Errorf("Incorrect label value for key '%s': expected '%s' but found '%s'", key, value, v)
|
|
|
|
}
|
|
|
|
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 testAccCheckComputeInstanceTemplateHasAliasIpRange(instanceTemplate *compute.InstanceTemplate, subnetworkRangeName, iPCidrRange string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, networkInterface := range instanceTemplate.Properties.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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeInstanceTemplateHasGuestAccelerator(instanceTemplate *compute.InstanceTemplate, acceleratorType string, acceleratorCount int64) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if len(instanceTemplate.Properties.GuestAccelerators) != 1 {
|
|
|
|
return fmt.Errorf("Expected only one guest accelerator")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasSuffix(instanceTemplate.Properties.GuestAccelerators[0].AcceleratorType, acceleratorType) {
|
|
|
|
return fmt.Errorf("Wrong accelerator type: expected %v, got %v", acceleratorType, instanceTemplate.Properties.GuestAccelerators[0].AcceleratorType)
|
|
|
|
}
|
|
|
|
|
|
|
|
if instanceTemplate.Properties.GuestAccelerators[0].AcceleratorCount != acceleratorCount {
|
|
|
|
return fmt.Errorf("Wrong accelerator acceleratorCount: expected %d, got %d", acceleratorCount, instanceTemplate.Properties.GuestAccelerators[0].AcceleratorCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 19:51:36 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateLacksGuestAccelerator(instanceTemplate *compute.InstanceTemplate) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if len(instanceTemplate.Properties.GuestAccelerators) > 0 {
|
|
|
|
return fmt.Errorf("Expected no guest accelerators")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 20:03:19 +00:00
|
|
|
func testAccCheckComputeInstanceTemplateHasMinCpuPlatform(instanceTemplate *compute.InstanceTemplate, minCpuPlatform string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if instanceTemplate.Properties.MinCpuPlatform != minCpuPlatform {
|
|
|
|
return fmt.Errorf("Wrong minimum CPU platform: expected %s, got %s", minCpuPlatform, instanceTemplate.Properties.MinCpuPlatform)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccComputeInstanceTemplate_basic() string {
|
|
|
|
return fmt.Sprintf(`
|
2015-02-10 10:29:49 +00:00
|
|
|
resource "google_compute_instance_template" "foobar" {
|
2016-01-05 21:47:10 +00:00
|
|
|
name = "instancet-test-%s"
|
2015-02-10 10:29:49 +00:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2016-08-19 02:31:45 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
2015-02-10 10:29:49 +00:00
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
2015-02-16 17:04:56 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
2015-02-10 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-28 15:33:49 +00:00
|
|
|
scheduling {
|
|
|
|
preemptible = false
|
|
|
|
automatic_restart = true
|
|
|
|
}
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
2017-10-09 17:17:15 +00:00
|
|
|
|
|
|
|
labels {
|
|
|
|
my_label = "foobar"
|
|
|
|
}
|
2016-01-05 21:47:10 +00:00
|
|
|
}`, acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2015-02-10 10:29:49 +00:00
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccComputeInstanceTemplate_preemptible() string {
|
|
|
|
return fmt.Sprintf(`
|
2017-08-09 19:25:16 +00:00
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instancet-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
can_ip_forward = false
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2017-08-09 19:25:16 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
preemptible = true
|
|
|
|
automatic_restart = false
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2017-08-09 19:25:16 +00:00
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccComputeInstanceTemplate_ip() string {
|
|
|
|
return fmt.Sprintf(`
|
2015-02-10 10:29:49 +00:00
|
|
|
resource "google_compute_address" "foo" {
|
2016-01-05 21:47:10 +00:00
|
|
|
name = "instancet-test-%s"
|
2015-02-10 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
2016-01-05 21:47:10 +00:00
|
|
|
name = "instancet-test-%s"
|
2015-02-10 10:29:49 +00:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2016-08-19 02:31:45 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
2015-02-10 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 17:04:56 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
nat_ip = "${google_compute_address.foo.address}"
|
|
|
|
}
|
2015-02-10 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-01-05 21:47:10 +00:00
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2015-02-10 10:29:49 +00:00
|
|
|
|
2018-06-05 19:35:44 +00:00
|
|
|
func testAccComputeInstanceTemplate_networkTier() string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instancet-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
network_tier = "STANDARD"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
2017-05-02 00:16:05 +00:00
|
|
|
func testAccComputeInstanceTemplate_networkIP(networkIP string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instancet-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2017-05-02 00:16:05 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
network_ip = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), networkIP)
|
|
|
|
}
|
|
|
|
|
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 testAccComputeInstanceTemplate_address(address string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instancet-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
address = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), address)
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccComputeInstanceTemplate_disks() string {
|
|
|
|
return fmt.Sprintf(`
|
2015-03-18 17:42:03 +00:00
|
|
|
resource "google_compute_disk" "foobar" {
|
2016-01-05 21:47:10 +00:00
|
|
|
name = "instancet-test-%s"
|
2016-08-19 02:31:45 +00:00
|
|
|
image = "debian-8-jessie-v20160803"
|
2015-03-18 17:42:03 +00:00
|
|
|
size = 10
|
|
|
|
type = "pd-ssd"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
2015-02-10 10:29:49 +00:00
|
|
|
resource "google_compute_instance_template" "foobar" {
|
2016-01-05 21:47:10 +00:00
|
|
|
name = "instancet-test-%s"
|
2015-02-10 10:29:49 +00:00
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2016-08-19 02:31:45 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
2015-02-10 10:29:49 +00:00
|
|
|
auto_delete = true
|
2015-08-19 06:57:04 +00:00
|
|
|
disk_size_gb = 100
|
2015-02-10 10:29:49 +00:00
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2015-03-18 17:42:03 +00:00
|
|
|
source = "terraform-test-foobar"
|
2015-02-10 10:29:49 +00:00
|
|
|
auto_delete = false
|
|
|
|
boot = false
|
|
|
|
}
|
|
|
|
|
2015-02-16 17:04:56 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
2015-02-10 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2016-01-05 21:47:10 +00:00
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2016-02-17 11:09:46 +00:00
|
|
|
|
|
|
|
func testAccComputeInstanceTemplate_subnet_auto(network string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "auto-network" {
|
|
|
|
name = "%s"
|
|
|
|
auto_create_subnetworks = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instance-tpl-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2016-08-19 02:31:45 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
2016-02-17 11:09:46 +00:00
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "${google_compute_network.auto-network.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, network, acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccComputeInstanceTemplate_subnet_custom() string {
|
|
|
|
return fmt.Sprintf(`
|
2016-02-17 11:09:46 +00:00
|
|
|
resource "google_compute_network" "network" {
|
|
|
|
name = "network-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "subnetwork" {
|
|
|
|
name = "subnetwork-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/24"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.network.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instance-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
region = "us-central1"
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2016-08-19 02:31:45 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
2016-02-17 11:09:46 +00:00
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.subnetwork.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2016-12-02 21:40:55 +00:00
|
|
|
|
2017-12-11 22:07:52 +00:00
|
|
|
func testAccComputeInstanceTemplate_subnet_xpn(org, billingId, projectName string) string {
|
2017-01-12 14:05:13 +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-01-12 14:05:13 +00:00
|
|
|
resource "google_compute_network" "network" {
|
|
|
|
name = "network-%s"
|
|
|
|
auto_create_subnetworks = false
|
2017-12-11 22:07:52 +00:00
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
2017-01-12 14:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "subnetwork" {
|
|
|
|
name = "subnetwork-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/24"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.network.self_link}"
|
2017-12-11 22:07:52 +00:00
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
2017-01-12 14:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instance-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
region = "us-central1"
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2017-01-12 14:05:13 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.subnetwork.name}"
|
|
|
|
subnetwork_project = "${google_compute_subnetwork.subnetwork.project}"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2017-12-11 22:07:52 +00:00
|
|
|
project = "${google_compute_shared_vpc_service_project.service_project.service_project}"
|
|
|
|
}`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
2017-01-12 14:05:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccComputeInstanceTemplate_startup_script() string {
|
|
|
|
return fmt.Sprintf(`
|
2016-12-02 21:40:55 +00:00
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instance-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
2017-10-01 02:42:15 +00:00
|
|
|
disk {
|
2016-12-02 21:40:55 +00:00
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface{
|
|
|
|
network = "default"
|
|
|
|
}
|
2017-01-12 14:05:13 +00:00
|
|
|
|
2016-12-02 21:40:55 +00:00
|
|
|
metadata_startup_script = "echo 'Hello'"
|
|
|
|
}`, acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
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 testAccComputeInstanceTemplate_primaryAliasIpRange(i string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instance-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface{
|
|
|
|
network = "default"
|
|
|
|
alias_ip_range {
|
|
|
|
ip_cidr_range = "/24"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeInstanceTemplate_secondaryAliasIpRange(i 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_template" "foobar" {
|
|
|
|
name = "instance-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}"
|
|
|
|
|
|
|
|
// Note that unlike compute instances, instance templates seem to be
|
|
|
|
// only able to specify the netmask here. Trying a full CIDR string
|
|
|
|
// results in:
|
|
|
|
// Invalid value for field 'resource.properties.networkInterfaces[0].aliasIpRanges[0].ipCidrRange':
|
|
|
|
// '172.16.0.0/24'. Alias IP CIDR range must be a valid netmask starting with '/' (e.g. '/24')
|
|
|
|
alias_ip_range {
|
|
|
|
subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}"
|
|
|
|
ip_cidr_range = "/24"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, i, i, i)
|
|
|
|
}
|
|
|
|
|
2018-01-23 19:51:36 +00:00
|
|
|
func testAccComputeInstanceTemplate_guestAccelerator(i string, count uint8) string {
|
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
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instance-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
# Instances with guest accelerators do not support live migration.
|
|
|
|
on_host_maintenance = "TERMINATE"
|
|
|
|
}
|
|
|
|
|
|
|
|
guest_accelerator {
|
2018-01-23 19:51:36 +00:00
|
|
|
count = %d
|
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
|
|
|
type = "nvidia-tesla-k80"
|
|
|
|
}
|
2018-01-23 19:51:36 +00:00
|
|
|
}`, i, count)
|
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
|
|
|
}
|
2017-12-01 20:03:19 +00:00
|
|
|
|
|
|
|
func testAccComputeInstanceTemplate_minCpuPlatform(i string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_instance_template" "foobar" {
|
|
|
|
name = "instance-test-%s"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
|
|
|
|
disk {
|
|
|
|
source_image = "debian-8-jessie-v20160803"
|
|
|
|
auto_delete = true
|
|
|
|
disk_size_gb = 10
|
|
|
|
boot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
# Instances with guest accelerators do not support live migration.
|
|
|
|
on_host_maintenance = "TERMINATE"
|
|
|
|
}
|
|
|
|
|
|
|
|
min_cpu_platform = "%s"
|
|
|
|
}`, i, DEFAULT_MIN_CPU_TEST_VALUE)
|
|
|
|
}
|