Commit Graph

766 Commits

Author SHA1 Message Date
James Bardin 6fee1f24ab don't add duplicate unknowns to a set
The flatmap shim was lazily adding duplicate items and letting cty.Set
clear them out, but if those duplicates contains unknown values they
can't be checked for equality and will end up remaining in the set.
2018-11-13 18:41:53 -05:00
James Bardin f959b560a2 trim index steps from RequiresNew paths
Only GetAttrSteps can actually trigger RequiresNew, but the flatmaps
paths will point to the indexed value that caused the change.
2018-10-31 13:40:01 -04:00
Martin Atkins 93630cf95f config/hcl2shim: ConfigValueFromHCL2Block function
This is a more specialized version of ConfigValueFromHCL2 which is
specifically for config values that represent the content of a block
body in the configuration.

By using the schema of that block we can more precisely emulate the old
HCL1/HIL behaviors by distinguishing attributes from blocks and applying
some slightly different behaviors for the handling of null values and
of empty collections that are representing the absense of blocks of a
particular type.
2018-10-16 19:14:54 -07:00
James Bardin 5c436bb820 add a nested map test to hcl2shim 2018-10-16 19:14:11 -07:00
James Bardin 9d8ca4515e unknown collections in a flatmap
Unknown collections in a flatmap also need to be converted to unknown
values.
2018-10-16 19:14:11 -07:00
Martin Atkins 8cc8bacce3 config/hcl2shim: Treat DynamicVal like any other unknown value in flatmap 2018-10-16 19:14:11 -07:00
Kristin Laemmert d1f27ce8c2 registry: renaming module-specific registry functions 2018-10-16 18:56:50 -07:00
James Bardin f4416ee1df update the new RequiresReplace function
Make the function work specifically how we need for RequiresReplace.
Skip index changes, any set changes are only recorded as the set itself,
and filter out duplicate paths.

Add a few more tests to check for various nested structures.
2018-10-16 18:53:51 -07:00
James Bardin 30ff37f335 change PathFromFlatmapKey to RequiresReplace
Rather than try and make a generalized path function here, what we
really need in a function to generate the paths needed for
RequiresReplace. This needs to take into account that sets elements
don't need to be indexed themselves, and changes to collection index
values aren't needed.
2018-10-16 18:53:51 -07:00
James Bardin 44e993ec29 add hcl2shim.PathFromFlatmapKey
PathFromFlatmapKey is used to convert a flatmap key to a cty.Path, and
ensures it conforms to the type schema.

This is used when handling Diffs, where the ResourceAttrDiffs are
indexed by the flatmapped key values, and we need to convert those to
addresses to apply to a cty.Value.
2018-10-16 18:53:51 -07:00
James Bardin 05e85885f9 handle Null collections in flatmaps
When creating a flatmap from a cty.Value, there may be Null collections
which don't need to be added to the flatmap at all. Skip over these to
avoid panicking in ElementIterator with a Null value.
2018-10-16 18:53:51 -07:00
James Bardin c28ce02f2a return a nil flatmap when presented with a NullVal
A nil flatmap will be encoded as a NullVal of the correct type. When
Converting a NullVal back to a flatmap, return nil immediately rather
than attempting to build the values.
2018-10-16 18:50:29 -07:00
James Bardin ac8ee20233 return a NullVal when presented with a nil flatmap
This allows us to decode the cty.Value back to a nil map, rather than
trying to create a map with nil values.
2018-10-16 18:50:29 -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 299fe25a04 hcl2shim: Handle unknown values when shimming to/from flatmap
Previously unknown values were round-tripping through flatmap and coming
out as known strings containing the UnknownVariableValue. (The classic bug
that, ironically, was one of the big reasons to write cty!)

Now we properly handle unknown values in both directions: going in to
flatmap we write UnknownVariableValue at the appropriate key (as the count
for sequences or maps) and then coming out of flatmap we turn
UnknownVariableValue back into a cty unknown value of the requested type.
2018-10-16 18:48:28 -07:00
Martin Atkins ccc1b6990f config/hcl2shim: shims from flatmap to cty and vice-versa
These particular shims will have a pretty limited lifetime in mainline
Terraform code (primarily to stub out the new expression evaluator against
the old state structs until the new format is implemented) but will live
on for some time in state migration and provider plugin compatibility
shims.
2018-10-16 18:46:46 -07:00
Martin Atkins ebafa51723 command: Various updates for the new backend package API
This is a rather-messy, complex change to get the "command" package
building again against the new backend API that was updated for
the new configuration loader.

