Commit Graph

7724 Commits

Author SHA1 Message Date
James Bardin 2b4d030a69 don't re-add removed list values even when planned
Providers were not strict (and were not forced to be) about customizing
the diff when a computed attribute needed to be updated during apply.
The fix we have in place to prevent loss of information during the
helper/schema apply process would add in single missing value back in.

The first place this was caught was when we attempt to fix up the
flatmapped attributes. The 1->0 count error is now better handled by our
cty.Value normalization step, so we can remove the special apply case
here altogether

The next place is in normalizeNullValues, and since the intent was to
re-insert missing zero-value lists and sets, adding a check for a length
of 0 protects us from adding in extra elements.

The new test fixture emulated common provider behavior of re-computing
values without customizing the diff. Since we can work around it, and
core will provider appropriate warnings, the shims should try to
maintain the legacy behavior.
2019-03-05 15:31:08 -05:00
James Bardin 47604c36c8 remove the partially-known ~ set sigil in diffs
The NewExtra values are stored outside the diff from plan, and the
original keys may not contain the ~ prefix. Adding the NewExtra back
into the diff with the mismatched key was causing an entire new set
element to be populated. Since this symbol isn't used to apply the diff
in helper/schema, we can simply strip them out.
2019-03-04 17:36:30 -05:00
James Bardin c814f2da37 Change backend.ValidateConfig to PrepareConfig
This mirrors the change made for providers, so that default values can
be inserted into the config by the backend implementation. This is only
the interface and method name changes, it does not yet add any default
values.
2019-02-25 18:37:20 -05:00
James Bardin da389d6cd4 simple list diffs may also have missing elements
Like was done for list blocks, simple lists of strings may be missing
empty string elements, and any list may be implicitly truncated.
2019-02-14 13:06:04 -05:00
James Bardin 931f459336 add a trouble test schema from the aws provider 2019-02-13 19:09:46 -05:00
James Bardin f932e11a50 create a test that removes a RequiresReplace path
One of the paths that triggers RequiresReplace does not apply to the
new value.
2019-02-12 11:48:36 -05:00
James Bardin 1ca7531cc7 allow implicit empty strings in lists
The helper/schema handling of lists loses empty string values, but
retains the correct count. Only re-count the values if the count is
missing entirely, and allow our shims to re-populate the zero values.
2019-02-11 19:24:14 -05:00
James Bardin 1bfc27817e process state even after provider.Apply errors
Terraform core expects a sane state even when the provider returns an
error. Make sure at the prior state is always the default value to
return, and then alway attempt to process any state returned by
provider.Apply.
2019-02-11 15:41:07 -05:00
James Bardin be127725cc Additional tests with interpolated values 2019-02-07 20:23:39 -05:00
James Bardin 411df99f33 only force top-level id's back to unknown
Nested structures may have "id" fields, which should be treated
normally.
2019-02-05 16:16:08 -05:00
James Bardin 3b18dd7c01
Merge pull request #20224 from hashicorp/jbardin/sdk
SDK set fixes
2019-02-05 14:11:51 -05:00
James Bardin 79d1e0d7cf add failing test for multiple computed set elems 2019-02-05 12:08:17 -05:00
James Bardin 2e2374cfcb add failing test for set elements with custom diff
Adding a DiffSuppressFunc for set elements can cause them to be missed
in the set diff entirely.
2019-02-05 12:08:16 -05:00
Martin Atkins bdcac8792d plugin: Use correct schema when marshaling imported resource objects
Previously we were using the type name requested in the import to select
the schema, but a provider is free to return additional objects of other
types as part of an import result, and so it's important that we perform
schema selection separately for each returned object.

If we don't do this, we get confusing downstream errors where the
resulting object decodes to the wrong type and breaks various invariants
expected by Terraform Core.

