Commit Graph

972 Commits

Author SHA1 Message Date
Brian Flad
0b404f4a95 Return early on GetProviderSchema RPC responses with error diagnostics
Reference: https://github.com/hashicorp/terraform/issues/31047

Prevent potential panics and immediately return provider-defined errors diagnostics.

Previously:

```
--- FAIL: TestGRPCProvider_GetSchema_ResponseErrorDiagnostic (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x17fa752]

goroutine 13 [running]:
testing.tRunner.func1.2({0x191a100, 0x2236330})
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1392 +0x39f
panic({0x191a100, 0x2236330})
	/usr/local/Cellar/go/1.18.2/libexec/src/runtime/panic.go:838 +0x207
github.com/hashicorp/terraform/internal/plugin6/convert.ProtoToConfigSchema(0x0)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin6/convert/schema.go:110 +0x52
github.com/hashicorp/terraform/internal/plugin6/convert.ProtoToProviderSchema(...)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin6/convert/schema.go:98
github.com/hashicorp/terraform/internal/plugin6.(*GRPCProvider).GetProviderSchema(0xc00004a200)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin6/grpc_provider.go:152 +0x29a
github.com/hashicorp/terraform/internal/plugin6.TestGRPCProvider_GetSchema_ResponseErrorDiagnostic(0x0?)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin6/grpc_provider_test.go:158 +0x265
testing.tRunner(0xc0001031e0, 0x1a733d8)
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1486 +0x35f
```

Previously:

