Commit Graph

44 Commits

Author SHA1 Message Date
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
Dana Hoffman
8b71cecad7
fix retries for wrapped errors (#1760)
Turns out this block of code:
 2ea2baaedd/google/resource_google_project_services.go (L246-L307)
wasn't actually retrying on quota failures (429s) because it was getting wrapped, so our retry helper saw it as as non-retryable. This fixes that.
2018-07-12 11:19:49 -07:00
Dana Hoffman
34a68289cd
retry node pool writes on failed precondition (#1660)
Hypothetically fixes #1643.

@thomasriley, are you able to patch this change into your provider to see if it fixed the problem? I haven't been able to get a working repo so I haven't verified the fix yet.
2018-06-22 16:21:35 -07:00
Jonathan Pentecost
f8a3335bf9 service_account_key: regression fix for v1.14 (#1664)
Commit 8f31fec introduced a bug for the 'service_account_key' resource
where it required a project be set either in the provider or in the
resource for 'service_account_key', but a project isn't required if the
service account is a service account fully qualified name or a service
account email.

This PR relaxes the requirement that a project needs to be set for the
'service_account_key' resource, 'service_account' datasource and
'service_account_key' datasource, but will error if we try to build a
fully qualified name from a service account id when no project can be
found.

This also cleans up 'serviceAccountFQN' so it is slightly easier to
follow and return an error if there is no project but we need one to
build the service account fully qualified name.

Fixes: #1655
2018-06-18 13:37:41 -07:00
Jonathan Pentecost
8f31fec857 New datasource: service account and service account key (#1535) 2018-05-31 17:31:45 -07:00
Paddy Carver
4c40febd4b Ignore API not enabled errors when reading project
When reading a project, both App Engine and Billing would fail if
_neither_ the default project the provider was configured with nor the
project being targeted had the App Engine Admin or Billing APIs
(respectively) enabled. We didn't catch this because our source project
obviously has both enabled.

This fixes the matter by checking the error returned from each of those,
and if it looks like an API not enabled error, logging it at warning
level instead of returning it as an error, which will let the read
proceed as usual.
2018-05-22 16:59:33 -07:00
The Magician
56481d8316 Add liens resource. (#1484) 2018-05-17 16:33:30 -07:00
Vincent Roseberry
dc029dd329
Improve testing for forwarding rule (#1482) 2018-05-14 10:07:59 -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
a91951d3f8 Revert "remove dead api version code and move things around"
This reverts commit 7e291ce8392dc2766a158dd8d70007dcf791aa44.
2018-05-04 07:54:08 -07:00
Dana Hoffman
d59fcbbc59
Remove switch statements between api versions for container; clean up dead version code (#1427)
* remove switch statements between api versions for container

* remove dead api version code and move things around
2018-05-03 21:51:54 -07:00
Vincent Roseberry
7fd468c034
Delete dead code (#1411) 2018-05-01 12:31:43 -07:00
Vincent Roseberry
e58e099b1a
Generate resource entries in ResourcesMap in provider.go for generated resources. (#1397) 2018-04-30 14:30:43 -07:00
Darren Haken
2b1b668953 #1300 Supporting regional clusters for node pools (#1320)
This PR also switched us to using the beta API in all cases, and that had a side effect which is worth noting, note included here for posterity.

=====
The problem is, we add a GPU, and as per the docs, GKE adds a taint to
the node pool saying "don't schedule here unless you tolerate GPUs",
which is pretty sensible.

Terraform doesn't know about that, because it didn't ask for the taint
to be added. So after apply, on refresh, it sees the state of the world
(1 taint) and the state of the config (0 taints) and wants to set the
world equal to the config. This introduces a diff, which makes the test
fail - tests fail if there's a diff after they run.

Taints are a beta feature, though. :) And since the config doesn't
contain any taints, terraform didn't see any beta features in that node
pool ... so it used to send the request to the v1 API. And since the v1
API didn't return anything about taints (since they're a beta feature),
terraform happily checked the state of the world (0 taints I know about)
vs the config (0 taints), and all was well.

This PR makes every node pool refresh request hit the beta API. So now
terraform finds out about the taints (which were always there) and the
test fails (which it always should have done).

The solution is probably to write a little bit of code which suppresses
the report of the diff of any taint with value 'nvidia.com/gpu', but
only if GPUs are enabled. I think that's something that can be done.
2018-04-24 17:55:21 -07:00
emily
7fd537db69
Fix IAM policy deletion/read for deleted resources (#1262)
* add util for handling wrapped/raw google api errors

* add 404 error handling to shared iam files

* fix errwrap calls in iam files

* fix import

* remove newlines, clear ID for removed state in iam binding
2018-03-27 16:41:44 -07:00
Shinichi TAMURA
fc6a821433 Suppress perpetual diff on logging sink filter with surrounding whitespaces (#1206) 2018-03-20 12:49:50 -04:00
Vincent Roseberry
4b1fdee504
Changes to handle autogeneration. (#1087)
* Add Set method to TerraformResourceData and ResourceDataMock

* Add Id() and SetId() to ResourceDataMock and TerraformResourceData

* Keep only name when reading region or zone field to handle api that returns self_link
2018-02-15 15:32:31 -08:00
Emily Ye
41a0fddfbd remove multiple locks from cluster update and add lock helper 2018-02-05 09:45:53 -08:00
Vincent Roseberry
629c53be03
Make get(Region|Project|Zone) method testable (#1040) 2018-02-02 10:55:43 -08:00
Emily Ye
5f3070e223 add diff suppress for empty network policy in container cluster 2018-01-31 14:36:03 -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
da3a6f13a1
Infers region from zone before using the provider-level region (#938) 2018-01-09 13:57:02 -08:00
Vincent Roseberry
283c8f89e3
Delete unused methods (#905) 2018-01-02 14:15:13 -05:00
Nathan McKinley
114b646fae
Enable 'zone' to be specified at the provider level instead of per-resource. (#816)
- Fetch Zone attribute any place where it *was* being fetched from the schema by
	combination schema / provider-level attribute.
- Allow region to be unspecified if zone is specified.
- Switch one example to using provider-level zone as an example.
- Make provider-level zone optional.  (Individual resources will fail if they can't find a zone.)
- Add tests for getZone and getRegion.
2017-12-06 14:30:04 -08:00
Vincent Roseberry
8f701c6ebb
Remove getNetworkName method and use ParseNetworkFieldValue instead (#802) 2017-11-29 10:54:10 -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
Nicki Watt
68f7d775c3 Add google_dataproc_job resource (#253)
* Add google_dataproc_job resource

* Correct state ref in docs

* make tests parallel

* cleanup, mostly whitespace related

* docs fmt
2017-11-21 09:32:43 -08:00
Dana Hoffman
2c8dbac663
Fix timeout issue with project services (#737)
* retry api enablement/disablement for 10 minutes

* retry to retryTime
2017-11-14 11:41:57 -08:00
Michael Bannister
ee641e0b1f Relax diff on maintenance_policy.daily_maintenance_window.start_time (#726)
* Relax diff on maintenance_policy.daily_maintenance_window.start_time

If the maintenance window has been set outside of Terraform to a time with a
single-digit hour (such as 1:00), and the terraform definition is set to the
same hour but with a leading zero as per validation (i.e. 01:00), do not
consider the time to be changed (as we currently don't support update on this
property).

Fixes #719

* Generalise rfc3339TimeDiffSuppress and add more test cases
2017-11-13 11:30:26 -08:00
Vincent Roseberry
0332208bc9
Add import support to global forwarding rule (#653) 2017-10-31 11:28:55 -07:00
Nicki Watt
96ac8fc8a4 Add google_dataproc_cluster resource (#252)
* Add google_dataproc_cluster resource

* Add google_dataproc_cluster tests

* Add google_dataproc_cluster docs

* Removed google_dataproc_job ref (to be added in separate PR)

* Added delete_autogen_bucket attribute

* Refactored / simplified wait mechanism

* Changes based on review

* go fmt

* Add  cluster_config enclosing config block

* Review updates - primarily re restructuring hierarchy

* Removed rogue import

* docs - alignment

* Changes for review

* Refactoring into expandXXX methods

* Refactoring of flattenXXX methods to be explicit
2017-10-30 16:41:37 -07:00
Vincent Roseberry
45c1d723e5 Create a reusable GlobalFieldValue and support reading project from schema (#550) 2017-10-10 09:53:57 -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
Dana Hoffman
bb0ab8e1f6 Merge the schemas and logic for the node pool resource and the node pool field in the cluster to aid in maintainability (#489) 2017-10-03 17:09:34 -07:00
Vincent Roseberry
5f887b6568 Add update support for pubsub subscription push config field (#512) 2017-10-03 13:14:51 -07:00
Dana Hoffman
2db85e8e75 Add new retry wrapper fn, retry sql database instance operations that commonly 503 (#417)
* Retry sql database instance operations that commonly 503

* use new retry wrapper fn in resource_storage_bucket.go
2017-10-03 12:41:04 -07:00
Joe Selman
ef543b20c5 Add google_logging_folder_sink resource (#470)
* Fix bad page title

* Add resource logging_folder_sink

* Use proper parse function and string format

* Remove unused strings
2017-10-03 09:26:19 -07:00
Dana Hoffman
2d733a1600 Add new google_compute_shared_vpc resource (#396)
* Revendor compute apis

* Add new resource for shared VPC host

* add test for disabled

* add docs for shared vpc host resource

* make project required

* Add new resource google_compute_shared_vpc

* Remove google_compute_shared_vpc_host

* Add docs for shared vpc resource

* Remove docs for shared vpc host resource

* fix typos in shared vpc docs

* move helper fn to utils.go
2017-09-13 10:36:07 +08:00
Vincent Roseberry
c751a32626 Add new resource region_instance_group_manager (#394) 2017-09-08 17:02:32 -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
Vincent Roseberry
5be9d28369 Import for compute_address supports multiple id formats. (#378)
This allows to import address from region and project different than the default project.
2017-09-07 10:38:26 -07:00
Joe Selman
227ea5660f Add support for setting labels to compute_image (#339) 2017-08-18 13:34:11 -07:00
Joe Selman
329a25848b Move non-provider related functions into a utils.go file (#325) 2017-08-15 16:35:46 -07:00