Commit Graph

77 Commits

Author SHA1 Message Date
Alex Pilon 4bf43efcfd
move hcl2shim package to configs 2019-08-06 19:58:58 -04:00
Alex Pilon 2a01704208
restore legacy functions for back compat 2019-08-06 15:22:28 -04:00
Alex Pilon 732211617e
fix typo 2019-08-05 22:08:04 -04:00
Alex Pilon 83aa07f907
prune NewResourceConfig and update tests 2019-08-05 22:08:03 -04:00
James Bardin 8250b2e4de more precise handling of ComputedKeys in config
With the new ConfigModeAttr, we can now have complex structures come in
as attributes rather than blocks. Previously attributes were either
known, or unknown, and there was no reason to descend into them. We now
need to record the complete path to unknown values within complex
attributes to create a proper diff after shimming the config.
2019-05-05 09:02:33 -04:00
James Bardin 43f0468829 fix ComputedKeys for nested blocks in shimmed cfg
The indexes were added out of order in the attribute keys
2019-05-02 14:08:40 -07:00
Martin Atkins 88e76fa9ef configs/configschema: Introduce the NestingGroup mode for blocks
In study of existing providers we've found a pattern we werent previously
accounting for of using a nested block type to represent a group of
arguments that relate to a particular feature that is always enabled but
where it improves configuration readability to group all of its settings
together in a nested block.

The existing NestingSingle was not a good fit for this because it is
designed under the assumption that the presence or absence of the block
has some significance in enabling or disabling the relevant feature, and
so for these always-active cases we'd generate a misleading plan where
the settings for the feature appear totally absent, rather than showing
the default values that will be selected.