A lot of this is mechanical rewriting to the new API, but
meta_config.go and meta_backend.go in particular saw some major
changes to interface with the new loader APIs and to deal with
the change in order of steps in the backend API.
2018-10-16 18:44:26 -07:00
Martin Atkins 22d140e883 configschema: Block.CoerceValue method
The usual way to use a configschema.Block is to obtain a hcldec spec from
it and then decode an hcl.Body. There are inevitably situations though
where a body has already been decoded into a cty.Value before we know
which schema we need to use.

This new method CoerceValue is intended to deal with this case, applying
the schema to an already-decoded value in what should be an intuitive way
for most situations.
2018-10-16 18:24:47 -07:00
Martin Atkins d6c6f8852c configschema: include description in schema
We will need access to this information in order to render interactive
input prompts, and it will also be useful in returning schema information
to external tools such as text editors that have autocomplete-like
functionality.
2018-10-16 18:24:47 -07:00
Martin Atkins c51d22bdeb config/hcl2shim: don't put nils in ConfigValue maps
Absent values are omitted by the old code we are emulating in HCL, so we
must do the same here in order to avoid breaking assumptions in the
helper/schema layer.
2018-10-16 18:24:10 -07:00
Sander van Harmelen 179b32d426 Add a `CredentialsForHost` method to disco.Disco
By adding this method you now only have to pass a `*disco.Disco` object around in order to do discovery and use any configured credentials for the discovered hosts.

Of course you can also still pass around both a `*disco.Disco` and a `auth.CredentialsSource` object if there is a need or a reason for that!
2018-08-03 11:29:11 +02:00
Sander van Harmelen 9ba33e1958
Merge pull request #18360 from hashicorp/svh/b-close-body
svchost/disco: make sure to close the response body
2018-06-29 19:33:10 +02:00
Sander van Harmelen 2c0c3771a9 Make sure to close the response body
And fix a few linter warnings while we're at it…
2018-06-29 16:14:54 +02:00
Borys Pierov c811440188 config: Don't log the private key on error in rsadecrypt 2018-06-26 15:19:37 -07:00
James Bardin 7b5efad725 update missing alias message
Update the old error message for a missing provider alias, as we no
longer automatically inherit providers.
2018-04-03 17:40:36 -04:00
James Bardin 15dc75720e don't re-use a TempDir path
Rather than creating and immediately removing a temp directory to get a
random path name, fetch files into a subdirectory.
2018-03-28 11:33:42 -04:00
Martin Atkins 5b08fd4f9f config: Don't expose go implementation details in Resource.Count
Previously we would return the raw error from strconv.ParseInt, which
includes details in its text that expose implementation details and are
thus not helpful to the user.

Instead, we use a locally-defined error message that talks only about
what the caller is expected to know: that count should be parsable as
an integer.
2018-01-19 13:06:00 -08:00
Masayuki Morita e873af9337 Fix panic with substr interpolation function by invalid offset
Fixes #17041
2018-01-06 00:59:35 +09:00
Pierre-Alain TORET 128f4d19e1 config: Allow build on DragonFlyBSD
DragonFlyBSD is not officially supported, but allowing it to work is straightforward at the moment so we'll allow it for now.
2018-01-03 11:36:47 -08:00
James Bardin cf4995d8a7 use the full module name with host for errors
The module related logs and errors should reference the full module name
including the source host.
2018-01-03 10:44:41 -05:00
Rob Campbell 5daeee5f6d Update various files for new version of "stringer"
The latest version of stringer now uses strconv instead of fmt.
2017-12-11 13:26:29 -08:00
Martin Atkins 87e1fb4d66 config: a nicer error message for invalid provider constraints
Previously our error message here was confusing and redundant:

    Error starting operation: provider.null: invalid version constraint "not valid": Malformed constraint: not valid

Instead, we'll generate a full HCL2 diagnostic here, which results in
something (subjectively) nicer:

    Error: Invalid provider version constraint

    The value "@ 1.0.0" given for provider.null is not a valid version
    constraint.

