Commit Graph

22140 Commits

Author SHA1 Message Date
Martin Atkins 37dfda93ce core: Fix ReferenceTransformer tests
The changes to our GraphNodeReferencable and GraphNodeReferencer
interfaces were not also reflected in our testing structs here, and so
these tests were no longer working.

This updates these implementations to the new required signatures,
adapting the simplified model used in the structs to generate local
variable references, since the reference model no longer uses the
arbitrary strings that this test originally depended on.

We also remove some of the tests here since the functionality they were
testing no longer applies: inter-module dependencies are now handled by
the graph nodes producing extra ReferencableAddrs, and the "backup" form
is no longer used because our new address model is able to distinguish
resources from resource instances without the need for the magical
backup reference forms we previously used.
2018-10-16 18:48:28 -07:00
Martin Atkins a6ca01f49d core: Fix TargetsTransformer tests
Resolution of dependencies automatically from expressions now requires
a schema to be available. To avoid the need to provide mock schemas for
all of these different resource types, we instead use the depends_on
argument here to mark the dependencies explicitly.
2018-10-16 18:48:28 -07:00
Martin Atkins 17d8ec6b6f core: NodeAbstractResource correct default result from ProvidedBy
Previously we had a bug where we'd use the resource type name instead of
the provider name. Now we use the DefaultProviderConfig helper function
to extract the provider name from the resource type name.
2018-10-16 18:48:28 -07:00
Martin Atkins c8f186b303 core: TestTransitiveReductionTransformer needs a schema
The ReferenceTransformer can't do its work here unless our resources have
schema attached, since otherwise it doesn't know which attributes to
search to find references.
2018-10-16 18:48:28 -07:00
Martin Atkins 7188cabdaf core: Testing helpers for building provider schemas
Now that a schema is required to decode resource configuration, a lot more
tests than before need access to mock providers in order to get a schema.
These new helpers allow a mock provider with a schema to be constructed
concisely.
2018-10-16 18:48:28 -07:00
Martin Atkins c58bdc6390 core: fix the tests in variables_test.go
This test required some adaptation for the new variable handling model in
the HCL2-oriented codepaths, where more of the handling is now done in the
"command" package.

The initial reorganization of this test was not correct, so this is a
further revision to adapt the original assertions to the new model as much
as possible, removing a few tests that no longer make sense in the new
world.
2018-10-16 18:48:28 -07:00
Martin Atkins 60ad24229f website: Link from Configuration index to Resource page
Since the index page is long, by the time the reader reaches the end of
it the relevant portion if the navigation is unlikely to be visible. To
compensate for this, we'll link to the first sub-section and thus give
the user an opportunity to notice the navigation structure for the rest
of the pages.
2018-10-16 18:48:28 -07:00
Martin Atkins b2e8987f7e website: Fix references to the now-defunct "Interpolation" page
This has been replaced with an "Expressions" page.

Also includes a number of changes to Markdown style to conform to our
usual conventions, applied automatically by my editor while making these
changes.
2018-10-16 18:48:28 -07:00
Martin Atkins 6549f24d88 website: Remove the "interpolation" docs page
This has now been superseded by the expressions.html.md file in the same
directory. As part of deploying this, the former URL for this page must
be redirected to the expressions page to retain a target for any
existing links on third-party sites.
2018-10-16 18:48:28 -07:00
Martin Atkins c060ecd0a5 website: Document the JSON configuration syntax 2018-10-16 18:47:33 -07:00
Martin Atkins a6749f9efc website: Expand documentation of Override Files
This kinda-weird feature was previously quite severely under-documented in
terms of exactly what effect it has. This new documentation for it first
attempts to frame it as something that should be rarely used, and then
explains in more detail exactly how it behaves for different top-level
block types within the configuration.
2018-10-16 18:47:33 -07:00
Martin Atkins b3239e8f1f website: Update the "Terraform Settings" page for new style
As part of revamping the "Configuration" portion of the website for the
v0.12 release, here we update the Terraform Settings page to use a similar
"guide-like" writing style as the other updated pages in this section.
2018-10-16 18:47:33 -07:00
Martin Atkins d72d9fde16 website: Document the index and attribute syntaxes 2018-10-16 18:47:33 -07:00
Martin Atkins 83a16e3deb website: Docs for all of the IP address calculation functions 2018-10-16 18:47:33 -07:00
Martin Atkins 7cb1de9f30 website: Docs for all of the hash/crypto functions 2018-10-16 18:47:33 -07:00
Martin Atkins 46f8208727 website: Docs for all of the Date and Time functions 2018-10-16 18:47:33 -07:00
Martin Atkins a35c0f3cbf website: Docs for all of the "filesystem" functions 2018-10-16 18:47:33 -07:00
Martin Atkins a491013054 website: Docs for all of the "encoding" functions 2018-10-16 18:47:33 -07:00
Martin Atkins e7d71995f6 website: Document the remaining "collection" functions
This also renames some of the existing function pages whose source
filenames were not matching the usual naming scheme (.html.md).
2018-10-16 18:47:33 -07:00
Martin Atkins c8da3e568f website: Add remaining functions to the functions section sidebar
These links don't lead anywhere yet.
2018-10-16 18:47:33 -07:00
Martin Atkins 48d940323e website: Beginnings of "Functions" configuration section
Previously we just listed out all of the functions in alphabetical order
inside the "Interpolation Syntax" page, but that format doesn't leave much
room for details and usage examples.

