Commit Graph

903 Commits

Author SHA1 Message Date
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
Brandon Croft
fda05f3d44
feat(credentials): allow hyphens to be encoded as __ in variables
Hyphen characters are allowed in environment variable names, but are not valid POSIX variable names. Usually, it's still possible to set variable names with hyphens using utilities like env or docker. But, as a fallback, host names may encode their hyphens as double underscores in the variable name. For the example "café.fr", the variable name "TF_TOKEN_xn____caf__dma_fr" or "TF_TOKEN_xn--caf-dma_fr"
may be used.
2022-04-13 13:49:59 -06:00
Brandon Croft
307326fa3a
allow remote service creds to be configured using env
Introduces a new method of configuring token service credentials using a host-specific environment variable. This configuration was previously possible using the [terraform-credentials-env](https://github.com/apparentlymart/terraform-credentials-env) credentials helper.

This new method is now consulted first, as it is seen to be the most proximate source of credentials before CLI configuration while still falling back to the credentials helper.
2022-04-13 13:49:57 -06:00
Brandon Croft
0dc26a9585
test(cloud): nonexisting org not a valid test when using mocks 2022-04-13 09:27:13 -06:00
Brandon Croft
a38a0ee8a8
test(cloud): ensure mocks are used for backend configure tests
Also adds a few new tests for cloud configuration using environment variables
2022-04-13 08:56:27 -06:00
Alisdair McDiarmid
fadcaaaad2 cli: Fix double-quoted map keys in diff UI
A previous change added missing quoting around object keys which do not
parse as barewords. At the same time we introduced a bug where map keys
could be double-quoted, due to calling the `displayAttributeName` helper
function (to quote non-bareword keys) then using the `writeValue` method
(which quotes all strings).

This commit fixes this and adds test coverage for map keys which require
quoting.
2022-04-13 09:10:00 -04:00
Sebastian Rivera
b191faf8a4 Add skip test if missing vars helper 2022-04-12 17:32:39 -04:00
Sebastian Rivera
34114286ff Cloud e2e tests for configuring with env vars 2022-04-11 15:19:17 -04:00
Sebastian Rivera
8040dfec34
Merge pull request #30787 from hashicorp/sebasslash/tf-workspace-cloud-config
Add cloud config support for TF_WORKSPACE
2022-04-11 14:38:23 -04:00
Sebastian Rivera
dd864b1bac Add TF_WORKSPACE validation method 2022-04-11 13:59:02 -04:00
James Bardin
74885b1108 remove data sources from state read and upgrade
Data sources should not require reading the previous versions. While we
previously skipped the decoding if it were to fail, this removes the
need for any prior state at all.

The only place where the prior state was functionally used was in the
destroy path. Because a data source destroy is only for cleanup purposes
to clean out the state using the same code paths as a managed resource,
we can substitute the prior state in the change change with a null value
to maintain the same behavior.
2022-04-11 11:55:53 -04:00
James Bardin
29ecac0808 remove the use of data source prior state entirely
After data source handling was moved from a separate refresh phase into
the planning phase, reading the existing state was only used for
informational purposes. This had been reduced to reporting warnings when
the provider returned an unexpected value to try and help locate legacy
provider bugs, but any actual issues located from those warnings were
very few and far between.

Because the prior state cannot be reliably decoded when faced with
incompatible provider schema upgrades, and there is no longer any
significant reason to try and get the prior state at all, we can skip
the process entirely.
2022-04-11 10:19:45 -04:00
James Bardin
a7987dec9f remove redundant readResourceInstanceState 2022-04-11 10:12:44 -04:00
James Bardin
01628f0d50 data schema changes may prevent state decoding
Data sources do not have state migrations, so there may be no way to
decode the prior state when faced with incompatible type changes.

Because prior state is only informational to the plan, and its existence
should not effect the planning process, we can skip decoding when faced
with errors.
2022-04-11 09:45:10 -04:00
Alisdair McDiarmid
d23f0998fb cli: Fix plan diff for sensitive nested attributes
When rendering diffs for resources which use nested attribute types, we
must cope with collections backing those attributes which are entirely
sensitive. The most common way this will be seen is through sensitive
values being present in sets, which will result in the entire set being
marked sensitive.
2022-04-08 16:16:52 -04:00
Eng Zer Jun
fedd315275
test: use T.TempDir to create temporary test directory (#30803)
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-04-08 17:34:16 +01:00
Sebastian Rivera
995ef15ab9 Add cloud configuration support for TF_WORKSPACE
TF_WORKSPACE can now be used for your cloud configuration, effectively serving as an alternative
to setting the name attribute in your workspaces configuration.
2022-04-07 11:46:36 -04:00
Alisdair McDiarmid
bb35f02c95 Conclude preconditions/postconditions experiment 2022-04-04 15:54:40 -04:00
Alisdair McDiarmid
c5d10bdef1 core: Store condition block results in plan
In order to include condition block results in the JSON plan output, we
must store them in the plan and its serialization.

Terraform can evaluate condition blocks multiple times, so we must be
able to update the result. Accordingly, the plan.Conditions object is a
map with keys representing the condition block's address. Condition
blocks are not referenceable in any other context, so this address form
cannot be used anywhere in the configuration.

The commit includes a new test case for the JSON output of a
refresh-only plan, which is currently the only way for a failing
condition result to be rendered through this path.
2022-04-04 15:36:29 -04:00
Martin Atkins
49d7c879ac Fix problems caught by staticcheck v0.3.0
This will allow us to upgrade to this version in a later commit without
causing the our build checks to fail.
2022-04-04 08:12:44 -07:00
kmoe
5907a86301
command/format: Correctly quote diff object keys (#30766)
When rendering a diff, we should quote object attribute names if the
string representation is not a valid identifier. While this is not
strictly necessary, it makes the diff output more closely resemble the
configuration language, which is less confusing.

This commit applies to both top-level schema attributes and any object
value attributes. We use a simplistic "%q" Go format string to quote the
strings, which is not strictly identical to HCL's quoting requirements,
but is the pattern used elsewhere in HCL and Terraform.

Co-Authored-By: Katy Moe <katy@katy.moe>

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
2022-04-01 10:09:28 +01:00
Lars Lehtonen
88c9b90c93
internal/backend/remote-state/oss: fix dropped error (#30352) 2022-04-01 08:07:31 +01:00
James Bardin
0bd59238d6
Merge pull request #30765 from hashicorp/jbardin/contributing-attributes
improve the contributing attributes filter
2022-03-31 16:56:09 -04:00
UKEME BASSEY
1c9929a378
Merge pull request #30773 from hashicorp/uk1288/fix-for-cloud-integration-panic
command/meta_backend: fix for cloud integration panic
2022-03-31 13:53:00 -04:00
gabriel376
f5a8608989
cli: Make state commands check required version (#30511) 2022-03-31 13:42:42 -04:00
Sebastian Rivera
a52c87cb5a Fix a flaky test manipulating environment variables
This test resolves an issue where variables were going unset causing leaks into other test
cases and therefore resulting in failures.
2022-03-31 09:57:15 -04:00
uk1288
9093b487fd fix for cloud integration panic 2022-03-30 17:50:08 -04:00
Sebastian Rivera
232d48fe00 Add support for TF_HOSTNAME env var 2022-03-30 11:54:50 -04:00
Sebastian Rivera
b4b4f4e9d9
Merge pull request #30719 from hashicorp/sebasslash/add-tf-org-env-var
Add TF_ORGANIZATION env var support
2022-03-30 11:41:07 -04:00
Sebastian Rivera
b1c22d333e Fix error formatting for missing env and config value
We previously used to throw an error denoting where in the configuration the attribute was missing or invalid.
Considering that organization can be now be omitted from the configuration, our previous error message will be
improperly formatted. This commit also updates the message to mention `TF_ORGANIZATION` as a valid substitute if
organization is missing or invalid in the configuration.
2022-03-30 11:04:30 -04:00
James Bardin
09dde8d5ed improve the contributing attributes filter
The initial rough implementation contained a bug where it would
incorrectly return a NilVal in some cases.

Improve the heuristics here to insert null values more precisely when
parent objects change to or from null. We also check for dynamic types
changing, in which case the entire object must be taken when we can't
match the individual attribute values.
2022-03-30 10:04:48 -04:00
Matthias Baur
971c899c12
Clarify multiple times usage (#30724)
* Clarify multiple times usage


Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2022-03-30 09:52:49 +01:00
Sebastian Rivera
45357f5004 Add TF_ORGANIZATION env var support
TF_ORGANIZATION will serve as a fallback for configuring the organization in the `cloud`
block. This is the first step to make it easier for users wanting to configure Terraform
programmatically.
2022-03-26 16:44:16 -04:00
Markus Bösling
275ff5b223
double word removed (#30679) 2022-03-25 14:31:52 +00:00
shinbunbun
a1ead44c71
cidrnetmask() produce an error with IPv6 (#30703)
* Add error handling for IPv6



Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2022-03-25 14:26:47 +00:00
Luces Huayhuaca
bdc7d8c0a1
Upgrade go-tfe dependency to use 1.0 version. It contains breaking changes, so we are updating method signatures, method names and the type of optional parameters, as needed. (#30626) 2022-03-23 13:58:47 -07:00
Anna Winkler
4ca508294c
Update comment for this transformer
Remove extra word and add link to Wikipedia article
2022-03-22 17:17:56 -06:00
Alisdair McDiarmid
b386f76b65
Merge pull request #30685 from hashicorp/alisdair/fix-30641
cli: Fix missing identifying attributes in diff
2022-03-21 09:11:45 -04:00