The testResourceImportOther test in the test provider didn't catch this
previously because it happened to have an identical schema to the other
resource type being imported. Now the schema is changed and also there's
a computed attribute we can set as part of the refresh phase to make sure
we're completing the Read call properly during import. Refresh was working
correctly, but we didn't have any tests for it as part of the import flow.
2019-02-01 15:22:54 -08:00
James Bardin 89c1ba099f add computed set test with CustomizeDiff 2019-02-01 17:21:37 -05:00
James Bardin fa92e69e17 simplify test check 2019-01-30 14:55:04 -05:00
James Bardin 3b04b41250 fix RequiresNew in diff
With the new diff.Apply we can keep the diff mostly intact, but we need
turn off all RequiresNew flags so that the prior state is not removed
from the apply.
2019-01-30 14:55:04 -05:00
Martin Atkins 477da57a92 helper/plugin: Honor resource type overrides in import
One quirky aspect of our import feature is that we allow the importer to
produce additional resources alongside the one that was imported, such as
to create separate rules for each rule of an imported security group.

Providers need to be able to set the types of these other resources since
they may not match the "main" resource type. They do this by calling
ResourceData.SetType, which in turn sets InstanceState.Ephemeral.Type.

In our shims here we therefore need to copy that out into our new TypeName
field so that the new core import code can see it and create the right
type in the state.

Testing this required a minor change to the test harness to allow the
ImportStateCheck function to see the resource type.
2019-01-30 09:05:08 -08:00
James Bardin 775df57217 add more tests
verify that changes to defaults are detected
2019-01-23 20:03:10 -05:00
James Bardin 7dd0acc46b don't count empty containers in diff.Apply
If there were no matching keys, and there was no diff at all, don't set
a zero count for the container. Normally Providers can't reliably detect
empty vs unset here, but there are some cases that worked.
2019-01-23 19:34:11 -05:00
James Bardin 675d700a5f test for missing map entries 2019-01-23 17:04:17 -05:00
James Bardin 93d78c4ee7 disable broken import test for now 2019-01-22 18:10:12 -05:00
James Bardin f78b5045d0 add failing test for lost elements in list blocks
Modifying an element loses the modification, and other elements in a
TypeList.
2019-01-22 18:10:12 -05:00
James Bardin c045d3e6a3 disable known failing tests
We need these changes in master for testing, worry about these test
after.
2019-01-17 19:19:13 -05:00
James Bardin 4439a7dcf4 add tests for nested default values
Don't lose default values set within a nested block.
2019-01-17 18:51:18 -05:00
James Bardin 0d1252812b add more tests for a computed nested list and set 2019-01-15 11:55:02 -05:00
James Bardin 9b89f6ecc6 add tests for deprecated/removed attrs 2019-01-12 10:41:04 -05:00
James Bardin 3e3802c36f update existing test provider test 2019-01-10 13:08:54 -05:00
James Bardin f4fe6d6716 add tests with set hashes to the test provider
These are representative of things that real-world providers use in
tests.
2019-01-10 12:26:53 -05:00
James Bardin 7455bf2a55 provider tests for empty values
Add tests to make limited use of empty container values and empty
strings.
2019-01-08 16:26:22 -05:00
James Bardin 725ccea6d4
Merge pull request #19732 from hashicorp/jbardin/terraform-remote-state
there is always an implied workspace of "default"
2018-12-21 09:11:18 -05:00
Martin Atkins 364d3ffc4a provider/test: Test for nested dynamic blocks
This is a HCL feature rather than a Terraform feature really, but we want
to make sure it keeps working consistently in future versions of Terraform
so this is a Terraform-flavored test for the block expansion behavior.

In particular, it tests that a nested dynamic block can access the parent
iterator, so that we won't regress #19543 in future.
2018-12-20 14:28:37 -08:00
James Bardin 41002e1a24 there is always an implied workspace of "default"
Fetching a state requires a workspace name, which should default to
"default"
2018-12-20 17:17:11 -05:00
Martin Atkins e39c69750c core: Specialized errors for incorrect indexes in resource reference
In prior versions of Terraform we permitted inconsistent use of indexes
in resource references, but in as of 0.12 the index usage must correlate
properly with whether "count" is set on the resource.

