Commit Graph

27796 Commits

Author SHA1 Message Date
Martin Atkins f91a3b87c1 terminal: Helpers for doing fmt-ish operations on the streams
It's pretty common to want to apply the various fmt.Fprint... functions
to our two output streams, and so to make that much less noisy at the
callsite here we have a small number of very thin wrappers around the
underlying fmt package functionality.

Although we're aiming to not have too much abstraction in this "terminal"
package, this seems justified in that it is only a very thin wrapper
around functionality that most Go programmers are already familiar with,
and so the risk of this causing any surprises is low and the improvement
to readability of callers seems worth it.
2021-02-12 11:24:13 -08:00
James Bardin 6f26203ae4 update CHANGELOG.md 2021-02-12 12:14:04 -05:00
Alisdair McDiarmid 6f58037d6a
Merge pull request #27738 from hashicorp/alisdair/command-views
cli: Add initial command views abstraction
2021-02-12 10:14:54 -05:00
Alisdair McDiarmid 57879bfb71 cli: Add global view arguments parser
Rather than modifying and relying on the existing Meta.process
argument extractor, we can more clearly handle global CLI flags using
a separate parser step. This allows us to explicitly configure the view
in the command.
2021-02-12 09:56:02 -05:00
James Bardin 4e12ba3d75
Merge pull request #27739 from hashicorp/jbardin/provider-aliases
Provider configuration_aliases and module validation
2021-02-11 17:49:27 -05:00
James Bardin 4195531925 old comment 2021-02-11 17:39:51 -05:00
Alisdair McDiarmid c5a6aa31d3 cli: Add initial command views abstraction
Terraform supports multiple output formats for several sub-commands.
The default format is user-readable text, but many sub-commands support
a `-json` flag to output a machine-readable format for the result. The
output command also supports a `-raw` flag for a simpler, scripting-
focused machine readable format.

This commit adds a "views" abstraction, intended to help ensure
consistency between the various output formats. This extracts the render
specific code from the command package, and moves it into a views
package. Each command is expected to create an interface for its view,
and one or more implementations of that interface.

By doing so, we separate the concerns of generating the sub-command
result from rendering the result in the specified output format. This
should make it easier to ensure that all output formats will be updated
together when changes occur in the result-generating phase.

There are some other consequences of this restructuring:

- Views now directly access the terminal streams, rather than the
  now-redundant cli.Ui instance;
- With the reorganization of commands, parsing CLI arguments is now the
  responsibility of a separate "arguments" package.

For now, views are added only for the output sub-command, as an example.
Because this command uses code which is shared with the apply and
refresh commands, those are also partially updated.
2021-02-11 15:06:39 -05:00
Alisdair McDiarmid 04e512d2f9
Merge pull request #27746 from hashicorp/alisdair/optimize-large-multi-line-string-outputs
cli: Optimize for large multi-line string outputs
2021-02-11 12:53:12 -05:00
Alisdair McDiarmid 943df48491 cli: Optimize for large multi-line string outputs 2021-02-11 10:42:06 -05:00
James Bardin 00730aed0b basic configuration_aliases support in core 2021-02-11 10:22:18 -05:00
James Bardin 9b11ff0358 remove outdated tests
These cases are now caught early in the configuration loading process,
and do not make it to the point of graph transformation.
2021-02-11 10:22:18 -05:00
James Bardin da252de1a0 add provider validation
Add validation which was removed from the configload package, along with
additional validation checks. The output is slightly different, as
instead of validating whether the modules are allowed to have provider
configurations, we validate the various combinations of provider
structures themselves.
2021-02-11 10:22:18 -05:00
Omar Ismail 14936e6550
Merge pull request #27735 from omarismail/cost-estimation-output
Cost Estimation CLI output unnecessary
2021-02-11 08:20:34 -05:00
Omar Ismail 4ac095b63f only print horizontal rule at first attempt 2021-02-10 20:47:50 -05:00
Martin Atkins ffba8064ed terminal: StreamsForTesting helper
This is to allow convenient testing of functions that are designed to work
directly with *terminal.Streams or the individual stream objects inside.

