terraform/command/testdata
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
..
013upgrade-existing-versions-tf command: Change 0.13upgrade default to versions.tf 2020-05-07 15:45:48 -04:00
013upgrade-explicit-providers command/013upgrade: detect builtin terraform provider (#25215) 2020-06-11 14:10:47 -04:00
013upgrade-file-exists command: Change 0.13upgrade default to versions.tf 2020-05-07 15:45:48 -04:00
013upgrade-implicit-not-found Update language docs URLs in code and tests 2021-01-22 12:22:21 -08:00
013upgrade-implicit-providers command/013upgrade: detect builtin terraform provider (#25215) 2020-06-11 14:10:47 -04:00
013upgrade-multiple-blocks command: Fix 0.13upgrade bug with multiple blocks 2020-05-07 20:11:44 -04:00
013upgrade-multiple-files command: Change 0.13upgrade default to versions.tf 2020-05-07 15:45:48 -04:00
013upgrade-no-providers command: Rework 0.13upgrade sub-command 2020-05-07 11:38:55 -04:00
013upgrade-preserves-comments command: Fix 0.13upgrade to preserve more comments 2020-06-24 15:54:46 -04:00
013upgrade-provider-not-found Update language docs URLs in code and tests 2021-01-22 12:22:21 -08:00
013upgrade-provider-redirect command: Add redirect support to 0.13upgrade 2020-08-31 14:53:35 -04:00
013upgrade-provider-redirect-version-unavailable command: Add redirect support to 0.13upgrade 2020-08-31 14:53:35 -04:00
013upgrade-providers-with-source command: Change 0.13upgrade default to versions.tf 2020-05-07 15:45:48 -04:00
013upgrade-skipped-files command: Change 0.13upgrade default to versions.tf 2020-05-07 15:45:48 -04:00
013upgrade-submodule command: Change 0.13upgrade default to versions.tf 2020-05-07 15:45:48 -04:00
013upgrade-unsupported-version command: Check required_version before upgrading 2020-05-07 15:45:48 -04:00
apply Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-config-invalid Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-destroy-targeted cli: Improve error for invalid -target flags 2021-02-08 13:48:04 -05:00
apply-error Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-input Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-input-partial Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-plan-no-module Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-sensitive-output Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-shutdown Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-targeted cli: Improve error for invalid -target flags 2021-02-08 13:48:04 -05:00
apply-terraform-env Standardise directory name for test data 2019-06-30 10:16:15 +02:00
apply-vars fix command tests 2020-08-07 14:13:57 -04:00
backend-change refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-change-multi-default-to-single refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-change-multi-to-multi refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-change-multi-to-no-default-with-default refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-change-multi-to-no-default-without-default refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-change-multi-to-single refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-change-single-to-single refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-changed-with-legacy refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-from-state command: use backend config from state when backend=false is used. (#23802) 2020-01-07 15:07:06 -05:00
backend-inmem-locked Standardise directory name for test data 2019-06-30 10:16:15 +02:00
backend-new Standardise directory name for test data 2019-06-30 10:16:15 +02:00
backend-new-interp Standardise directory name for test data 2019-06-30 10:16:15 +02:00
backend-new-legacy refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-new-migrate refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-new-migrate-existing refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-plan-backend-empty Standardise directory name for test data 2019-06-30 10:16:15 +02:00
backend-plan-backend-empty-config refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-plan-backend-match refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-plan-backend-mismatch refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-plan-legacy Standardise directory name for test data 2019-06-30 10:16:15 +02:00
backend-plan-legacy-data refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-plan-local Standardise directory name for test data 2019-06-30 10:16:15 +02:00
backend-plan-local-match refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-plan-local-mismatch-lineage refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-plan-local-newer refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-unchanged refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-unchanged-with-legacy refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-unset refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
backend-unset-with-legacy refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
empty Standardise directory name for test data 2019-06-30 10:16:15 +02:00
fmt command: Fix fmt to preserve blank block labels 2020-11-18 11:59:10 -05:00
get Standardise directory name for test data 2019-06-30 10:16:15 +02:00
graph Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-missing-resource-config Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-module-input-variable terraform: Eval module call arguments for import 2020-08-17 17:14:12 -04:00
import-module-var-file reproduction test 2020-06-12 15:39:55 -04:00
import-provider Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-provider-aliased Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-provider-datasource command/import: attach references before validating provider (#22862) 2020-02-12 14:00:08 -05:00
import-provider-implicit Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-provider-invalid command: Fix stale lock when exiting early 2020-02-14 14:48:30 -05:00
import-provider-remote-state Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-provider-var Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-provider-var-default Standardise directory name for test data 2019-06-30 10:16:15 +02:00
import-provider-var-file Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-backend Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-backend-config-file command: Fix backend config override validation 2020-08-21 16:21:13 -04:00
init-backend-config-file-change Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-backend-config-kv Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-backend-empty Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-check-required-version terraform: Fix required version constraint diags 2020-08-18 09:35:32 -04:00
init-get Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-get-provider-detected-legacy command/init: Improve diags for legacy providers 2020-06-12 09:57:01 -04:00
init-get-provider-invalid-package command/init: Display provider validation errors 2020-07-07 15:20:20 -04:00
init-get-provider-legacy-from-state command: Better in-house provider install errors 2020-09-01 14:02:19 -04:00
init-get-provider-source command/init: Use full config for provider reqs 2020-05-25 16:50:12 -04:00
init-get-providers vendor: go get github.com/apparentlymart/go-versions@v1.0.0 2020-06-12 08:45:14 -07:00
init-internal Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-internal-invalid internal/providercache: Handle built-in providers 2020-04-06 09:24:23 -07:00
init-legacy-provider-cache command: new cache directory .terraform/providers for providers 2020-10-14 07:53:41 -07:00
init-legacy-rc Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-provider-lock-file Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-providers-lock Standardise directory name for test data 2019-06-30 10:16:15 +02:00
init-required-providers provider source tests: added test suite to exercise hyphenated providers (#24685) 2020-04-16 15:54:33 -04:00
inmem-backend Standardise directory name for test data 2019-06-30 10:16:15 +02:00
login-oauth-server command: Fix OAuth2 PKCE arguments 2020-05-05 09:58:48 -07:00
login-tfe-server Add token validation for manual terraform login 2020-02-04 17:24:25 -05:00
modules Support reading module outputs in terraform console (#24808) 2020-04-30 09:21:42 -04:00
parallelism Standardise directory name for test data 2019-06-30 10:16:15 +02:00
plan Standardise directory name for test data 2019-06-30 10:16:15 +02:00
plan-emptydiff Standardise directory name for test data 2019-06-30 10:16:15 +02:00
plan-invalid Standardise directory name for test data 2019-06-30 10:16:15 +02:00
plan-out-backend Standardise directory name for test data 2019-06-30 10:16:15 +02:00
plan-out-backend-legacy Standardise directory name for test data 2019-06-30 10:16:15 +02:00
plan-vars Standardise directory name for test data 2019-06-30 10:16:15 +02:00
providers command/providers: Show provider requirements tree 2020-06-09 14:21:53 -04:00
providers-schema command: Providers schema shows required_providers 2020-09-22 10:28:32 -04:00
push Standardise directory name for test data 2019-06-30 10:16:15 +02:00
push-backend-new Standardise directory name for test data 2019-06-30 10:16:15 +02:00
push-input Standardise directory name for test data 2019-06-30 10:16:15 +02:00
push-input-partial Standardise directory name for test data 2019-06-30 10:16:15 +02:00
push-no-remote Standardise directory name for test data 2019-06-30 10:16:15 +02:00
push-no-upload Standardise directory name for test data 2019-06-30 10:16:15 +02:00
push-tfvars Standardise directory name for test data 2019-06-30 10:16:15 +02:00
refresh Standardise directory name for test data 2019-06-30 10:16:15 +02:00
refresh-empty Standardise directory name for test data 2019-06-30 10:16:15 +02:00
refresh-output Standardise directory name for test data 2019-06-30 10:16:15 +02:00
refresh-targeted cli: Improve error for invalid -target flags 2021-02-08 13:48:04 -05:00
refresh-unset-var Standardise directory name for test data 2019-06-30 10:16:15 +02:00
refresh-var Standardise directory name for test data 2019-06-30 10:16:15 +02:00
show Standardise directory name for test data 2019-06-30 10:16:15 +02:00
show-json update new outputs plan json 2020-10-12 17:29:45 -04:00
show-json-state Unmark values before showing in JSON 2020-10-28 15:30:04 -04:00
state-list-backend-custom addrs: embed Provider in AbsProviderConfig instead of Type 2020-02-13 15:32:58 -05:00
state-list-backend-default addrs: embed Provider in AbsProviderConfig instead of Type 2020-02-13 15:32:58 -05:00
state-list-nested-modules command/state list: list resources in nested and expanded modules (#27268) 2020-12-14 11:07:15 -05:00
state-pull-backend Standardise directory name for test data 2019-06-30 10:16:15 +02:00
state-push-bad-lineage refactor tests to use modern states.State in favor of terraform.State where possible 2020-09-30 16:07:54 -04:00
state-push-good Standardise directory name for test data 2019-06-30 10:16:15 +02:00
state-push-replace-match Standardise directory name for test data 2019-06-30 10:16:15 +02:00
state-push-serial-newer addrs: embed Provider in AbsProviderConfig instead of Type 2020-02-13 15:32:58 -05:00
state-push-serial-older Standardise directory name for test data 2019-06-30 10:16:15 +02:00
taint-check-required-version command: Taint should respect required_version 2020-09-22 17:33:09 -04:00
validate-invalid command: Add tests for terraform validate -json 2020-12-11 13:09:25 -05:00
validate-valid command: Add tests for terraform validate -json 2020-12-11 13:09:25 -05:00
variables Remove sensitive_variables experiment 2020-10-08 11:22:20 -04:00
empty-file Standardise directory name for test data 2019-06-30 10:16:15 +02:00
statelocker.go state: remove deprecated state package (#25490) 2020-08-11 11:43:01 -04:00