Now we give each function its own page, and categorize them for easier
navigation. While many functions are very simple and don't really warrant
a full page, certain functions do have additional details that are worth
mentioning and this structure scales better for those more complicated
functions.

So far this includes only the numeric and string functions. Other
categories will follow in subsequent commits.
2018-10-16 18:47:33 -07:00
Martin Atkins 39579e8d0f website: revisions to the "Configuration Syntax" page and expressions
This rewrite of the "Configuration Syntax" page now gives some more detail
on the top-level structural constructs and de-emphasizes the name "HCL"
as subordinate to "the Terraform language".

It also now includes some commentary on valid identifiers and comments,
and issues around character encodings and line endings.

In addition, we now have a new "Expressions" page that replaces the old
"Interpolation Syntax" page, covering the expression language features
we inherit from HCL and how they behave in the context of Terraform.

The "Expressions" page currently links to a page about the built-in
functions which does not yet exist. This will be created in a later
commit.
2018-10-16 18:47:33 -07:00
Martin Atkins e1754970a8 website: Revise the "Data Sources" configuration docs section
This adopts a more guide-like writing style, similar to what prior commits
have done to some other subsections of this section.

The data sources page has not got any real attention since the feature
was first added, and our vocabulary for describing them and their
lifecycle hadn't quite settled when the page was originally written. This
new version is consistent in how it uses "data source" to describe the
feature that providers offer and "data resource" to describe what is
created by a "data" block in configuration, which then allows us to
draw on the many shared features between both data and managed resources.

For the moment this waits until "data resource" is defined in order to
first introduce the qualifier "managed resource". We may wish to revise
this again to mention that more specific nomenclature in passing on the
"Resources" page, in case a user encounters it elsewhere and wants to
learn what it means without needing to be familiar with data resources
first.
2018-10-16 18:47:33 -07:00
Martin Atkins eeb96b1e12 website: Revise the "Modules" configuration docs section
This adopts a more guide-like writing style, similar to what prior commits
have done to some other subsections of this section.

Since we already have a whole top-level section devoted to modules, there
is no need for full coverage of all of their features here. Instead, this
section focuses on an an initial introduction to what modules are and
the basics of their usage within the Terraform language. We then link
to the main modules section for the full details.
2018-10-16 18:47:33 -07:00
Martin Atkins fdc8bb6c00 website: Revise the "Local Values" configuration docs section
This adopts a more guide-like writing style, similar to what prior commits
have done to some other subsections of this section.
2018-10-16 18:47:33 -07:00
Martin Atkins e41883d972 website: Revise the "Output Values" configuration docs section
This adopts a more guide-like writing style, similar to what prior commits
have done to some other subsections of this section.

In the process of writing this, I identified some unclear statements in
the "Resources" subsection, and so these are also revised here for
consistency with the output values documentation.
2018-10-16 18:47:33 -07:00
Martin Atkins f8f2ff2202 website: Revise the "Input Variables" configuration docs section
This adopts a more guide-like writing style, similar to what prior commits
have done to the Resources and Providers sections.
2018-10-16 18:47:33 -07:00
Martin Atkins a6cf796873 website: Revise the "Providers" configuration docs section
These revisions reflect this sub-section's new earlier placement in the
sub-section list, leading to a more guide-like style for the initial
sections.

Also includes some minor copy-editing to align terminology with that
introduced in the prior commit for the "Resources" docs page.
2018-10-16 18:47:33 -07:00
Martin Atkins 6fa6a0d110 website: revise the "Resources" configuration docs section
This is now the leading subsection of the Configuration section of the
docs, and so this rewrite intends to make it more "guide-like" and as
accessible as possible to those who are not yet familiar with other
Terraform concepts.

This rewrite also attempts to introduce some consistency into our
vocabulary, which should eventually be reflected throughout our
documentation. In particular:

- "Resource" refers to the block the user writes in configuration, while
  "Resource _Type_" refers to what the provider defines. We previously
  used "resource" for both of these interchangeably.