Because the InputStream and OutputStream APIs expose directly an *os.File,
this does some extra work to set up OS-level pipes so we can capture the
output into local buffers to make test assertions against. The idea here
is to keep the tricky stuff we need for testing confined to the test
codepaths, so that the "real" codepaths don't end up needing to work
around abstractions that are otherwise unnecessary.
2021-02-10 11:51:56 -08:00
hashicorp-ci 7720d4a395 Cleanup after v0.15.0-alpha20210210 release 2021-02-10 18:00:31 +00:00
hashicorp-ci d631eca23c
Release v0.15.0-alpha20210210 2021-02-10 17:40:24 +00:00
Omar Ismail d96c90b6af Cost Estimation CLI output unnecessary 2021-02-10 11:17:05 -05:00
James Bardin 7aaffac223 configload should not be doing validation
The configload package should only be responsible for locating and
loading the configuration, and not be further inspecting the config
source itself. Moving the validating into the configs package.
2021-02-10 10:20:40 -05:00
Pam Selle 0a99757ecf
Merge pull request #27722 from hashicorp/pselle/init-installed
Emit ProviderAlreadyInstalled when provider installed
2021-02-10 10:02:21 -05:00
Pam Selle f97f8c2a9b
Merge pull request #27708 from philipsahli/patch-1
Fix typo
2021-02-09 11:14:16 -05:00
Pam Selle aa24bfec47 Emit ProviderAlreadyInstalled when provider installed
Emit the ProviderAlreadyInstalled event when we successfully verify
that we've already installed this provider and are skipping
installation
2021-02-09 11:08:49 -05:00
Alisdair McDiarmid 96be094ecd
Merge pull request #27711 from hashicorp/alisdair/fix-target-flag-parsing-and-add-tests
cli: Improve error for invalid -target flags
2021-02-09 09:15:02 -05:00
James Bardin ac585be079 initial support for parsing configuration_aliases
Add support for parsing configuration_aliases in required_providers
entries. The decoder needed to be re-written here in order to support
the bare reference style usage of provider names so that they match the
usage in other location within configuration. The only change to
existing handling of the required_providers block is more precise error
locations in a couple cases.
2021-02-09 08:38:30 -05:00
James Bardin a033598224 update hcl and terraform-config-inspect 2021-02-09 08:37:59 -05:00
Alisdair McDiarmid 4991cc4835 cli: Improve error for invalid -target flags
Errors encountered when parsing flags for apply, plan, and refresh were
being suppressed. This resulted in a generic usage error when using an
invalid `-target` flag.

This commit makes several changes to address this. First, these commands
now output the flag parse error before exiting, leaving at least some
hint about the error. You can verify this manually with something like:

    terraform apply -invalid-flag

We also change how target attributes are parsed, moving the
responsibility from the flags instance to the command. This allows us to
customize the diagnostic output to be more user friendly. The
diagnostics now look like:

```shellsession
$ terraform apply -no-color -target=foo

Error: Invalid target "foo"

Resource specification must include a resource type and name.
```