Since users are likely to have existing configurations with incorrect
usage, here we introduce some specialized error messages for situations
where we can detect such issues statically. This seems to cover all of the
common patterns we've seen in practice.

Some usage patterns will fall back on a less-helpful dynamic error here,
but no configurations coming from 0.11 can end up that way because 0.11
did not permit forms such as aws_instance.no_count[count.index].bar that
this validation would not be able to "see".

Our configuration upgrade tool also contains a fix for this already, but
it takes a more conservative approach of adding the index [1] rather than
[count.index] because it can't be sure (without human help) if correlation
of indices is what was intended.
2018-12-20 13:55:42 -08:00
James Bardin c70be3c328 failing tests when using resources with count
Two different tests failing around resourced with count
2018-12-17 12:15:43 -05:00
James Bardin 53ff35b9ca StateFunc tests 2018-12-03 18:03:45 -05:00
James Bardin f0e51aca1a test a nil computed value within an expression
Comparing a nil-computed value was returning unknown, preventing the
data source from being evaluated.
2018-11-28 17:37:58 -05:00
James Bardin 622f5cc6fb add test for computed map value
This ensures that a computed map can be correctly applied.
2018-11-27 08:54:15 -05:00
James Bardin c24a18d514 remove unnecessary computed flag
The "with_list" attr wasn't actually computed,

Make sure we read with the correct function.
2018-11-27 08:54:15 -05:00
James Bardin 15d2330918 computed value wasn't being set 2018-11-27 08:54:15 -05:00
James Bardin eddf676c1f add provider test with a nested list in a set
in some cases helper/schema misses the list counts.
2018-11-16 15:11:16 -05:00
James Bardin a681124301 verify DiffSuppresFunc behavior
Terraform used to provide empty diffs to the provider when calculating
`ignore_changes`, which would cause some DiffSuppressFunc to fail, as
can be seen in #18209.

Verify that this is no longer the case in 0.12
2018-11-16 11:17:23 -05:00
James Bardin 83317975fe add more tests with carious set combinations 2018-11-16 09:59:03 -05:00
James Bardin 71b55601ce new failing tests for nested sets 2018-11-16 09:59:03 -05:00
James Bardin d2bd41c260 add a nested set test 2018-11-13 18:53:02 -05:00
James Bardin c4d0be8a52 failing test for schemas with a single set attr
Resources with certain combinations of attributes in a nested single set
fail to perperly coerce their shimmed values.
2018-11-13 18:41:53 -05:00
Sander van Harmelen 52a1b22f7a Implement the remote enhanced backend
This is a refactored version of the `remote` backend that was initially added to Terraform v0.11.8 which should now be compatible with v0.12.0.
2018-11-06 16:29:46 +01:00
James Bardin e91f381cc4 test case for optional bools in schema
Booleans in the legacy form were stored as strings, and can appear as
the incorrect type in the new type system.

Unset fields in sets also might show up erroneously in diffs, with
equal old and new values.
2018-11-01 16:19:03 -04:00
James Bardin 8212a6a9d0 add provider tests for force-new with a map
Adding and removing a single map that requires a new resource can cause
empty diffs, relying on the core proposed state values for destruction.
2018-10-31 13:42:28 -04:00
James Bardin 36cede09f7 add provider tests for SuppressDiffFunc 2018-10-30 14:53:38 -04:00
James Bardin 121c9c127f add timeout tests to the test provider 2018-10-30 13:14:08 -04:00
James Bardin ac5f08c5d8 PrepareProviderConfig for terraform provider 2018-10-18 11:12:56 -04:00
Martin Atkins 541952bb8f Revert some work that happened since v0.12-dev branched
This work was done against APIs that were already changed in the branch
before work began, and so it doesn't apply to the v0.12 development work.