- "Resource" is no longer used to refer to what gets created and managed
  in remote APIs as a result of a resource block in configuration. Lacking
  a good distinct name for these, this guide uses the word "object",
  qualifying it as "infrastructure object" or "remote object" where
  necessary to retain clarity. This distinction is important to enable
  a clear description of resource lifecycle.

- "Argument" refers to an element (attribute or block) within a resource
  block. This terminology was already being used in some places, so we
  embrace it here as a way to distinguish from "attribute", which is
  what a resource _exports_ for use in expressions.

- Since interpolation is no longer needed to use expressions in the
  language, the word "expression" is used to describe the definition of
  a value that might involve some computation. Where necessary, this is
  used with a modifier "arbitrary expression" to contrast with situations
  where the set of allowed expression constructs is constrained.
2018-10-16 18:46:46 -07:00
Martin Atkins 27429b61a9 website: Flesh out the intro to the "Configuration" section.
The prior content on this page was little more than an instruction to
begin navigating the sub-sections of this section.

The new content aims to give a broad overview of some of the language
concepts and a syntax example, in order to create some context to help
the user navigate the subsections more easily.

This also introduces for the first time usage of the term "the Terraform
language". This was previously left un-named, leading to some awkward
sentence constructions elsewhere in the docs. This new name gives us
some specific terminology to use in order to contrast the language that
exists at Terraform's level of abstraction, defining the semantics, from
the underlying grammar provided by HCL.
2018-10-16 18:46:46 -07:00
Martin Atkins e5e3452ffa website: Reorganize the "Configuration" docs section
With the additional configuration language features coming in Terraform
v0.12, our existing documentation structure is beginning to strain.

Here we reorganize the navigation slightly in order to introduce the
concepts in a more appropriate order so that we can reveal complexity
more gradually. Subsequent commits will revise the content of these
pages to better reflect the new sequencing.

The "Environment Variables" page is moved from the Configuration section
into the "Commands" section, since it is not considered a part of the
configuration language and thus more appropriate in the CLI documentation.
The old placement is reflective of the broader purpose that the
"Configuration" section had originally, but its new focus will be on
the Terraform language (.tf files) in particular, with other aspects of
customizing Terraforms behavior covered in other sections.
2018-10-16 18:46:46 -07:00
Martin Atkins b33a970b62 core: fix test fixtures for HCL2 syntax idiom
A number of our test fixtures were previously using the non-idiomatic form
of including a single child attribute all on one line with the block
header and bounding braces.

This non-idiomatic form is an error in HCL2, and hclfmt has always "fixed"
it to the expected form of each attribute being on a line of its own, and
so here we just update all the affected test fixtures to canonical form
(using hclfmt), allowing them to be parsed as intended.

Since the these entire files were processed with hclfmt, there are some
other unrelated style changes included in situations where the file
layouts were non-idiomatic in other ways.
2018-10-16 18:46:46 -07:00
Martin Atkins c82e3ec92f core: even more nil checks to catch missing objects
These are all things that ought to be present in normal use but can end up
being nil in incorrect tests. Test debugging is simpler if these things
return errors gracefully, rather than crashing.
2018-10-16 18:46:46 -07:00
Martin Atkins 26c1584317 core: EvalConfigProvider shouldn't crash if its provider isn't set
While there's no good reason for this to happen in practice, it can arise
in tests if mocks aren't set up quite right, and so we'll catch it and
report it nicely to make test debugging a little easier.
2018-10-16 18:46:46 -07:00
Martin Atkins 7dacb6b6a8 core: Don't crash if EvaluateBlock returns nil during validation
There's actually no good reason for this to happen in the normal case, but
it can happen reasonably easy if a test doesn't properly configure the
MockEvalContext, and so having this check here makes test debugging a
little easier.
2018-10-16 18:46:46 -07:00
Martin Atkins 69d2fa0c15 terraform: fix crasher in TestProcessIgnoreChanges
Since this test case is using t.Run, it must be sure to pass the nested
*testing.T over to the testDiffs function or else calls to t.Fatal will
crash the whole test process, since they would otherwise be called on the
wrong instance of *testing.T.
2018-10-16 18:46:46 -07:00
Martin Atkins 0dd7677d1f core: fail gracefully if provider schemas aren't available
The only reason these cases are arising right now is because we have tests
that haven't yet been updated to properly support schema, but it can't
hurt to add some robustness here to reduce the risk of real crashes.
2018-10-16 18:46:46 -07:00
Martin Atkins 5e8445b7a5 addrs: Resource.String shouldn't ever crash
Previously we had a panic in here for invalid resource modes. While that
does always indicate a programming error, it's frustrating to have a
crasher inside a String method since it often impedes our ability to
report an error properly, since the error reporting itself can crash.