Finally, we add test coverage for both parsing of target flags, and at
the command level for successful use of resource targeting. These tests
focus on the UI output (via the change summary and refresh logs), as the
functionality of targeting is covered by the context tests in the
terraform package.
2021-02-08 13:48:04 -05:00
Stephen e39abbf6f0
fix regex logical or documentation (#27637)
* fix regex logical or documentation

Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2021-02-08 11:04:38 -05:00
Philip Sahli d7cbf8f1fc
Fix typo 2021-02-08 16:56:19 +01:00
Alisdair McDiarmid 32d2084387
Merge pull request #27679 from hashicorp/alisdair/apply-destroy-test-fixes
cli: Better diagnostics for apply positional args
2021-02-05 13:05:19 -05:00
Robin Norwood f279bf58c4
Merge pull request #27689 from hashicorp/rln-data-sources-tutorial
Add crosslink to new Learn tutorial
2021-02-05 09:44:33 -06:00
Robin Norwood 181048b913 Add crosslink to new Learn tutorial 2021-02-04 13:43:03 -06:00
Alisdair McDiarmid d7613a0aac cli: Better diagnostics for apply positional args
The previous changes removing support for using the trailing positional
argument as a working directory missed a spot in the apply/destroy
command implementation. We still support this argument for applying a
saved plan:

    terraform apply foo.tfplan

However, if you pass a positional path which doesn't "look like" a plan
(for example, the path to a configuration directory), Terraform would
silently ignore it and continue.

This commit fixes that by adding an error message if the user specifies
a path which the plan loader rejects as not "looking like" a plan. This
message includes a reference to the `-chdir` flag as a pointer about
what to do next.

We also rearrange the error message when calling `terraform destroy`
with a plan file argument, and add test coverage for the above. While
we're here, update the destroy tests to copy the fixture directory,
chdir, and defer cleanup.
2021-02-04 10:27:18 -05:00
Alisdair McDiarmid 8057f19bb5
Update CHANGELOG.md 2021-02-04 10:16:31 -05:00
Alisdair McDiarmid 294bbd8b8c
Merge pull request #27681 from hashicorp/alisdair/remove-deprecated-destroy-force
cli: Remove deprecated destroy -force flag
2021-02-04 10:15:07 -05:00
Alisdair McDiarmid b2ba650c21 cli: Remove deprecated destroy -force flag
This dramatically simplifies the logic around auto-approve, which is
nice.

Also add test coverage for the manual approve step, for both apply and
destroy, answering both yes and no.
2021-02-03 15:05:05 -05:00
James Bardin 030632e87e
Merge pull request #27668 from hashicorp/jbardin/parallelism-test
fix concurrent test relying on sleep
2021-02-03 09:39:42 -05:00
James Bardin 1e5a8e4dae fix concurrent test relying on sleep
Make an old concurrent test deterministic, and not rely on sleep for any
synchronization.
2021-02-03 09:20:08 -05:00
Alisdair McDiarmid c8f83e184b
Update CHANGELOG.md 2021-02-02 13:55:49 -05:00
Alisdair McDiarmid a51803ae0b
Merge pull request #27664 from hashicorp/alisdair/remove-positional-path-arguments
cli: Remove legacy positional path arguments
2021-02-02 13:50:58 -05:00
Pam Selle 84f5b863ef
Merge pull request #27635 from hashicorp/pselle/obj-compatible-set
Unmark values in couldHaveUnknownBlockPlaceholder before iteration
2021-02-02 13:44:49 -05:00
Alisdair McDiarmid 888f36aebb cli: Remove positional plan argument from graph
To make the command arguments easier to understand and extend, we are
moving away from positional arguments. This commit changes the graph
command to take a `-plan` flag instead of an optional trailing path.
2021-02-02 13:21:26 -05:00
Alisdair McDiarmid ca23a096d8 cli: Remove legacy positional path arguments
Several commands continued to support the legacy positional path
argument to specify a working directory. This functionality has been
replaced with the global -chdir flag, which is specified before any
other arguments, including the sub-command name.

This commit removes support for the trailing path parameter from
most commands. The only command which still supports a path argument is
fmt, which also supports "-" to indicate receiving configuration from
standard input.

Any invocation of a command with an invalid trailing path parameter will
result in a short error message, pointing at the -chdir alternative.

There are many test updates in this commit, almost all of which are
migrations from using positional arguments to specify a working
directory. Because of the layer at which these tests run, we are unable
to use the -chdir argument, so the churn in test files is larger than
ideal. Sorry!
2021-02-02 13:21:26 -05:00
James Bardin 9c16e5726e
Merge pull request #27620 from hashicorp/v-aws-sdk-go-v1.37.0
deps: Bump github.com/aws/aws-sdk-go@v1.37.0
2021-02-02 08:20:44 -05:00
Brian Flad 70aac9c551
command: Use different warning messaging in init command and move above potentially confusing output (#27514)
Reference: https://github.com/hashicorp/terraform/issues/27459
Reference: https://github.com/hashicorp/terraform/pull/27507

This follows the change in the plan command to move the development overrides warning above other output from the command that may exhibit unexpected behavior.
2021-02-01 10:50:08 -05:00
James Bardin cf09435526 update CHANGELOG.md 2021-02-01 09:37:52 -05:00
Pam Selle e6daf3dbf1 Unmark before ElementIterator in couldHaveUnknownBlockPlaceholder
This is needed for cases where a variable may be fetched and become
a member of a set, and thus the whole set is marked, which means
ElementIterator will panic on unmarked values
2021-01-29 17:06:12 -05:00
Alisdair McDiarmid 5df11f2013
Merge pull request #27633 from hashicorp/alisdair/count-hook-refactor
cli: Move resource count code to command package
2021-01-29 15:49:34 -05:00
Alisdair McDiarmid 5ca118b4e6 cli: Move resource count code to command package
CountHook is an implementation of terraform.Hook which is used to
calculate how many resources were added, changed, or destroyed during an
apply. This hook was previously injected in the local backend code,
which means that the apply command code has no access to these counts.

This commit moves the CountHook code into the command package, and
removes an unused instance of the hook in the plan code path. The goal
here is moving UI code into the command package.
2021-01-29 15:29:35 -05:00
James Bardin bd70df8392
Merge pull request #27621 from hashicorp/jbardin/plan-orphan-data-instance
removed orphaned data sources from the working state
2021-01-29 08:39:04 -05:00
James Bardin 2df2d210b4 removed orphaned data sources from the state
When evaluating orphaned data sources during plan, they need to be
removed from both the refresh state and the current working state.
2021-01-28 16:35:21 -05:00