To allow v0.12 to merge down to master, we'll revert this work out for now
and then re-introduce equivalent functionality in later commits that works
against the new APIs.
2018-10-16 19:48:28 -07:00
James Bardin 5303137b8c udpate test configs to work with hcl2
The last 2 broken tests will be hanlded later
2018-10-16 19:14:54 -07:00
Martin Atkins 9f1098ac5f builtin/providers/terraform: Fix tests
Various things drifted since these tests were originally written. This
catches them up to the latest implementations of state decoding,
upgrading, etc.
2018-10-16 19:14:11 -07:00
Martin Atkins 8c67fd52b0 builtin/providers: Don't panic if requested remote state isn't present 2018-10-16 19:14:11 -07:00
Martin Atkins d11dd20bf3 builtin/providers/test: use new API for root module address
terraform.RootModulePath is no longer present, but
addrs.RootModuleInstance is equivalent to it.
2018-10-16 19:14:11 -07:00
Martin Atkins 630b0d147d providers/terraform: Always produce correctly-typed result
We need to produce values for all of the attributes implied by our schema,
even if some of them are null.
2018-10-16 19:14:11 -07:00
Martin Atkins 235f582ae5 core: Re-implement EvalReadDataApply against new provider interface 2018-10-16 19:14:11 -07:00
James Bardin faa46d4727 add Close method to the terraform provider
Close is now part of the plugin interfaces, so needs to be implemented
by the terraform provider.
2018-10-16 19:11:09 -07:00
Martin Atkins a3403f2766 terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.

The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.