Instead we'll just return an invalid string and hope the caller really is
bailing out with an error message.
2018-10-16 18:46:46 -07:00
Martin Atkins c4fac74371 configs: Fix crasher in provider configuration reference parsing
Due to a logic error, this would panic if given an empty traversal.
2018-10-16 18:46:46 -07:00
Martin Atkins cd584309b9 configs: Fix typo in the deprecation warning about ignore_changes = ["*"] 2018-10-16 18:46:46 -07:00
Martin Atkins 4a21b763aa core: Get tests compiling again
After the refactoring to integrate HCL2 many of the tests were no longer
using correct types, attribute names, etc.

This is a bulk update of all of the tests to make them compile again, with
minimal changes otherwise. Although the tests now compile, many of them
do not yet pass. The tests will be gradually repaired in subsequent
commits, as we continue to complete the refactoring and retrofit work.
2018-10-16 18:46:46 -07:00
Martin Atkins 119c80d5e2 addrs: ModuleInstance methods for building AbsProviderConfig
These helpers, similar to other such methods on ModuleInstance, are useful
for programmatically constructing provider config addresses, particularly
in tests where this is more straightforward than parsing from strings.
2018-10-16 18:46:46 -07:00
Martin Atkins 20f6de735d core: Update MockResourceProvisioner to include GetConfigSchema
This method is now required for the ResourceProvisioner interface.
2018-10-16 18:46:46 -07:00
Martin Atkins f085af4ba6 command: update "terraform console" for HCL2
This now uses the HCL2 parser and evaluator APIs and evaluates in terms
of a new-style *lang.Scope, rather than the old terraform.Interpolator
type that is no longer functional.

The Context.Eval method used here behaves differently than the
Context.Interpolater method used previously: it performs a graph walk
to populate transient values such as input variables, local values, and
output values, and produces its scope in terms of the result of that
graph walk. Because of this, it is a lot more robust than the prior method
when asked to resolve references other than those that are persisted
in the state.
2018-10-16 18:46:46 -07:00
Martin Atkins 73053eb5ef core: Context.Eval method
Some of the objects that are referencable from expressions are transient
values computed only during a graph walk, and not persisted in state. In
order to support arbitrary evaluation of expressions, such as in the
"terraform console" CLI command, it's necessary to be able to evaluate
these values before we start evaluating.

This new Eval method achieves this by performing a special graph walk that
ignores resources (except for dependency resolution) and just focuses on
evaluating all of these transient values, before returning an evaluation
scope that can then resolve expressions in terms of that result.

This replaces the Context.Interpolator method, which was fraught with
various issues due to it not properly priming the state before evaluating.
2018-10-16 18:46:46 -07:00
Martin Atkins 630e3b4be2 core: evaluation for HCL2-flavored reference expressions
Here we replace the stub implementations in evaluationStateData with real
implementations that are based on their equivalents in the old
Interpolator type.

The behavior here is a little different due to the different semantics
expected under HCL2, but the principle remains the same: the main
references are resolved from the state, using config for validation
in order to produce some helpful error messages.
2018-10-16 18:46:46 -07:00
Martin Atkins 25e3ac56d2 core: Wire back in module input variables to the evaluator
I took some missteps here while doing the initial refactor for HCL2 types.
This restores the map of maps that retains all of the variable values, and
then makes it available to the evaluator.
2018-10-16 18:46:46 -07:00
Martin Atkins 4b5868f653 core: BuiltinEvalContext constructs evaluationStateData itself
Previously our evaluationStateData object was constructed inside
Evaluator.Scope, but this was awkward because all of the fields inside it
need to be populated from BuiltinEvalContext fields, and so the signature
of Evaluator.Scope kept growing new arguments over time.

Instead, we reassign the responsibilities here so that Evaluator.Scope
takes an already-constructed lang.Data, and then teach BuiltinEvalContext
to build this object itself from its own internal values.
2018-10-16 18:46:46 -07:00
Martin Atkins b0435cd533 core: ProviderConfigTransformer properly locates parent module
Due to a logic error here we were trying to find our our module's parent
as a descendent of itself, rather than as a descendent of the root. It
turns out that we can do this even more simply by just accessing the
Parent field on the given config, avoiding the need to traverse the tree
down from the root at all.

While here, this also switches to using the path.Call helper method rather
than manually slicing the path array, since this better communicates our
intent.
2018-10-16 18:46:46 -07:00
Martin Atkins b9c4780f07 addrs: Helper methods for converting module calls to absolute modules 2018-10-16 18:46:46 -07:00