NestingGroup is, therefore, a slight variation of NestingSingle where
presence vs. absence of the block is not distinguishable (it's never null)
and instead its contents are treated as unset when the block is absent.
This then in turn causes any default values associated with the nested
arguments to be honored and displayed in the plan whenever the block is
not explicitly configured.

The current SDK cannot activate this mode, but that's okay because its
"legacy type system" opt-out flag allows it to force a block to be
processed in this way anyway. We're adding this now so that we can
introduce the feature in a future SDK without causing a breaking change
to the protocol, since the set of possible block nesting modes is not
extensible.
2019-04-10 14:53:52 -07:00
James Bardin c37147d876 fix computed set keys in shims
When generated a config, the computed set keys were missing the leading
set name.
2019-01-22 18:10:12 -05:00
James Bardin 6dad121e70 insert resource timeouts into the config schema
Resource timeouts were a separate config block, but did not exist in the
resource schema. Insert any defined timeouts when generating the
configshema.Block so that the fields can be accepted and validated by
core.
2018-10-30 13:14:08 -04:00
James Bardin 6732b6713b missed IsNull check in config shim 2018-10-26 14:02:09 -04:00
James Bardin e08a388d3c check IsKnown on values that may panic 2018-10-18 19:21:32 -04:00
Martin Atkins c06f24b323 core: Use hcl2shimConfigValueFromHCL2Block when shimming ResourceConfig
This ensures more HCL1/HIL-like behaviors when dealing with nested blocks
that are not set in the configuration, which is important for
compatibility with helper/schema's validation logic.
2018-10-16 19:14:54 -07:00
Martin Atkins e3dad1bcc1 core: Drop InstanceInfo.HumanId
Our shims from new provider API to old can't populate the InstanceInfo
fully since the new API only includes the type name, and so anyone
depending on this method is now broken anyway.

In practice only our own tests depend on this, and so we'll drop it to
make it explicit that it no longer works (rather than having it return
nonsense) and then fix up the remaining tests that were depending on it
to use a different strategy.
2018-10-16 19:14:11 -07:00
Martin Atkins 1cc9d00da6 core: don't panic if NewResourceConfigShimmed gets a null
When we're working on a create or destroy change it's expected for one of
the values to be null. Here we mimick the pre-0.12 behavior of producing
just an empty map in that case, which the helper/schema code (now the only
caller of this shim) then ignores completely.
2018-10-16 19:14:11 -07:00
Martin Atkins 479c6b2466 move "configschema" from "config" to "configs"
The "config" package is no longer used and will be removed as part
of the 0.12 release cleanup. Since configschema is part of the
"new world" of configuration modelling, it makes more sense for
it to live as a subdirectory of the newer "configs" package.
2018-10-16 18:50:29 -07:00
Martin Atkins 1ed56f9903 core: NewInstanceInfo should take ResourceInstance, not Resource
On the initial pass here I reached a faulty conclusion about what from
the new world should shim into a NewInstanceInfo, based on a poor read
of existing code.

It actually _should've_ been based on an absolute instance after all,
as evidenced by the expected result of TestContext2Refresh_targetedCount.
Therefore the signature is changed here, and all of the callers (which,
in retrospect, were all holding a full instance address anyway!) are
updated to that new signature.
2018-10-16 18:49:20 -07:00
Martin Atkins 153021dd08 core: NewResourceConfigShimmed not to crash without schema
Although there isn't really a good reason why there should be no schema
in practice, it's better for us not to crash right now while we're still
updating all of the callers (mostly tests) to make schema available.
2018-10-16 18:49:20 -07:00
James Bardin d0693d0db5 fix InstanceInfo.HumanId
The module no longer has a "root" component, and use the
normalizeModulePath function for consistency
2018-10-16 18:49:20 -07:00
James Bardin d55d623ef0 handle unset computed values in tests
The old testDiffFn used th raw config to dynamically set computed values
in the diff. Since the schema now defines what values should be there,
all test diffs end up with unkown computed values. Filter these out by
looking for a value set to "compute"
2018-10-16 18:48:28 -07:00
Martin Atkins cc5b1d452f core: NewInstanceInfo now produces correct "id" for data resources
We need to mimic the old API here, and we weren't doing that quite right
since the "data" prefix was missing from data resources.
2018-10-16 18:48:28 -07:00
James Bardin e6478599c6 strip unknown values from the resource config
Computed values are now all added to the config value as unknowns. Strip
these out to match the legacy expatiations.
2018-10-16 18:48:28 -07:00
Martin Atkins c937c06a03 terraform: ugly huge change to weave in new HCL2-oriented types
Due to how deeply the configuration types go into Terraform Core, there
isn't a great way to switch out to HCL2 gradually. As a consequence, this
huge commit gets us from the old state to a _compilable_ new state, but
does not yet attempt to fix any tests and has a number of known missing
parts and bugs. We will continue to iterate on this in forthcoming
commits, heading back towards passing tests and making Terraform
fully-functional again.

The three main goals here are:
- Use the configuration models from the "configs" package instead of the
  older models in the "config" package, which is now deprecated and
  preserved only to help us write our migration tool.
- Do expression inspection and evaluation using the functionality of the
  new "lang" package, instead of the Interpolator type and related
  functionality in the main "terraform" package.
- Represent addresses of various objects using types in the addrs package,
  rather than hand-constructed strings. This is not critical to support
  the above, but was a big help during the implementation of these other
  points since it made it much more explicit what kind of address is
  expected in each context.

Since our new packages are built to accommodate some future planned
features that are not yet implemented (e.g. the "for_each" argument on
resources, "count"/"for_each" on modules), and since there's still a fair
amount of functionality still using old-style APIs, there is a moderate
amount of shimming here to connect new assumptions with old, hopefully in
a way that makes it easier to find and eliminate these shims later.

I apologize in advance to the person who inevitably just found this huge
commit while spelunking through the commit history.
2018-10-16 18:46:46 -07:00
Florian Forster 6680b1f16b core: check for negative indices in ResourceConfig.get
The bounds checking in ResourceConfig.get() was insufficient: it detected when the index was greater than or equal to cv.Len() but not when the index was less than zero. If the user provided an (invalid) configuration that referenced "foo.-1.bar", the provider would panic.

Now it behaves the same way as if the index were too high.
2017-12-12 09:18:38 -08:00
Martin Atkins d4efc95191 command: show resource actions using resource addresses
Previously we were using the internal resource id syntax in the UI. Now
we'll use the standard user-facing resource address syntax instead.
2017-09-01 17:55:05 -07:00
James Bardin 68ba2d6ff0 ResourceConfig.get should never return (nil, true)
Fixes a case where ResourceConfig.get inadvertently returns a nil value.

Add an integration test where assigning a map to a list via
interpolation would panic.
2016-11-18 16:24:40 -05:00
Mitchell Hashimoto 9b5b122f14
terraform: ResourceConfig reimplementation for TypeUnknown
The primary change here is to expect that Config contains computed
values. This introduces `unknownCheckWalker` that does a really basic
reflectwalk to look for computed values and use that for IsComputed.

We had a weird mixture before checking whether c.Config was simply
missing values to determine where to look. Now we rely on IsComputed
heavily.
2016-11-09 14:28:16 -08:00
Mitchell Hashimoto 29485f6167
terraform: ResourceConfig.IsComputed cases 2016-11-09 14:28:15 -08:00
Mitchell Hashimoto 0c271b2b2d
terraform: better detection of unknown values in ResourceConfig, tests 2016-11-09 14:28:15 -08:00
Mitchell Hashimoto 9cc5e81a6c
terraform: add tests for IsComputed that pass on master 2016-11-09 14:28:15 -08:00
Mitchell Hashimoto 5ed1b5fc89
terraform: use the new TypeUnknown type from HIL
This makes all the computed stuff "just work" since HIL uses the same
computed sentinel value (string UUID) and the type differentiates it
from a regular string.
2016-11-09 14:28:15 -08:00
Mitchell Hashimoto 3dd64d9f2e
terraform: ResourceConfig.Equal should sort ComputedKeys
This was causing otherwise equal ResourceConfigs to report non-equal
which was incorrect, thus causing incorrect shadow graph errors.
2016-10-22 12:00:05 -07:00
Mitchell Hashimoto 77b9177bd5
terraform: an incredible number of failing tests! 2016-10-19 13:38:49 -07:00
Mitchell Hashimoto d7a5cc5b35
terraform: InstanceInfo.uniqueId
This adds a new function to get a unique identifier scoped to the graph
walk in order to identify operations against the same instance. This is
used by the shadow to namespace provider function calls.
2016-10-11 22:17:30 +08:00
Mitchell Hashimoto d37bb87bf2
terraform: ResourceConfig.DeepCopy should handle the nil case 2016-10-11 22:17:27 +08:00
Mitchell Hashimoto 37f5c6ae26
terraform: ResourceConfig.Equal handles nil case 2016-10-11 22:17:27 +08:00
Mitchell Hashimoto f897fa4701
terraform: ResourceConfig.Equal and tests 2016-09-27 18:52:32 -07:00
Mitchell Hashimoto 56901e5cfd
terraform: ResourceConfig.DeepCopy
This implements DeepCopy, still need to implement Equals to make this
more useful. Coming in the next commit but this still has its own full
functionality + tests.
2016-09-27 16:09:32 -07:00
James Bardin 632c16c212 Fix inconsistent results with self interpolation
Due to a race in interpolateForce(), a reference to self could return
inconsistent results.
2016-08-30 14:16:37 -04:00
James Nugent 340655d56c core: Allow "." character in map keys
Fixes #2143 and fixes #7130.
2016-07-14 12:38:43 -06:00
Sander van Harmelen d97b24e3c1
Add tests and fix last issues 2016-05-26 19:56:03 -05:00
Mitchell Hashimoto fa934d96d0 helper/schema: FieldReaderConfig detects computed maps 2015-04-21 22:07:52 +02:00
Mitchell Hashimoto 0e59acc2c9 terraform: enable self vars 2015-02-23 14:56:02 -08:00
Mitchell Hashimoto e37c187228 terraform: goodbye context.go (old) 2015-02-19 12:08:32 -08:00
Mitchell Hashimoto 012d68923c terraform: Eval 2015-02-19 12:07:55 -08:00
Mitchell Hashimoto 659a77c6ae helper/schema: validate subresources more effectively 2015-02-18 09:41:55 -08:00
Mitchell Hashimoto dcaf653d6f helper/schema: properly detect that a list is computed 2014-10-09 19:09:06 -07:00
Mitchell Hashimoto ea18b62e8f terraform: count.index 2014-10-02 22:02:59 -07:00
Armon Dadgar 4fe05428b3 terraform: Avoid having multiple primaries 2014-09-29 15:20:03 -07:00
Armon Dadgar f398708be2 terraform: Adding flag for CreateBeforeDestroy 2014-09-29 15:20:03 -07:00
Mitchell Hashimoto 2791badf01 terraform: ask for input for providers 2014-09-29 09:13:15 -07:00