Commit Graph

89 Commits

Author SHA1 Message Date
Dana Hoffman
50afa7b199
compute instance helpers / metadata cleanup (#797)
* get rid of getSubnetworkLink and getProjectAndRegionFromSubnetworkLink

* dedupe metadata flatteners

* update flattenMetadata comment
2017-11-29 09:47:42 -08:00
Nic Cope
94a405d179 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 10:01:27 -08:00
Vincent Roseberry
6c5d6b72e0
Store project and region in state (#784)
* Store project and region in state

* Delete unused project in runtimeconfig_variable
2017-11-27 16:32:20 -08:00
Dana Hoffman
f68765f5cd
Fix bug with empty initialize_params block (#664)
* fix initialize params bug

* make sure all init params are deleted, not just #
2017-11-03 15:25:54 -07:00
Dana Hoffman
51ed0b74dd
Allow attaching and detaching disks from instances (#636)
* allow updating attached disks

* check for scratch and update comment
2017-11-02 13:08:02 -07:00
Dana Hoffman
c577ad6e8d Allow setting boot and attached disk sources by name or self link (#605)
* disk cleanup

* fix attached disk test

* allow disk sources from name or url

* parse disk source better on read

* update docs

* fix boot disk source url
2017-10-23 13:26:59 -07:00
Dana Hoffman
be0525885e post-migration disk cleanup (#600)
* disk cleanup

* fix attached disk test
2017-10-23 12:53:41 -07:00
Joe Selman
2765290724 Add label support to google_compute_snapshot (#570)
* Add label support to google_compute_snapshot
* Refactor operation polling code to use client directly
2017-10-13 15:36:03 -07:00
Peter Milley
fe01f7fdd6 Copy network_interface attributes to Terraform state. (#536) 2017-10-11 13:33:58 -07:00
Vincent Roseberry
3d4c517ce8 Fix crash because missing error check before waiting on operation (#556) 2017-10-09 14:12:05 -07:00
Vincent Roseberry
87f3a58cb2 Add support for org policies at the organization level (#523)
* Fetch latest resource manager client
* Add new resource to manage Org Policy at the organization level.
* Update documentation
2017-10-05 13:20:16 -07:00
Paddy
300bae3244 Fix compute_instance migration bug.
`compute_instance`'s StateVersion was set to 2. Then we released a
migration to v3, but never updated the StateVersion to 3, meaning the
migration was never run. When we added the migration for disks, we
bumped to 4, bypassing 3 altogher. In theory, this is fine, and is
expected; after all, some people may have state in version 0 and need to
upgrade all the way to 4, so our schema migration function is supposed
to support this.

Unfortunately, for migrations to v2, v3, and v4 of our schema, the
migration _returned_ after each migration, instead of falling through.
This meant that (in this case), version 2 would see it needs to be
version 4, run the state migration to version 3, then _return_, setting
its StateVersion to _4_, which means the migration from 3->4 got skipped
entirely.

This PR bumps the version to 5, and adds a migration from 4->5 such that
if there are still disks in state after 4, re-run 4. This will fix
things for people that upgraded to 1.0.0 and had their StateVersion
updated without the migration running.

I also updated the tests @danawillow wrote to start from state version 2
instead of state version 3, as the state would never be in version 3.

I also duplicated those tests, but started them from state version 4
(assuming the migration hadn't run) and verifying that the migration
from 4->5 would correct that.
2017-10-02 12:34:09 -07:00
Paddy
e4d920b774 Remove disks field. 2017-09-28 17:22:29 -07:00
Paddy
edad00bf4b Replace variable we actually needed. 2017-09-28 15:44:21 -07:00
Paddy
a76fa3bd6a Merge branch 'master' into paddy_1.0_deprecations 2017-09-28 15:37:19 -07:00
Paddy
f2f276ea0b Remove deprecated resources for 1.0.0.
In advance of 1.0.0, let's take the opportunity to remove the fields on
resources that have been deprecated for a while.
2017-09-28 14:38:38 -07:00
Dana Hoffman
6d947cd20e Add state migration from disk to boot_disk/scratch_disk/attached_disk (#329)
* Add state migration from disk to boot_disk/scratch_disk/attached_disk

* get rid of test for now

* update schema version

* add tests for migration

* fix travis errors

* actually fix travis errors

* fix logic when project is set, also remove some log statements

* add tests for reading based on encryption key and image

* use as much of the image URL as we can for matching on image

* read project from config if it wasn't set in the attribute

* update resolveImage call
2017-09-28 14:37:03 -07:00
Vincent Roseberry
b5e1bf4a82 Remove alias ip range from beta feature for compute instance 2017-09-28 10:48:28 -07:00
Dana Hoffman
cc8ea81117 Fix a few instances where we read the project from the provider config and not using the helper function (#469) 2017-09-26 17:01:52 -07:00
Joe Selman
41248230ef Expose instance_id as a computed field on compute_instance (#427) 2017-09-13 16:18:08 -07:00
Vincent Roseberry
7ceea51dfd Add support for alias_ip_range in google_compute_instance network interface (#375) 2017-09-07 13:43:00 -07:00
Dana Hoffman
333c2f09db Fix bug with CSEK where the key stored in state might be associated with the wrong disk (#327)
* Fix bug with CSEK where the key stored in state might be associated with the wrong disk

* preserve original order of attached disks

* use the disk index to figure out the raw key
2017-09-07 22:04:26 +08:00
Vincent Roseberry
c2399f76fb Add support for min_cpu_platform in google_compute_instance. (#349) 2017-08-30 17:25:31 -04:00
Vincent Roseberry
7a216c40b5 Add support for guest_accelerators (GPU) to google_compute_instance (#330) 2017-08-22 15:49:43 -04:00
Joe Selman
227ea5660f Add support for setting labels to compute_image (#339) 2017-08-18 13:34:11 -07:00
Riley Karson
9e76fab11b Convert old validation functions to use IntAtLeast from helper/validation. (#312)
* Convert old validation functions to use IntAtLeast in helper/validation.

* make fmt

* Remove unused import.
2017-08-10 13:01:45 -07:00
Joe Selman
f9d0570168 Fix scheduling automatic restart, remove deprecated options (#248)
* Fix bug where scheduling.automatic_restart false is never used

* Remove deprecated automatic_restart value in favor of scheduling.automatic_restart

* Remove deprecated on_host_maintenance

* Correct bad var name

* Re-add removed schema values and marked as Removed

* Fix var to snake case

* Migrate empty scheduling blocks in compute_instance_template

* Shorten error message

* Use only one return value instead of two
2017-08-09 12:25:16 -07:00
Vincent Roseberry
1480539c82 Remove ConflictsWith for network and subnetwork. More than one interface is supported and ConflictsWith doesn't support List properly (#294) 2017-08-04 14:22:04 -07:00
Vincent Roseberry
3fde8cf24e google_compute_instance can specified the subnetwork using a self_link (#290) 2017-08-04 11:00:45 -07:00
Vincent Roseberry
ec21efb665 google_compute_instance reads scheduling fields from GCP. (#237) 2017-08-03 13:51:45 -07:00
Matt Morrison
0595ef25a5 Fix disk type’Malformed URL’ error (#275)
* Fix disk type’Malformed URL’ error

The API expects the disk type to be a SelfLink URL, but the disk type 
name was being used (e.g. “pd-ssd”).

* Add ACC Tests for boot disk type

* Fix acceptance test & fmt test config

The Instance data does not contain the actual disk type, just "PERSISTENT". This commit uses the computeClient to pull the disk data from the API, allowing checking of the disk type.

Also fmt'd the test configuration.
2017-08-01 15:39:32 -07:00
Joe Selman
28f8931f0b Fix bug where startup-script metadata did not refresh (#180)
* Fix bug where startup-script metadata did not refresh

* Remove MetadataFormatSchema and replace with explicit filters/transforms
2017-08-01 10:47:58 -07:00
Riley Karson
50069050c1 Removed the Compute Operation Wait Zone and migrated to universal wait. (#251)
* Removed the Compute Operation Wait Zone and migrated to universal wait.

* Removed unused var.
2017-07-27 08:48:25 -07:00
Dana Hoffman
2367357869 Update compute instance docs/tests to use new boot and scratch disk attributes (#189)
* update compute instance docs to use new boot and scratch disk attributes, document attached_disk

* Update compute instance tests to mostly use new boot and scratch disk attributes

* Fix encryption test by setting values in state from what was there before
2017-07-14 10:57:23 -07:00
Dana Hoffman
32bf0df2d0 Add scratch_disk property to google_compute_instance and deprecate disk (#123)
* Add scratch_disk property to google_compute_instance

* docs for scratch_disk

* limit scope of scratchDisks array by using bool, test formatting

* add slash back to disk check
2017-06-28 15:43:58 -07:00
Dana Hoffman
549e1314f9 Add boot_disk property to google_compute_instance (#122)
* Add boot_disk property to google_compute_instance

* docs for boot_disk

* limit scope of bootDisk, use bool instead

* test formatting

* make device_name forcenew, add sha256 encryption key
2017-06-28 15:36:00 -07:00
Joe Selman
e3c27065dc Add support for using labels on compute_instance 2017-06-26 10:37:16 -07:00
Joe Selman
5583b6d932 Update compute api client and AutomaticRestart usage
Instance.AutomaticRestart changed from a bool to a *bool to distinguish between
an empty value vs an explicitly set value. See
https://github.com/google/google-api-go-client/issues/196 for more context.
2017-06-19 20:48:21 -07:00
Jake Champlin
66029ac431
Transfer google provider 2017-06-06 11:58:51 -04:00