```
--- FAIL: TestGRPCProvider_GetSchema_ResponseErrorDiagnostic (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x18a2732]

goroutine 7 [running]:
testing.tRunner.func1.2({0x1a5e720, 0x250be50})
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1392 +0x39f
panic({0x1a5e720, 0x250be50})
	/usr/local/Cellar/go/1.18.2/libexec/src/runtime/panic.go:838 +0x207
github.com/hashicorp/terraform/internal/plugin/convert.ProtoToConfigSchema(0x0)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin/convert/schema.go:104 +0x52
github.com/hashicorp/terraform/internal/plugin/convert.ProtoToProviderSchema(...)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin/convert/schema.go:92
github.com/hashicorp/terraform/internal/plugin.(*GRPCProvider).GetProviderSchema(0xc00004a600)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin/grpc_provider.go:149 +0x29a
github.com/hashicorp/terraform/internal/plugin.TestGRPCProvider_GetSchema_ResponseErrorDiagnostic(0x0?)
	/Users/bflad/src/github.com/hashicorp/terraform/internal/plugin/grpc_provider_test.go:130 +0x265
testing.tRunner(0xc0001031e0, 0x1be9500)
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/usr/local/Cellar/go/1.18.2/libexec/src/testing/testing.go:1486 +0x35f
```
2022-06-03 14:27:55 -04:00
James Bardin
93ff27227a
Merge pull request #31163 from hashicorp/jbardin/plan-destroy
Use plan graph builder for destroy
2022-06-01 15:37:13 -04:00
James Bardin
e36ee757a5 minor cleanup from review 2022-06-01 15:29:59 -04:00
James Bardin
4fb8a5a3ec
Merge pull request #31164 from hashicorp/jbardin/go-getter-security-options
add XTerraformGetLimit to prevent redirect loops
2022-06-01 13:04:20 -04:00
James Bardin
47f9850f02 add XTerraformGetLimit to prevent redirect loops 2022-06-01 12:46:22 -04:00
Luces Huayhuaca
70ddcc7d0d
add url to summary and check for optional values (#30993) 2022-05-31 13:48:07 -07:00
kmoe
54b837416c
command: mention plan options in refresh help text (#30892)
* command: add parallelism option to refresh help text
2022-05-31 14:27:21 +01:00
Alisdair McDiarmid
a6587970d0
Merge pull request #30552 from gbataille/29156_do_not_log_sensitive_values
Fixes #29156: Failing sensitive variables values are not logged
2022-05-30 10:40:51 -04:00
Alisdair McDiarmid
06f6a901ea
Merge pull request #30985 from hashicorp/alisdair/var-flag-spaces-error
cli: Improved error for invalid -var "foo = bar"
2022-05-30 10:40:00 -04:00
James Bardin
ec476af655 test for configured destroy plan provider 2022-05-27 11:58:25 -04:00
James Bardin
8fed14fc59 use the PlanGraphBuilder for destroy
Rather than maintain a separate graph builder for destroy, use the
normal plan graph with some extra options. Utilize the same pattern as
the validate graph for now, where we take the normal plan graph builder
and inject a new concrete function for the destroy nodes.
2022-05-27 10:59:11 -04:00
James Bardin
77d13808d5 rename field to destroyPlan for consistency 2022-05-27 10:58:28 -04:00
James Bardin
6860596b68 don't add orphan nodes during destroy
All instances in state are being removed for destroy, so we can skip
checking for orphans. Because we want to use the normal plan graph, we
need to be able to still call this during destroy, so flag it off.
2022-05-27 10:56:40 -04:00
James Bardin
d6f0d1ea57 don't add config nodes during destroy plan
We want to use the normal plan graph for destroy, so we need to flag off
configuration for that process.
2022-05-27 10:55:38 -04:00
James Bardin
e3a6e1f6e8 remove unused fields from DestroyEdgeTransformer 2022-05-27 10:54:58 -04:00
James Bardin
b8e362d24c do not connect references _to_ destroyers either
Destroy nodes should never participate in references. These edges didn't
come up before, because we weren't building a complete graph including
all temporary values.
2022-05-27 10:50:01 -04:00
James Bardin
2ad3ac7d01
Merge pull request #31111 from hashicorp/jbardin/unknown-error-paths
add unknown paths to diags for debugging
2022-05-24 10:37:50 -04:00
Martin Atkins
096f0dc0da build: Write the detected version number into the generated executable
This also sets an additional variable if it detects that this is an alpha
or development build, which currently does nothing but might eventually
turn on the ability to use experimental features, if we make that
something available only in prereleases.
2022-05-23 16:48:34 -07:00
James Bardin
a6968b5b20
Merge pull request #31060 from hashicorp/alisdair/fix-configload-snapshot-panic
configs: Fix module loader nil pointer panic
2022-05-23 13:56:33 -04:00
James Bardin
48309835b7 add unknown paths to diags for debugging
When a user reports a "Configuration contains unknown value" error,
there is no information on what might have been unknown during apply.
Add unknown attribute paths to the diagnostic message to provide some
more information when a reproduction may not be possible. Sine this is
one of those "should never happen" types of errors which will be
reported to the developers directly, we can leave the format as the raw
internal representation for simplicity.
2022-05-23 13:28:30 -04:00
Martin Atkins
ec421fe02d configs: A test for the regression reported in #31081
5417975946 addressed a regression in the
logic for catching when the newer module meta-arguments are used in
conjunction with the legacy practice of including provider configurations
inside modules, where the check started incorrectly catching situations
where the legacy nested provider configuration was in the same module
as the child call using one of those meta-arguments.

This is a regression test to catch if a similar bug arises in the future.

Since it's testing validation rules that apply to an entire configuration
tree, it ended up in a rather idiosyncratic location under the "configload"
package, rather than directly in "configs". The "configs" package only
knows how to load one module at a time, so it's harder to write a test
like this in that context. Due to it being further removed from the code
it is testing, I included a test for the correct error too in order to
increase the chance that we'll learn if future changes in the "configs"
package invalidate this regression test.

I've verified that this new test fails without the change made in the
earlier commit.
2022-05-20 11:24:31 -07:00
Craig Wright
be7f46a1ad
Merge pull request #29354 from srdecny/main
Fix CLI help text for output. Reviewed with @apparentlymart and @kmoe.
2022-05-20 10:58:09 -07:00
kmoe
5417975946
configs: fix module for_each call bug (#31091)
This fixes a bug introduced in 1879a39 in which initialising a module will fail
if that module contains both a provider block and a module call using for_each.
2022-05-20 16:58:46 +01:00
Alisdair McDiarmid
d1e35a3f7c configs: Fix module loader nil pointer panic
In configurations which have already been initialized, updating the
source of a non-root module call to an invalid value could cause a nil
pointer panic. This commit fixes the bug and adds test coverage.
2022-05-17 09:13:35 -04:00
Alisdair McDiarmid
6494aa0326 Include var declaration where possible 2022-05-13 17:09:38 -04:00
Martin Atkins
289bb60ce1 core: Defer on transitive dependencies for data resources with conditions
When a data resource is used for the purposes of verifying a condition
about an object managed elsewhere (e.g. if the managed resource doesn't
directly export all of the information required for the condition) it's
important that we defer the data resource read to the apply step if the
corresponding managed resource has any changes pending.

Typically we'd expect that to come "for free" but unfortunately we have
a pragmatic special case in our handling of data resources where we
normally defer to the apply step only if a _direct_ dependency of the data
resource has a change pending, and allow a plan-time read if there's
a pending change in an indirect dependency. This allowed us to preserve
some compatibility with the questionable historical behavior of always
reading data resources proactively unless the configuration contains
unknown values, since the arguably-more-correct behavior would've been a
regression for anyone who had been depending on that before.

Since preconditions and postconditions didn't exist until now, we are not
constrained in the same way by backward compatibility, and so we can adopt
the more correct behavior in the case where a data resource has conditions
specified. This does unfortunately make the handling of data resources
with conditions subtly inconsistent with those that don't, but this is
a better situation than the alternative where it would be easy to get into
a trapped situation where the remote system is invalid and it's impossible
to plan the change that would make it valid again because the conditions
evaluate too soon, prior to the fix being applied.
2022-05-11 11:01:38 -07:00
Martin Atkins
4cffff24b1 core: Report reason for deferring data read until apply
We have two different reasons why a data resource might be read only
during apply, rather than during planning as usual: the configuration
contains unknown values, or the data resource as a whole depends on a
managed resource which itself has a change pending.

However, we didn't previously distinguish these two in a way that allowed
the UI to describe the difference, and so we confusingly reported both
as "config refers to values not yet known", which in turn led to a number
of reasonable questions about why Terraform was claiming that but then
immediately below showing the configuration entirely known.

Now we'll use our existing "ActionReason" mechanism to tell the UI layer
which of the two reasons applies to a particular data resource instance.
The "dependency pending" situation tends to happen in conjunction with
"config unknown", so we'll prefer to refer that the configuration is
unknown if both are true.
2022-05-09 11:12:47 -07:00
Grégory Bataille
378ee6ac56
Fixes #29156: Failing sensitive variables values are not logged 2022-05-07 13:25:20 +02:00
James Bardin
b97c64009e
Merge pull request #30987 from hashicorp/jbardin/get-schema-diags
plugin: diagnostics must be checked on all schema calls
2022-05-04 11:18:42 -04:00
Anna Winkler
22c121df86
Bump compatibility version to 1.3.0 for terraform core release (#30988)
* Bump compatibility version to 1.3.0 for terraform core release

Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
2022-05-03 12:28:41 -06:00
James Bardin
8943c79322 diagnostics must be checked on all schema calls
We can no longer be assured that the particular instance of a provider
we are using has had GetProviderSchema called. Always check the
diagnostics even if we're fetching a cached response.
2022-05-03 10:30:59 -04:00
Alisdair McDiarmid
91d75baba1 cli: Improved error for invalid -var "foo = bar"
When specifying variable values on the command line, name-value pairs
must be joined with an equals sign, without surrounding spaces.
Previously Terraform would interpret "foo = bar" as assigning the value
" bar" to the variable named "foo ". This is never valid, as variable
names may not include whitespace.

This commit looks for this specific error and returns a diagnostic with
a suggestion for correcting it. We cannot simply trim whitespace,
because it is valid to write "foo= bar" to assign the value " bar" to
the variable "foo", as unlikely as it seems.
2022-05-03 09:14:29 -04:00
Alisdair McDiarmid
0c435e2e08 communicator/ssh: Fix crash using SSH+HTTP proxy 2022-05-03 08:24:59 -04:00
James Bardin
80792312d8
Merge pull request #30979 from hashicorp/jbardin/cancel-auto-approve
check for cancellation before apply confirmation
2022-05-02 17:14:14 -04:00
Luces Huayhuaca
ea1f0007ff
fix typo for task.Status (#30978) 2022-05-02 11:52:22 -07:00
James Bardin
df0a70bfb6 check for cancellation before apply confirmation
When executing an apply with no plan, it's possible for a cancellation
to arrive during the final batch of provider operations, resulting in no
errors in the plan. The run context was next checked during the
confirmation for apply, but in the case of -auto-approve that
confirmation is skipped, resulting in the canceled plan being applied.

Make sure we directly check for cancellation before confirming the plan.
2022-05-02 14:09:47 -04:00
James Bardin
34a01c92d6 copy Dependencies before sorting in state
Instances of the same AbsResource may share the same Dependencies, which
could point to the same backing array of values. Since address values
are not pointers, and not meant to be shared, we must copy the value
before sorting the slice in-place. Because individual instances of the
same resource may be encoded to state concurrently, failure to copy the
slice first can result in a data race.
2022-04-28 11:44:32 -04:00
htamakos
4cfb6bc893
communicator/ssh: Add support SSH over HTTP Proxy (#30274)
Terraform's remote-exec provision hangs out when it execs on HTTP Proxy bacause it dosen't support SSH over HTTP Proxy. This commits enables Terraform's remote-exec to support SSH over HTTP Proxy.

* adds `proxy_*` fields to `connection` which add configuration for a proxy host
* if `proxy_host` set, connect to that proxy host via CONNECT method, then make the SSH connection to `host` or `bastion_host`
2022-04-27 16:59:17 -04:00
Alisdair McDiarmid
5e023ecfee
Merge pull request #30949 from hashicorp/alisdair/typeexpr-tests
typeexpr: Add test coverage
2022-04-27 15:44:00 -04:00
Alisdair McDiarmid
c82e291422 typeexpr: More optional modifier tests
Ensuring that the constraint boolean carries through to the next level
of constraint calculation after an optional() modifier.
2022-04-27 14:53:16 -04:00
Alisdair McDiarmid
dde4979c49 typeexpr: Improve diagnostic for any() constraints
Using the any keyword with arguments (e.g. any(string, bool)) is
invalid, but any is not technically a "primitive type keyword". This
commit corrects the language in the diagnostic and updates the tests.
2022-04-27 14:52:03 -04:00
Tom Bamford
351fd9b119
Merge pull request #30936 from hashicorp/f/azurerm-backend-oidc
backend/remote-state/azure: support OIDC authentication
2022-04-27 19:34:53 +01:00
Tom Bamford
d08bc4463d
Azure Backend: support OIDC authentication 2022-04-27 19:27:30 +01:00
Alisdair McDiarmid
356cee7b89 typeexpr: Add test coverage for optional modifier 2022-04-27 14:25:42 -04:00
Alisdair McDiarmid
bf9f733ca2 typeexpr: Import tests from hashicorp/hcl
This package is a fork of the HCL ext/typeexpr package, but we dropped
the tests when bringing it across. This commit imports those tests
verbatim.
2022-04-27 14:16:33 -04:00
Alisdair McDiarmid
12c8f9498c json-output: Add output type to JSON format
Previously the supported JSON plan and state formats included only
serialized output values, which was a lossy serialization of the
Terraform type system. This commit adds a type field in the usual cty
JSON format, which allows reconstitution of the original value.

For example, previously a list(string) and a set(string) containing the
same values were indistinguishable. This change serializes these as
follows:

{
  "value": ["a","b","c"],
  "type": ["list","string"]
}

and:

{
  "value": ["a","b","c"],
  "type": ["set","string"]
}
2022-04-27 13:30:15 -04:00
Sebastian Rivera
9d7fdbea2d Handle -input=false in cloud integration
For non-interactive contexts, Terraform is typically executed with the flag -input=false.
However for runs that are not set to auto approve, the cloud integration will prompt a user for
approval input even with input being set to false. This commit enables the cloud integration to know
the value of the input flag and use it to determine whether or not to ask the user for input.

If -input is set to false and the run cannot be auto approved, the cloud integration will throw an error
stating run confirmation can no longer be handled in the CLI and that they must do so through the browser.
2022-04-26 11:17:44 -04:00
Sebastian Rivera
c557078704
Merge pull request #30917 from hashicorp/sebasslash/config-token-precedence
Give the configuration token higher precedence over the CLI config file
2022-04-26 10:23:02 -04:00
James Bardin
d9af967a6e build a test apply graph during plan
The plan graph does not contain all the information necessary to detect
cycles which may happen when building the apply graph. Once we have more
information from the plan we can build the complete apply graph with all
individual instances to verify that the apply can begin without errors.
2022-04-22 15:54:01 -04:00
James Bardin
7da52d94f2
Merge pull request #30900 from hashicorp/jbardin/replace-triggered-by
Configurable instance replacement via lifecycle `replace_triggered_by`
2022-04-22 14:36:42 -04:00