Commit Graph

45 Commits

Author SHA1 Message Date
The Magician
c605b0bc4b [Terraform]: Apply gofmt -s to all files managed by MM (#2676)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2018-12-20 17:22:22 -08:00
The Magician
77e87d0f9b Remove google_compute_instance*.address (#2595)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2018-12-20 17:22:22 -08:00
The Magician
4674cc73f5 Fix make fmt (#2404)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2018-12-20 17:22:22 -08:00
The Magician
eb19080de7 Deprecated network_interface.address in code in instance template. (#2394)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2018-12-20 17:22:22 -08:00
Chris Stephens
ae09a200c7 deprecate address as originally intended 2018-12-20 17:22:22 -08:00
Chris Stephens
9be729fb78 support KMS encryption for instance templates 2018-12-20 17:22:22 -08:00
Nathan McKinley
902675c324 Reverting 1.20 and 1.19 cherrypick branches. 2018-12-20 17:22:22 -08:00
Nathan McKinley
bbaf961dda make fmt 2018-12-12 17:23:35 -08:00
The Magician
09b344057c Deprecated network_interface.address in code in instance template. (#2394)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2018-12-12 17:23:35 -08:00
Chris Stephens
49d8d6f2f3 support KMS encryption for instance templates 2018-12-12 17:23:35 -08:00
Dana Hoffman
a0979fe66a don't try to parse the source image if there is none 2018-10-10 13:06:38 -07:00
Paddy
0e4c53e527
Merge pull request #2153 from terraform-providers/paddy_2067
Fix error in instance template read.
2018-10-02 16:47:15 -07:00
Paddy Carver
99ef0adf31 Variable rename. 2018-10-02 16:43:21 -07:00
Riley Karson
a4a453dc1b
Deprecate assigned_nat_ip in compute_instance family (#2155)
Part of #2143
2018-10-02 16:07:28 -07:00
Paddy Carver
ee4ec86bef Fix error in instance template read.
Flattening disks involves taking the relative link of each disk. This
only works if you start from a self_link, but we were starting from
anything that resolveImage returns, which includes several
not-self_links.

This PR adds a test that shows the failure, and then fixes it by
expanding the output back out to a self_link before getting the relative
link from it.
2018-10-02 14:45:19 -07:00
Paddy
c1d404ddc1
Merge pull request #1995 from terraform-providers/paddy_1916_diff_fix
Fix perma-diff on instance templates.
2018-10-02 14:13:15 -07:00
Paddy Carver
2fc8da91e7 Fix Dana's comments, expand images to self_links.
Fix Dana's comments, one of which exposed a bug: we weren't actually
fixing the diff. Because resolveImage can return multiple formats, and
only returns a self_link if a self_link is passed in, it was diffing
more often than not against a self_link supplied in the config. We just
had a bug in our CustomizeDiff function that concealed this.

I added the resolvedImageSelfLink helper function to turn the output
from resolveImage into a self_link, which fixes the problem. It also has
the knock-on effect of fixing #2067 at the same time, which is nice. I
decided to add another function instead of just modifying resolveImage
to always return a self_link because I don't want to deal with the
backwards compatibility problems of changing how we're storing a bunch
of things in state this close to 1.19.0. And honestly, we should
probably just be storing the self_link always, _anyways_.
2018-10-02 01:11:03 -07:00
Dana Hoffman
250cfa351c
fix instance template interaction with regional disks, make docs more clear about valid values (#2138) 2018-10-01 11:07:56 -07:00
Paddy Carver
5cf6a5d131 Fix perma-diff on instance templates.
When using instance templates, if you use one of our image shorthands at
the moment, you'll get a perma-diff. This is because the config gets
resolved to another format before it is set in state, and so we need to
set that other format in state.

Unfortunately, resolving images requires network access, so we have to
do this with CustomizeDiff. CustomizeDiff was having trouble (I think?
More on this below) on setting a field as not ForceNew once the field
was already set, so I moved the decision for whether a field was
ForceNew or not into CustomizeDiff. I also resolved the old and new
images, and if they were the same, cleared the diff.

Unfortunately, you can't actually clear a field on a sub-block right
now. You have to clear top-level fields only. So this will currently
throw an error. I opened hashicorp/terraform#18795 to fix that. Once
that's merged, and we vendor it here, this patch fixes the problem.

If hashicorp/terraform#18795 doesn't get merged, the next best
workaround is to keep track of _all_ the fields under `disk` with a diff
in our CustomizeDiff, check whether they've all changed or not, and if
they've all changed, clear the changes on `disk`, which I _think_ will
resolve the issue. That's just a massive pain, unfortunately.
2018-09-05 17:35:44 -07:00
Paddy Carver
b94881b423 Always set instance template source images on read.
Previously, we were only setting source images for the disks in instance
templates if they weren't set in the config. Instead, let's just always
set them. This fixes our test failures about self_links not matching
names. Also, relative links are safer than just image names, as
Terraform wouldn't notice if another project's image of the same name
got used instead of your project's.

Also fix the setting of tags and tag fingerprints to always set, even if
to the empty value, to fix the tests.
2018-08-21 18:32:25 -07:00
Paddy Carver
53cc357b4c Fix network_tier tests.
Make network_tier computed, so when it's not specified we don't get a
permadiff.

Always store v1 self_links, so we don't get a permadiff.
2018-06-05 17:49:33 -07:00
Dana Hoffman
2f5c77cd7f add support for network tiers (#1530)
* add support for network tiers

* Update resource_compute_forwarding_rule.go
2018-06-05 12:35:44 -07:00
Shinichi TAMURA
73fe8bcec8 mark google_compute_instance_template's nat_ip as ForceNew (#1444) 2018-05-09 13:18:08 -07:00
Dana Hoffman
8907321d60
Roll forward beta scaffolding PR (#1453)
* Revert "Merge pull request #1434 from terraform-providers/paddy_revert_beta"

This reverts commit 118cd71201, reversing
changes made to d59fcbbc59.

* add ConvertSelfLinkToV1 calls to places where beta links are stored
2018-05-09 11:24:40 -07:00
Paddy Carver
aa2626b490 Revert "remove switch statements between api versions for compute"
This reverts commit bf1b3a24e8c1cac832e74d9d0e145c7010a4c2f1.
2018-05-04 07:51:45 -07:00
Dana Hoffman
30409d315e
Remove switch statements between api versions for compute (#1422) 2018-05-03 12:24:21 -07:00
Dana Hoffman
bde72e7576
un-deprecate name_prefix for instance templates (#1328) 2018-04-12 16:08:31 -07:00
Dana Hoffman
7596164ad1
Deprecate name_prefix (#1035)
* deprecate name_prefix

* make name_prefix computed and add migration instructions
2018-04-02 10:28:59 -07:00
Jacob Straszynski
939ba6d365 skip guest accelerators if count is 0. (#866)
* skip guest accelerators if count is 0.

Instances in instance groups in google will fail to provision, despite
requesting 0 GPUs. This came up for me when trying to provision
a similar instance group in all available regions, but only asking for
GPU's in those that support them by parameterizing the `count` and
setting it to 0.

This might be a violation of some terraform principles. For example,
testing locally with this change `terraform` did not recognize that
indeed my infra needed to be re-deployed (from it's pov, I assume it
believes this because inputs hadn't changed). Additionally, there may be
valid reasons for creating an instance template with 0 gpu's that can be
tuned upwards.

* Add guest accelerator skip test for instances.

* do not leave empty pointers to guest accelerators.

* attempt to clear guest accelerator diff

* conditionally customize diff for guest accels
2018-01-23 11:51:36 -08:00
Vincent Roseberry
d0f5fec463
Standardize resource name extraction from self_link/uri (#939)
* Standardize resource name extraction from self_link/uri

* remove rebase artifact

* style improvement

* Fix merge issue
2018-01-17 10:45:28 -08:00
Vincent Roseberry
12baa8766b
Add support for min_cpu_platform to instance_template (#808)
* Add support for min_cpu_platform to instance_template

* Set value in initializer

* Extract test min cpu platform value in a const
2017-12-01 12:03:19 -08:00
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
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
Radek Simko
31dc9d3790 Merge pull request #566 from terraform-providers/b-inst-tpl-device-name-computed
r/compute_instance_template: Make disk.device_name computed
2017-10-10 20:37:26 +01:00
Radek Simko
8378b58bdf
r/compute_instance_template: Make disk.device_name computed 2017-10-10 19:43:59 +01:00
Joe Selman
e3ca8fbe59 Add labels to google_compute_instance_template (#515) 2017-10-09 10:17:15 -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
Vincent Roseberry
7a216c40b5 Add support for guest_accelerators (GPU) to google_compute_instance (#330) 2017-08-22 15:49:43 -04:00
Joe Selman
e0e9b3a4d7 Remove default value for removed value automatic_restart (#321)
Import tests for compute_instance_template fail without this change as
they expect a value of true for automatic_restart. As this value was
removed, we're no longer setting it (and therefore it looks like it has
a value of false, which is different from the default).
2017-08-11 10:46:30 -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
Riley Karson
1f8254f260 Migrate all occurrences of WaitGlobal/WaitGlobal time to universal wait. (#243) 2017-07-26 09:40:06 -07:00
Riley Karson
4cc6e9939a Add name validation function, standardise validation functions used (#164)
* Used standard validation functions where possible, added a GCP name validation function.

* Add tests for GCP name, factor out a ValidateRegexp function.

* make fmt
2017-07-07 12:48:29 -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