The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.

Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-10-16 19:11:09 -07:00
Kristin Laemmert 52ae93cf97 builtin/providers: terraform remote state datasource (#18446)
* builtin/providers: implement terraform remote state datasource as providers.Interface

* append and return diags separately (to match the idiomatic usage
elsewhere in Terraform)
* diagnostic summary style improvements
* update tests to pass config to schema.CoerceValue
* trust that the schema will be enforced and there is no need to check
that a given attribute exists
* added dataSourceRemoteStateGetSchema() (effectively replacing a
function that was inappropriately removed) for consistency with other
terraform providers
* builtin/provider terraform test: added InternalValidate() test for dataSourceRemoteStateGetSchema
2018-10-16 18:53:51 -07:00
Martin Atkins 5782357c28 backend: Update interface and implementations for new config loader
The new config loader requires some steps to happen in a different
order, particularly in regard to knowing the schema in order to
decode the configuration.

Here we lean directly on the configschema package, rather than
on helper/schema.Backend as before, because it's generally
sufficient for our needs here and this prepares us for the
helper/schema package later moving out into its own repository
to seed a "plugin SDK".
2018-10-16 18:39:12 -07:00
Sander van Harmelen 3e935c846f terraform/terraform_remote_state: accept complex configs
The `remote` backend config contains an attribute that is defined as a `*schema.Set`, but currently only `string` values are accepted as the `config` attribute is defined as a `schema.TypeMap`.

Additionally the `b.Validate()` method wasn’t called to prevent a possible panic in case of unexpected configurations being passed to `b.Configure()`.

This commit is a bit of a hack to be able to support this in the 0.11 series. The 0.12 series will have proper support, so when merging 0.12 this should be reverted again.
2018-08-29 20:21:47 +02:00
Sander van Harmelen 7fb2d1b8de Implement the Enterprise enhanced remote backend 2018-08-03 22:22:55 +02:00
Sander van Harmelen 97d1c46602 Update the backend import names
It’s a purely cosmetic change, but I find it easier to read them like this.
2018-08-03 11:29:11 +02:00
James Bardin e011dd95f3 don't let default workspace override environment
The workspace attribute should only override the environment if it's not
the default value.
2018-03-09 10:27:06 -05:00
James Bardin 13433687cb filter null output values from state
While null values should not normally appear in a state file, we should
filter the values rather than crash.
2018-03-08 11:39:29 -05:00
Nic Cope 5c58ef16f7 provider/terraform: deprecate "environment" in favor of "workspace" 2017-12-05 10:18:28 -08:00
Radek Simko 2974d63e75
Merge pull request #16588 from hashicorp/f-panic-on-invalid-rd-set
helper/schema: Opt-in panic on invalid ResourceData.Set
2017-11-08 19:17:46 +00:00
Radek Simko e93d64b18c
helper/schema: Opt-in panic on invalid ResourceData.Set 2017-11-08 10:05:11 +00:00
Martin Atkins bcc5dffea2 provider/terraform: import terraform provider back into core 2017-11-02 10:48:20 -07:00
Martin Atkins a3ced1a367 provider/terraform: reorganize for merge into core
The "terraform" provider was previously split out into its own repository,
but that turned out to be a mistake due to how tightly it depends on
aspects of Terraform Core.

Here we prepare to bring it back into the core repository by reorganizing
the directory layout to conform with what's expected there.
2017-11-02 10:46:31 -07:00
Chris Marchesi 5d5a670d69 provider/test: Added complex-ish list testing
Added a list SetNew test to try and reproduce issues testing diff
customization with the Nomad provider. We are running into "diffs didn't
match during apply", with the plan diff exhibiting a strange
off-by-one-type error in a list diff:

  datacenters.#:         "1" => "2"
  datacenters.0:         "dc1" => "dc2"
  datacenters.1:         "" => "dc3"
  datacenters.2:         "" => "dc3"

The test here does not reproduce that issue, unfortunately, but should
help pinpoint the root cause through elimination.
2017-11-01 14:25:32 -07:00
Chris Marchesi 529d7e6dae helper/schema: Review -> CustomizeDiff
Restoring the naming of this field in the resource back to
CustomizeDiff, as this is generally more descriptive of the process
that's happening, despite the lengthy name.
2017-11-01 14:25:32 -07:00
Chris Marchesi c6647a3bb7 helper/schema: CustomizeDiff -> Review
To keep with the current convention of most other schema.Resource
functional fields being fairly short, CustomizeDiff has been changed to
"Review". It would be "Diff", however it is already used by existing
functions in schema.Provider and schema.Resource.
2017-11-01 14:25:32 -07:00
Chris Marchesi 8af9610b87 helper/schema: Hook CustomizeDiffFunc into diff logic
It's alive! CustomizeDiff logic now has been inserted into the diff
process. The test_resource_with_custom_diff resource provides some basic
testing and a reference implementation.

There should now be plenty of test coverage for this feature via the
tests added for ResourceDiff, and the basic test added to the
schemaMap.Diff test, and the test resource, but more can be added to
test any specific case that comes up otherwise.
2017-11-01 14:25:32 -07:00
James Bardin 1ab40eae35 remove builtin providers
All providers moved to new repos.

Added README, which also serves to preserve the directory in git in
cacse we want to add select providers back into core (e.g. null,
template, test)
2017-06-12 13:42:06 -04:00
Martin Atkins 33a266d61c provider/terraform: "workspace" argument instead of "environment"
We are moving away from using the term "environment" to describe separate
named states for a single config, using "workspace" instead. The old
attribute name remains supported for backward compatibility, but is
marked as deprecated.
2017-06-09 15:01:39 -07:00
Martin Atkins f695e8b330 provider/test: allow test_resource to be imported
When working on the core import code, it's useful to have a zero-cost
local resource to work with for quick iteration.
2017-06-09 14:03:59 -07:00
stack72 6e7ee05392 Merge branch 'gh3424-vgw-route-prop' 2017-06-09 14:13:27 +03:00
stack72 c7d6dfd7e7 provider/aws: go vet issue with aws_vpn_gateway_route_propagation 2017-06-09 14:12:18 +03:00
Puneeth Nanjundaswamy 4d7c0d4924 fix aws cidr validation error (#15158) 2017-06-09 13:38:34 +03:00
Dana Hoffman 93c6c0de25 provider/google: Add an additional delay when checking for sql operations (#15170) 2017-06-09 13:33:29 +03:00
Jay Wang b465b01355 [MS] provider/azurerm: Data Source for Azure Resource Group (#15022)
* Data Source support for Resource Group

* Better message for mismatching locations.

* Reuse existing read code

* Adds documentation

* Adds test

* Adds a function for composing ID strings

* Change location to computed.
2017-06-09 13:10:42 +03:00
clint shryock d587b68863 provider/aws: Add an explicit depends on for the internet gateway, should help this test pass 2017-06-08 16:44:22 -05:00
clint shryock cd2a0b476b provider/heroku: Update app test to use new Heroku Space 2017-06-08 15:28:19 -05:00
Clint 8c52df5526 provider/heroku: Add support for special HEROKU_SPACES_ORGANIZATION env var for the TestAccHerokuSpace_Basic test (#15191) 2017-06-08 11:57:31 -05:00
Ashish Kumar Thakur a5c208ef68 provider/kubernetes: Add support for pod (#13571)
Add support for K8s pod
2017-06-08 14:58:10 +01:00
Bill Maxwell 305ae18d2c Rancher V2 provider updates (#13908)
* Move to v2 client in vendor directory

* Move to v2 api and project IDs for environments

* add host label support to registration command

* Update go-rancher/catalog

* Allow go-rancher to handle URL versioning
2017-06-08 12:24:53 +03:00
Riley Karson 45d193101c provider/google: Add support for draining_timeout_sec to compute_backend_service. (#14559) 2017-06-07 15:17:49 -07:00
Jan Škrášek 70e8d2d33f provider/aws/spot_fleet_request: fixed reading network associate_public_ip_address configuration (#13748) 2017-06-07 15:14:00 -05:00
Shinichi TAMURA 0b6518a29b provider/google: Changed network argument in google_compute_instance_group as optional (#13493) 2017-06-07 11:20:17 -07:00
Riley Karson f5cccc6b7f Added private_ip_google_access update support to google_compute_subnetwork. (#15125) 2017-06-07 16:52:14 +03:00
Paul Stack 75842077da provider/aws: Add gov and cn hosted zone Ids to aws_elb_hosted_zone data source (#15149)
Fixes: #15128
2017-06-07 13:18:26 +03:00
Gavin Williams a281a29cb6 provider/openstack: Optimize the printing of request/response headers… (#15086)
* provider/openstack: Optimize the printing of request/response headers when debugging Openstack HTTP requests

* provider/openstack: Log the response code aswell
2017-06-06 21:34:44 -06:00
Martin Atkins 1aff439c3d provider/aws: aws_vpn_gateway_route_propagation resource
This is a separate resource that serves a similar purpose to the
propagating_vgws argument on aws_route_table, but allows route
propagations to be created independently of the route table, which in
turn allows the VPN gateway to be created after the route table it will
contribute to, possibly in a separate Terraform module.

To make this work, propagating_vgws on aws_route_table is now marked
as Computed, meaning that it won't try to delete any existing propagation
edges if there is no setting for it in configuration at all. This allows
the user to choose whether to use the argument or the separate resource,
though using both together will not work, as explained in the docs.
2017-06-06 17:56:31 -07:00
Vasily Tarasov 677a418e78 provider/aws: Filter acm certificates by type (#15064)
* Filter ACM certificates by type

* Add schema tests for certificate types
2017-06-06 15:08:52 -05:00
Anthony Stanton 8acd5641eb Librato Alerts fixes (#15118)
* Improve UpdateAlert

* Check for non-nil values before d.Set()

* Initialize struct with required values

* Improve use of d.Set()

* Rely on Terraform MaxItems check

* Simplify Read method

* Catch Retry errors

* Improve test coverage
2017-06-06 19:29:29 +03:00
Clint 372a80bc42 provider/aws: Add Sweeper setup, Sweepers for DB Option Group, Key Pair (#14773)
* provider/aws: Add Sweeper setup, Sweepers for DB Option Group, Key Pair

* provider/google: Add sweeper for any leaked databases
* more recursion and added LC sweeper, to test out the Dependency path

* implement a dependency example

* implement sweep-run flag to filter runs

* stub a test for TestMain

* test for multiple -sweep-run list
2017-06-06 10:34:17 -05:00