Commit Graph

21159 Commits

Author SHA1 Message Date
James Bardin 89b931e18a
Merge pull request #16540 from hashicorp/jbardin/provider-inheritance
New provider inheritance
2017-11-02 17:41:41 -04:00
James Bardin ecdba2b0b2 add transform step logs from GraphTransformMulti 2017-11-02 16:38:32 -04:00
James Bardin b4e9240679 remove implicit provier tests from config/module
No longer needed
2017-11-02 15:43:45 -04:00
James Bardin 523b121341 fix get test working directory
use a temp dir and cleanup
2017-11-02 15:38:53 -04:00
James Bardin 241dae7ead resintate disabled tests
Reinstate the disabled tests that required some sort of inheritance
during graph evaluation.
2017-11-02 15:29:51 -04:00
James Bardin 05ef30be2c udpate test graph outputs
Some of the test graph outputs have changes now that implicit providers
are no longer added in the config.
2017-11-02 15:29:51 -04:00
James Bardin 838ffafc18 stop adding implicit provider configs
Now that providers in the graph can adopt resources without an explicit
provider, there's no need to add the implicit configs to the module.Tree
when loading.
2017-11-02 15:29:51 -04:00
James Bardin a782568645 simplify MissingProvider and ParentProvider transf
Simplify the MissingProviderTransformer so that it only adds missing
providers at the root level. There's no need for the multitple providers
added at every level of the path

ParentProviderTransformer then only needs to connect providers with the
equivalent type at the root level.
2017-11-02 15:29:51 -04:00
James Bardin 341ec39174 udpate more tests to remove intermediate providers
The new missing provider transformer doesn't add these nay longer
2017-11-02 15:29:51 -04:00
James Bardin 94ee4d9111 Add new test and update graph outputs
The the grandChild missing test has a provider declared in a child
module which is missing in a grandchildmodule. Verify that the
grandchild gets connected to the child provider, and they all are
connected to the root providers.

Update some test outputs to match the expected behavior of only adding
missing providers at the root level.
2017-11-02 15:00:06 -04:00
James Bardin 2f91007999 group the provider transformations
The series of provider transformations is important, and often repeated.
Group these together in a single transform function.
2017-11-02 15:00:06 -04:00
James Bardin 12a4a29cbd update missing provider transform test
The CloserProviderTransformer requires that the resources be connected
to their provider first, so that it cen get the correct dependencies,
and adding the ProviderTransformer changed the test output slightly.
2017-11-02 15:00:06 -04:00
James Bardin 8388dfd2f9 update GraphBuilder_targetModule test
The updates CLoseProviderTransformer connects all provider instances,
which is technically the correct behavior.
2017-11-02 15:00:06 -04:00
James Bardin a14fd0344c WIP reference providers by full name
This turned out to be a big messy commit, since the way providers are
referenced is tightly coupled throughout the code. That starts to unify
how providers are referenced, using the format output node Name method.

Add a new field to the internal resource data types called
ResolvedProvider. This is set by a new setter method SetProvider when a
resource is connected to a provider during graph creation. This allows
us to later lookup the provider instance a resource is connected to,
without requiring it to have the same module path.

The InitProvider context method now takes 2 arguments, one if the
provider type and the second is the full name of the provider. While the
provider type could still be parsed from the full name, this makes it
more explicit and, and changes to the name format won't effect this
code.
2017-11-02 15:00:06 -04:00
James Bardin 1d54d4b10d WIP start only referring to provier by adddress
Don't try to build a full adress based on the context path for providers
in EvalContextBuiltin. Only use the name explicitly provided.
2017-11-02 15:00:06 -04:00
James Bardin f0727501c1 WIP only add missing providers at the root level
When looking for providers to connect to resources, walk up the resource
path to find the appropriate provider.
2017-11-02 15:00:06 -04:00
James Bardin 0986d01223 add providers directly from the configuration
The first step in only using the required provider nodes in a graph is
to be able to specifically add them from the configuration.

The MissingProviderTransformer was previously responsible for adding
all providers. Now it is really just adding any that are missing from
the config.
2017-11-02 15:00:06 -04: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
Martin Atkins da61627b9c
Update CHANGELOG.md 2017-11-01 17:00:43 -07:00
Martin Atkins 6d6a80fd9d
Update CHANGELOG.md 2017-11-01 16:58:31 -07:00
Martin Atkins 9d77d35f53
Update CHANGELOG.md 2017-11-01 16:56:59 -07:00
Martin Atkins 3da5fefdc1 command: Allow TF_DATA_DIR env var to override data directory
This allows the user to customize the location where Terraform stores
the files normally placed in the ".terraform" subdirectory, if e.g. the
current working directory is not writable.
2017-11-01 16:55:23 -07:00
Martin Atkins 4787428cad
Merge #14887: Custom diff logic for providers 2017-11-01 15:56:54 -07:00
Chris Marchesi 0c0ae3ca7c helper/schema: CustomizeDiff allowed on writable resources only
This keeps CustomizeDiff from being defined on data sources, where it
would be useless. We just catch this in InternalValidate like the rest
of the CRUD functions that are not used in data sources.
2017-11-01 15:42:24 -07:00
Chris Marchesi 2c541e8c97 helper/schema: Add behaviour detail to various custom diff comments
Added some more detailed comments to CustomizeDiff's comments. The new
comments detail how CustomizeDiff will be called in the event of
different scenarios like creating a new resource, diffing an existing
one, diffing an existing resource that has a change that requires a new
resource, and destroy/tainted resources.

Also added similar detail to ForceNew in ResourceDiff.

