Commit Graph

940 Commits

Author SHA1 Message Date
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
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
Sebastian Rivera
5ded48e081 Give token in cloud config higher precedence than CLI config file 2022-04-22 14:09:20 -04:00
Keith Clawson
23dffee568 Always use token in backend config when provided 2022-04-22 14:01:00 -04:00
chavacava
5f58daaf57
fix typo in struct tag (#30884)
typo found by [`revive`](https://github.com/mgechev/revive)
2022-04-22 13:53:32 +01:00
James Bardin
7b6dfabb74
Merge pull request #30906 from hashicorp/jbardin/races
Fix known races and enable race detector in tests
2022-04-21 09:47:53 -04:00
James Bardin
0731213ecf sync retry goroutine return 2022-04-20 15:29:19 -04:00
James Bardin
c52e3ed37b test fixture race 2022-04-20 15:01:17 -04:00
James Bardin
0fe38fba6c prevent unsynchronized output changes access
The raw plan output changes were stored in the output exec node, when
they should have instead been fetch lazily through the context via the
synchronized ChangesSync value.
2022-04-20 14:45:58 -04:00
Sebastian Rivera
f63ef2b5ef Rename cloud env vars to use TF_CLOUD prefix 2022-04-20 14:34:53 -04:00
James Bardin
1e79682c24 minor fixes 2022-04-20 12:51:24 -04:00
Martin Atkins
d4776e8ef1 lang/funcs: type conversion functions can convert null values
We had intended these functions to attempt to convert any given value, but
there is a special behavior in the function system where functions must
opt in to being able to handle dynamically-typed arguments so that we
don't need to repeat the special case for that inside every function
implementation.

In this case we _do_ want to specially handle dynamically-typed values,
because the keyword "null" in HCL produces
cty.NullVal(cty.DynamicPseudoType) and we want the conversion function
to convert it to a null of a more specific type.

These conversion functions are already just a thin wrapper around the
underlying type conversion functionality anyway, and that already supports
converting dynamic-typed values in the expected way, so we can just opt
in to allowing dynamically-typed values and let the conversion
functionality do the expected work.

Fixing this allows module authors to use type conversion functions to
give additional type information to Terraform in situations that are too
ambiguous to be handled automatically by the type inference/unification
process. Previously tostring(null) was effectively a no-op, totally
ignoring the author's request to treat the null as a string.
2022-04-20 09:09:12 -07:00
Tom Harvey
2eb9118cd1
backend/remote-state/azure: defaulting the Azure Backend to use MSAL (#30891)
* backend/remote-state/azure: defaulting the Azure Backend to use MSAL

Fixes #30881

* backend/remote-state/azurerm: deprecating `use_microsoft_graph`
2022-04-20 17:31:44 +02:00
James Bardin
3a0a019521 round-trip replace triggers 2022-04-20 09:17:10 -04:00
James Bardin
54c1791a1b add triggers reason to plan proto 2022-04-20 09:17:10 -04:00
James Bardin
868052c9e3 set replace_trigered_by reason in diff output 2022-04-20 09:17:10 -04:00
James Bardin
e2fc9a19f5 use ResourceInstanceReplaceByTriggers
Set ResourceInstanceReplaceByTriggers in the change.
2022-04-20 09:17:10 -04:00
James Bardin
e4c4dcbd14 add ResourceInstanceReplaceByTriggers 2022-04-20 09:17:10 -04:00
James Bardin
91121aa856 limit replace_triggered_by to same module instance
replace_triggered_by references are scoped to the current module, so we
need to filter changes for the current module instance. Rather than
creating a ConfigResource and filtering the result, make a
Changes.InstancesForAbsResource method to get only the AbsResource
changes.
2022-04-20 09:17:10 -04:00
James Bardin
fb6fcf783b Fix replace_triggered_by criteria
Only immediate changes to the resource are considered.
2022-04-20 09:17:10 -04:00
James Bardin
6670b71a2e context test demonstrating replace_triggered_by 2022-04-20 09:17:10 -04:00
James Bardin
7598665c90 check for replacement via replace_triggered_by
Check for triggered resource replacement in the plan. While the
functionality of the feature works here, we ill want to follow up with a
way to indicate in the plan _why_ the resource was replaced.
2022-04-20 09:17:10 -04:00
James Bardin
4f2195af2b collect references from replace_triggered_by
The replace_triggered_by expressions create edges in the graph, so must
be returned in the References method.
2022-04-20 09:17:10 -04:00
James Bardin
4d43d6f699 Use the EvalContext to lookup trigger changes
The EvalContext is the only place with all the information to be able to
complete the evaluation of the replace_triggered_by expressions. These
need to be evaluated into a reference, which is then looked up in the
pending changes which the context has access too. On top of needing the
plan changes, we also need access to all providers and schemas to decode
the changes if we need to traverse the resource values for individual
attributes.
2022-04-20 09:17:10 -04:00
James Bardin
8b4c89bdaf evaluate replace_triggered_by expressions
Evaluate the expressions stored in replace_triggered_by into the
*addrs.Reference needed to lookup changes in the plan.
2022-04-20 09:17:10 -04:00
James Bardin
6eb3264d1a parse replace_triggered_by in resource configs 2022-04-20 09:17:10 -04:00
Brandon Croft
1943af51a2
fix(creds): allow periods in TF_TOKEN_... credentials vars 2022-04-15 12:38:14 -06:00
Brandon Croft
42da030090
Merge pull request #30850 from hashicorp/brandonc/cloud_test_revisions
test(cloud): ensure mocks are used for backend configure tests
2022-04-14 09:31:49 -06:00
Radek Simko
746af015ea
internal/getproviders: Add URL to error message for clarity (#30810)
* internal/getproviders: Add URL to error message for clarity

Occasionally `terraform init` on some providers may return the following error message:

Error while installing citrix/citrixadc v1.13.0: could not query provider
registry for registry.terraform.io/citrix/citrixadc: failed to retrieve
authentication checksums for provider: 403 Forbidden

The 403 is most often returned from GitHub (rather than Registry API)
and this change makes it more obvious.

* Use Host instead of full URL
2022-04-14 16:14:50 +01:00
James Bardin
d360a78771
Merge pull request #30832 from hashicorp/jbardin/data-readResourceInstanceState
remove the use of data source prior state from planning
2022-04-14 09:47:25 -04:00
James Bardin
f31dab4838
Merge pull request #30830 from hashicorp/jbardin/data-schema-change
data schema changes may prevent state decoding
2022-04-14 09:46:59 -04:00
Sebastian Rivera
3ebd8c9483
Merge pull request #30836 from hashicorp/sebasslash/env-cloud-e2e-tests
Cloud e2e tests for configuring `cloud` with env vars
2022-04-13 17:07:20 -04:00
Brandon Croft
f04202d222
Update credentials_test.go 2022-04-13 14:06:25 -06:00