Commit Graph

1370 Commits

Author SHA1 Message Date
Alisdair McDiarmid 7ff58780d4 Remove unnecessary type assertion checks
The type assertion checks on the credentials source are unnecessary, and
the alternative code path they allow would panic.
2020-02-06 15:30:49 -05:00
Alisdair McDiarmid 325f8a84f8 command/logout: Exit early if already logged out 2020-02-06 15:00:55 -05:00
Alisdair McDiarmid 081f02971d command/logout: Add terraform logout command
Use terraform logout to remove stored credentials for a remote service
host.
2020-02-06 15:00:55 -05:00
Alisdair McDiarmid e57685d8fc
Merge pull request #24030 from hashicorp/alisdair/terraform-login-token-validation
Add token validation for manual terraform login
2020-02-05 10:07:28 -05:00
Kristin Laemmert 7eed30595a
moduledeps: replace ProviderInstance with addrs.Provider (#24017)
* addrs: add ParseProviderSourceString function to parse fqns from
tfconfig-inspect
* moduledeps: use addrs.Provider instead of ProviderInstance
2020-02-05 09:27:32 -05:00
Alisdair McDiarmid c77cfaafc2 Add token validation for manual terraform login
When a token is pasted by the user, we make a request to the
TFE API /account/details endpoint to verify its validity. If successful,
we display the logged-in username as confirmation. If not, we refuse to
store the invalid token and display an error message.

This commit also trims whitespace from around the pasted value, to
reduce the likelihood of a copy & paste error.
2020-02-04 17:24:25 -05:00
Kristin Laemmert 927999a820
command/state show: use configured provider (#24027)
The `state show`  command was not checking if a given resource had a
configured provider, and instead was only using the default provider
config. This PR checks for a configured provider, using the default
provider if one is not set.

Fixes #22010
2020-02-04 12:07:59 -05:00
Alisdair McDiarmid f34cba407f
Merge pull request #23995 from hashicorp/alisdair/terraform-login
Enable login subcommand, add manual token support
2020-02-04 11:28:27 -05:00
Kristin Laemmert 80ab551867
terraform: use addrs.Provider as map keys for provider schemas (#24002)
This is a stepping-stone PR for the provider source project. In this PR
"legcay-stype" FQNs are created from the provider name string. Future
work involves encoding the FQN directly in the AbsProviderConfig and
removing the calls to addrs.NewLegacyProvider().
2020-02-03 08:18:04 -05:00
Martin Atkins 8b511524d6
Initial steps towards AbsProviderConfig/LocalProviderConfig separation (#23978)
* Introduce "Local" terminology for non-absolute provider config addresses

In a future change AbsProviderConfig and LocalProviderConfig are going to
become two entirely distinct types, rather than Abs embedding Local as
written here. This naming change is in preparation for that subsequent
work, which will also include introducing a new "ProviderConfig" type
that is an interface that AbsProviderConfig and LocalProviderConfig both
implement.

This is intended to be largely just a naming change to get started, so
we can deal with all of the messy renaming. However, this did also require
a slight change in modeling where the Resource.DefaultProviderConfig
method has become Resource.DefaultProvider returning a Provider address
directly, because this method doesn't have enough information to construct
a true and accurate LocalProviderConfig -- it would need to refer to the
configuration to know what this module is calling the provider it has
selected.

In order to leave a trail to follow for subsequent work, all of the
changes here are intended to ensure that remaining work will become
obvious via compile-time errors when all of the following changes happen:
- The concept of "legacy" provider addresses is removed from the addrs
  package, including removing addrs.NewLegacyProvider and
  addrs.Provider.LegacyString.
- addrs.AbsProviderConfig stops having addrs.LocalProviderConfig embedded
  in it and has an addrs.Provider and a string alias directly instead.
- The provider-schema-handling parts of Terraform core are updated to
  work with addrs.Provider to identify providers, rather than legacy
  strings.

In particular, there are still several codepaths here making legacy
provider address assumptions (in order to limit the scope of this change)
but I've made sure each one is doing something that relies on at least
one of the above changes not having been made yet.

* addrs: ProviderConfig interface

In a (very) few special situations in the main "terraform" package we need
to make runtime decisions about whether a provider config is absolute
or local.

We currently do that by exploiting the fact that AbsProviderConfig has
LocalProviderConfig nested inside of it and so in the local case we can
just ignore the wrapping AbsProviderConfig and use the embedded value.

In a future change we'll be moving away from that embedding and making
these two types distinct in order to represent that mapping between them
requires consulting a lookup table in the configuration, and so here we
introduce a new interface type ProviderConfig that can represent either
AbsProviderConfig or LocalProviderConfig decided dynamically at runtime.

This also includes the Config.ResolveAbsProviderAddr method that will
eventually be responsible for that local-to-absolute translation, so
that callers with access to the configuration can normalize to an
addrs.AbsProviderConfig given a non-nil addrs.ProviderConfig. That's
currently unused because existing callers are still relying on the
simplistic structural transform, but we'll switch them over in a later
commit.

* rename LocalType to LocalName

Co-authored-by: Kristin Laemmert <mildwonkey@users.noreply.github.com>
2020-01-31 08:23:07 -05:00
Alisdair McDiarmid b75201acc2 Enable login subcommand, add manual token support 2020-01-30 09:55:38 -05:00
Kristin Laemmert 6541775ce4
addrs: roll back change to Type field in ProviderConfig (#23937) 2020-01-28 08:13:30 -05:00
Martin Atkins e9d0822b2a command: Accept a "provider source" from the main package
Following the same approach we use for other CLI-Config-able objects like
the service discovery system, the main package is responsible for
producing a suitable implementation of this interface which the command
package can then use.

When unit testing in the command package we can then substitute mocks as
necessary, following the dependency inversion principle.
2020-01-24 13:45:37 -08:00
Kristin Laemmert 92f427779d
command/show: fix issue with show and aliased provider (#23848)
The formatter in `command/format/state.go`, when formatting a resource
with an aliased provider, was looking for a schema with the alias (ie,
test.foo), but the schemas are only listed by provider type (test).
Update the state formatter to lookup schemas by provider type only.

Some of the show tests (and a couple others) were not properly cleaning
up the created tmpdirs, so I fixed those. Also, the show tests are using
a statefile named `state.tfstate`, but were not passing that path to the
show command, so we were getting some false positives (a `show` command
that returns `no state` exits 0).

Fixes #21462
2020-01-13 15:10:00 -05:00
Kristin Laemmert 18dd1bb4d6
Mildwonkey/tfconfig upgrade (#23670)
* deps: bump terraform-config-inspect library
* configs: parse `version` in new required_providers block

With the latest version of `terraform-config-inspect`, the
required_providers attribute can now be a string or an object with
attributes "source" and "version". This change allows parsing the
version constraint from the new object while ignoring any given source attribute.
2020-01-10 11:54:53 -05:00
Pam Selle cd6c93774a Update docs to reflect current behavior 2020-01-08 16:51:42 -05:00
Kristin Laemmert 4d8fde3d6f
command: use backend config from state when backend=false is used. (#23802)
* command: use backend config from state when backend=false is used.

When a user runs `terraform init --backend=false`, terraform should
inspect the state for a previously-configured backend, and use that
backend, ignoring any backend config in the current configuration. If no
backend is configured or there is no state, return a local backend.

Fixes #16593
2020-01-07 15:07:06 -05:00
James Bardin 98c02ac114 remove stale dependencies on `state mv`
Clear any Dependencies if there is an entry matching a `state mv` from
address. While stale dependencies won't directly effect any current
operations, clearing the list will allow them to be recreated in their
entirety during refresh. This will help future releases that may rely
solely on the pre-calculated dependencies for destruction ordering.
2020-01-06 15:06:41 -05:00
Pam Selle d2fc7aad87
Merge pull request #23268 from rajata07/master
small fix with command usage 'terraform workspace New'
2019-12-17 07:37:20 -05:00
Kristin Laemmert 49fc53d1d1
provider source enhancements
* configs: move ProviderConfigCompact[Str] from addrs to configs

The configs package is aware of provider name and type (which are the
same thing today, but expected to be two different things in a future
release), and should be the source of truth for a provider config
address. This is an intermediate step; the next step will change the returned types to something based in the configs package.

* command: rename choosePlugins to chooseProviders to clarify scope of function

* use `Provider.LegacyString()` (instead of `Provider.Type`) consistently
* explicitly create legacy-style provider (continuing from above change)
2019-12-11 08:35:55 -05:00
Martin Atkins c06675c616 command: New -compact-warnings option
When warnings appear in isolation (not accompanied by an error) it's
reasonable to want to defer resolving them for a while because they are
not actually blocking immediate work.

However, our warning messages tend to be long by default in order to
include all of the necessary context to understand the implications of
the warning, and that can make them overwhelming when combined with other
output.

As a compromise, this adds a new CLI option -compact-warnings which is
supported for all the main operation commands and which uses a more
compact format to print out warnings as long as they aren't also
accompanied by errors.

The default remains unchanged except that the threshold for consolidating
warning messages is reduced to one so that we'll now only show one of
each distinct warning summary.

Full warning messages are always shown if there's at least one error
included in the diagnostic set too, because in that case the warning
message could contain additional context to help understand the error.
2019-12-10 11:53:14 -08:00
Kristin Laemmert f8a23da480 explicitly create legacy-style provider 2019-12-09 15:17:47 -05:00
Kristin Laemmert 86e450a85f use LegacyString() consistently 2019-12-09 11:34:36 -05:00
Kristin Laemmert efafadbe5e command: rename choosePlugins to chooseProviders to clarify scope of function 2019-12-09 09:47:09 -05:00
Kristin Laemmert 67fc4dd5a1 configs: move ProviderConfigCompact[Str] from addrs to configs
The configs package is aware of provider name and type (which are the
same thing today, but expected to be two different things in a future
release), and should be the source of truth for a provider config
address.
2019-12-09 08:30:08 -05:00
James Bardin f281eb2b44
Merge pull request #23595 from hashicorp/jbardin/deprecate-destroy-references
Update destroy provisioner warnings
2019-12-06 12:31:20 -05:00
Pam Selle d8c31a1efa
Merge pull request #23581 from hashicorp/pselle/show-panic-23377
Fix panic on show plan
2019-12-06 12:08:16 -05:00
Pam Selle 9c4d3cc1b1 Add a test 2019-12-06 11:53:43 -05:00
James Bardin 42a2bb4da3 expand test tempdir symlinks to fix tests on macos 2019-12-06 10:56:47 -05:00
James Bardin 96d1e57191 fix type in state mv test 2019-12-06 10:52:14 -05:00
James Bardin b715ef2590 don't print just warnings when loading backend cfg
Any warnings will be caught again when the entire config is loaded, and
duplicated in the output.
2019-12-06 10:20:23 -05:00
Kristin Laemmert e3416124cc
addrs: replace "Type string" with "Type Provider" in ProviderConfig
* huge change to weave new addrs.Provider into addrs.ProviderConfig
* terraform: do not include an empty string in the returned Providers /
Provisioners
- Fixed a minor bug where results included an extra empty string
2019-12-06 08:00:18 -05:00
James Bardin 4896052736
Merge pull request #23582 from hashicorp/jbardin/state-mv
Allow moving instances to new resources
2019-12-05 18:06:04 -05:00
Aaron Heesakkers 3dfeb67708 command/internal-plugin: Strip off TF_CLI_ARGS arguments
These are not meaningful for the `internal-plugin` subcommand, which is for internal use only.
2019-12-05 15:00:51 -08:00
James Bardin a5cb36b34c Allow moving instances to new resources
If a state mv target happens to be a resource that doesn't exist, allow
the creation of the new resource inferring the EachMode from the target
address.
2019-12-05 17:38:52 -05:00
Pam Selle 2b8e876bdb Don't inspect an empty set, return false 2019-12-05 16:00:19 -05:00
Pam Selle ba9cb786c3
Merge pull request #23546 from tmshn/dry-plan-color
make plan-diff format a bit more dry
2019-12-04 17:24:27 -05:00
Kristin Laemmert 9891d0354a
providers: use addrs.Provider as map keys for provider.Factory (#23548)
* terraform/context: use new addrs.Provider as map key in provider factories
* added NewLegacyProviderType and LegacyString funcs to make it explicit that these are temporary placeholders

This PR introduces a new concept, provider fully-qualified name (FQN), encapsulated by the `addrs.Provider` struct.
2019-12-04 11:30:20 -05:00
tmshn fcc1a76d5e make plan-diff format a bit more dry 2019-12-03 19:02:59 +09:00
Kristin Laemmert 6728e521c1
addrs: rename Provider Name to more accurate Provider Type (#23449) 2019-12-02 15:32:31 -05:00
Kristin Laemmert 99225b8d76
command/jsonstate,plan: fix panic with null values (#23492)
The code responsible for marshalling attribute values was checking for
nil values, but not null.

Fixes #23485, #23274
2019-11-25 15:01:38 -05:00
Martin Atkins 7081c26e54 command: Don't show more than two of the same warning
Some of our warnings are produced in response to particular configuration
constructs which might appear many times across a Terraform configuration.
To avoid the warning output dwarfing all of the other output, we'll use
ConsolidateWarnings to limit each distinct warning summary to appear at
most twice, and annotate the final one in the sequence with an additional
paragraph noting that some number of them have been hidden.

This is intended as a compromise to ensure that these warnings are still
seen and noted but to help ensure that we won't produce so many of them
as to distract from other output that appears alongside them.

This applies only to warnings relating to specific configuration ranges;
errors will continue to be shown individually, and sourceless warnings
(which are rare in Terraform today) will likewise remain ungrouped because
they are less likely to be repeating the same statement about different
instances of the same problem throughout the configuration.
2019-11-19 15:36:08 -08:00
Simon Brady 7a9fa93724 command/plan: Fix panic in plan output with string containing null and whitespace (#23102)
* command/plan: Fix panic in plan output with string containing null and whitespace
* command/format: add test for null string with whitespace
2019-11-15 10:25:49 -05:00
Martin Atkins d0f50ff83f command: Don't treat config warnings as errors
Meta.backendConfig was incorrectly treating the second return value from
loadBackendConfig as if it were go "error" rather than
tfdiags.Diagnostics, which in turn meant that it would treat warnings like
errors.

This had confusing results because it still returned that
tfdiags.Diagnostics value in its own diagnostics return value, causing the
caller to see warnings even though the backendConfig function had taken
the error codepath.
2019-11-14 14:50:51 -08:00
Ethan 6833ac290b command: Use full URL for the download page when prompting for upgrade
This makes it more likely that a terminal emulator will detect the URL as a clickable link.
2019-11-08 16:10:39 -08:00
Thayne McCombs a895a42f85 command/format: fix missing elements at the end of lists in diffs 2019-11-08 16:05:23 -08:00
James Bardin bee703360c
Merge pull request #23252 from hashicorp/jbardin/abs-state-dependencies
store absolute addresses for resource dependencies in the state
2019-11-08 10:25:32 -05:00
Martin Atkins 7db2825646 command/format: multi-line rendering for unchanged strings
We have a special treatment for multi-line strings that are being updated
in-place where we show them across multiple lines in the plan output, but
we didn't use that same treatment for rendering multi-line strings in
isolation such as when they are being added for the first time.

Here we detect when we're rendering a multi-line string in a no-change
situation and render it using the diff renderer instead, using the same
value for old and new and thus producing a multi-line result without any
diff markers at all.

This improves consistency between the change and no-change cases, and
makes multi-line strings (such as YAML in block mode) readable in all
cases.
2019-11-07 15:25:40 -08:00
James Bardin 46dbb3dde5 use Dependencies to connect creator and destroyer
The DestroyEdgeTransformer cannot determine ordering from the graph when
the destroyers are from orphaned resources, because there are no
references to resolve. The new stored Dependencies provides what we need
to connect the instances in this case.

We also add the StateDependencies method directly in the
GraphNodeResourceInstance interface, since all instances already
implement this, and we don't need another optional interface to check.

The old code in DestroyEdgeTransformer may no longer be needed in the
long run, but that can be determined separately, since too many of the
tests start with an incomplete state and rely on the Dependencies being
determined from the configuration alone.
2019-11-07 17:49:03 -05:00
James Bardin 886af20f07 fixup some test comparisons 2019-11-07 17:49:03 -05:00