This should help mitigate any confusion that may come up when using
CustomizeDiff, especially in the ForceNew scenario when the second run
happens with no state.
2017-11-01 15:42:24 -07:00
James Bardin 229c70cabe
Merge pull request #16296 from stack72/manta-backend
Migrate Manta Remote state to be a backend
2017-11-01 18:07:26 -04:00
Radek Simko b599dc6471
Make CoC and support channels more visible
https://help.github.com/articles/adding-a-code-of-conduct-to-your-project/
https://help.github.com/articles/adding-support-resources-to-your-project/
2017-11-01 23:06:23 +01:00
Chris Marchesi 5031767b93 terraform: Add more exception cases for value comparison
Needed to add more cases to support value comparison exceptions that the
rest of TF expects to work (this fixes tests in various places).

Also moved things to a switch block so that it's a little more compact.
2017-11-01 14:25:32 -07:00
Chris Marchesi 12378b4ee2 terraform: Add value check to diff.Same
A diff new needs to pass basic value checks to be considered the
"same". Several provisions have been added to ensure that the list, set,
and RequiresNew behaviours that have needed some exceptions in the past
are preserved in this new logic.

This ensures that we are checking for value equality as much as
possible, which will be more important when we transition to the
possibility of diffs being sourced from external data.
2017-11-01 14:25:32 -07:00
Chris Marchesi f5bdbc0911 helper/schema: Simplify setDiff, remove exported SetDiff mentions
setDiff does not make use of its new parameter anymore, so it has been
removed. Also, as there is no more SetDiff (exported) function, mentions
of that have been removed from comments too.
2017-11-01 14:25:32 -07:00
Chris Marchesi 3ac0cdf0c0 helper/schema: Better ResourceDiff schema key validation
This fixes nil pointer issues that could come up if an invalid key was
referenced (ie: not one in the schema). Also ships a helper validation
function to streamline things.
2017-11-01 14:25:32 -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 09e2109ff8 helper/schema: Resouce.Diff no longer ResourceProvider API compatible
The old comments said that this interface was API compatible with
terraform.ResourceProvider's Diff method - with the addition of passing
down meta to it, this is no longer the case.

Not too sure if this is really a big deal - schema.Resource never fully
implemented terraform.ResourceProvider, from what I can see, and the
path from Provdier.Diff to Resource.Diff is still pretty clear. Just
wanted to remove an outdated comment.
2017-11-01 14:25:32 -07:00
Chris Marchesi 9625830980 helper/schema: Move computedKeys init to init function
This simplifies the new value initialization and future-proofs it
against more complex initialization functionality.
2017-11-01 14:25:32 -07:00
Chris Marchesi f0aafe4d67 helper/schema: Restore new value for complex set test 2017-11-01 14:25:32 -07:00
Chris Marchesi 3444549d60 helper/schema: Move computed key reader logic to childAddrOf
This will make this check safer and will remove the risk of it passing
on keys with a similar prefix.
2017-11-01 14:25:32 -07:00
Chris Marchesi 36aa63b338 helper/schema: Guard against out of range on childAddrOf
This could panic if we sent a parent that was actually longer than the
child (should almost never come up, but the guard will make it safe
anyway).

Also fixed a slice style lint warning in UpdatedKeys.
2017-11-01 14:25:32 -07:00
Chris Marchesi 931b0e1441 helper/schema: Remove exported SetDiff method
The consensus is that it's a generally better idea to move setting the
functionality of old values completely to the refresh/read process,
hence it's moot to have this function around anymore. This also means we
don't need the old value reader/writer anymore, which simplifies things.
2017-11-01 14:25:32 -07:00
Chris Marchesi ad98471559 helper/schema: Correct some comments
Removed some outdated comments for SetNew, and normalized the computed
key note for SetNew, SetNewComputed, and SetDiff.
2017-11-01 14:25:32 -07:00
Chris Marchesi 8a7c9a6f02 helper/schema: frist -> first 2017-11-01 14:25:32 -07:00
Chris Marchesi 7d5f9ed6b1 helper/schema: NewComputed values should be nil
When working on this initially, I think I thought that since NewComputed
values in the diff were empty strings, that it was using the zero value.
After review, it doesn't seem like this is the case - so I have adjusted
NewComputed to pass nil values. There is also a guard now that keeps the
new value writer from accepting computed fields with non-nil values.
2017-11-01 14:25:32 -07:00
Chris Marchesi 6f422d8c44 helper/schema: Remove unused log line
Meant to remove this before finalizing the PR. :P
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 f7e42728b6 helper/schema: Remove unused Destroy check for CustomizeDiff
Both Destroy and DestroyDeposed are not propagated down the diff stack,
meaning that there is no way we can tell at this point if an instance is
being destroyed or deposed, so this check would never be used.

In this regard, Destroy never runs a diff down the stack at all, and a
deposition check is not run until *after* the provider's diff function
is called. To answer this question and close it off, we could either
determine if a resource is deposed earlier, and propagate that down, or
treat deposed resources like full destroy nodes, and not diff them at
all (but rather making a diff with the only thing in it being
DestroyDeposed flagged).
2017-11-01 14:25:32 -07:00
Chris Marchesi fa1fc2ca8e helper/schema: CustomizeDiff invocation test
Just one more test to check to make sure that CustomizeDiff is called
on resource level.
2017-11-01 14:25:32 -07:00
Chris Marchesi ee769188d7 helper/schema: More CustomizeDiff test cases
Added a few more test cases for CustomizeDiff, caught another error in
the process. I think this is ready for review now, and possibly some
real-world testing of the waters by way of porting some resources that
would benefit from the feature.
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
Chris Marchesi 8126ee8401 helper/schema: Fix supplied config to tests 2017-11-01 14:25:32 -07:00