At the moment this message is an outlier in that the other validation
errors are all still just plain Go errors, but over time we'll want to
adjust all of these to be full diagnostics so that we can embed source
range information in them to help the user find the offending
configuration.
2017-12-07 14:28:43 -08:00
James Bardin e0b2c64645 accessing count directly in an output should is OK
There should be no warning when accessing a resource's count value
directly in an output.
2017-12-06 18:59:53 -05:00
James Bardin 0e7dab09e6 Use the new registry.Client
The registry code has been moved into the new registry package. Remove
the duplicated code and use the new registry and registry/test packages.
2017-12-05 14:59:21 -05:00
Paul Banks 06f067b4e6
Update registry API docs with browse and search (#16846)
* Verify discovery works without trailing slash on discovery URL

* Update registry API docs with browse and search endpoints

* Add sample request/responses

* Add comment to test to indicate expecations

* Fix typo

* Remove trailing slash weirdness
2017-12-05 19:38:16 +00:00
David Meyer fe0cc3b0db config: new "rsadecrypt" interpolation function
The primary use-case is to decrypt windows passwords obtained from AWS, but this function is generic and may find other purposes too.
2017-12-05 11:06:32 -08:00
mizuno 01c1142589 config: new "timeadd" interpolation function 2017-12-05 10:46:12 -08:00
James Bardin 048af6e237 Add test fixture to check for warnings 2017-11-28 14:18:54 -05:00
Martin Atkins cc5e480378 config: detect and warn about access to "counted" attributes
A common pattern is to conditionally assign to "count"
in a resource in order to decide dynamically whether it
should be created. In that situation it's necessary to
refer to attributes of the resource using the splat
syntax, but historically we didn't show errors in output
expressions and so people "got away with" incorrect usage
in that context.

The intent of this warning is to catch
potentially-problematic usage of attributes on such
resources even if the count happens to be currently
set dynamically to 1, which would not generate the
error. Then the user can quickly locate and fix the
incorrect usage regardless of the current value.
2017-11-28 11:15:29 -08:00
Martin Atkins ba0514106a return tfdiags.Diagnostics from validation methods
Validation is the best time to return detailed diagnostics
to the user since we're much more likely to have source
location information, etc than we are in later operations.

This change doesn't actually add any detail to the messages
yet, but it changes the interface so that we can gradually
introduce more detailed diagnostics over time.

While here there are some minor adjustments to some of the
messages to improve their consistency with terminology we
use elsewhere.
2017-11-28 11:15:29 -08:00
James Bardin 8091bd627d move Svchost method to regsrc.Module
The level of abstraction that needs the "svchost" is the Module, not the
FriendlyHost. Us the new method in the module package for registry
interaction.
2017-11-20 18:29:09 -05:00
James Bardin bd576d780a failing test for module not found error
The "not found" error should use the raw string directly from the config
source, but the existing method was adding the default registry if there
was no host indicated.
2017-11-20 17:42:35 -05:00
James Bardin 8619f566bb validate providers passed to a module exist
This validation was lost in the migration of inheritance back to core.
Make sure a module configuraton doesn't specifiy a provider that doesn't
exist.
2017-11-10 11:01:32 -05:00
James Bardin b79adeae02 save resolved providers for resources to state
Use the ResourceState.Provider field to store the full name of the
provider used during apply. This field is only used when a resource is
removed from the config, and will allow that resource to be removed by
the exact same provider with which it was created.

Modify the locations which might accept the alue of the
ResourceState.Provider field to detect that the name is resolved.
2017-11-07 13:09:36 -05:00
James Bardin b15258dfec remove provider inheritance from Tree.Load
Now that resources can be connected to providers with different paths in
the core graph, handling the inheritance in config makes less sense.

Removing this to make room for core to walk the Tree and connect
resources directly to the proper provider instance.
2017-11-06 17:27:45 -05:00
James Bardin 57470f6bf5 remove ProviderConfig Path and Inherited fields
maving all inheritance into core
2017-11-06 17:11:07 -05:00
James Bardin 3297f60d03 remove raw print statements 2017-11-06 17:10:33 -05:00
James Bardin 2ed529f81a update from review
Reference modules by terraform address
Unquote versions
2017-11-03 10:50:19 -04:00
James Bardin c510473fd2 remove code added by stale vim buffer 2017-11-03 10:33:18 -04:00
James Bardin 1bf64ec788 add "Updating" output and fix output tests 2017-11-03 10:28:08 -04:00