Commit Graph

886 Commits

Author SHA1 Message Date
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
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
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
James Bardin
fef66f9a60
Merge pull request #30486 from hashicorp/jbardin/drift
Only show external changes which contributed to the plan
2022-03-18 14:19:46 -04:00
James Bardin
8c5e11d41a add relevant_attributes to the json plan format
Add the resource instances and individual attributes which may have
contributed to the planned changes to the json format of the plan. We
use the existing path encoding for individual attributes, which is
already used in the replace_paths change field.
2022-03-17 09:35:36 -04:00
James Bardin
f0cd8be66f add whole resource references 2022-03-17 09:35:36 -04:00
James Bardin
773f5b02ec round-trip relevant attributes through planfile 2022-03-17 09:35:36 -04:00
James Bardin
e2b74247f2 track contributing instances
Track individual instance drift rather than whole resources which
contributed to the plan. This will allow the output to be more precise,
and we can still use NoKey instances as a proxy for containing resources
when needed.
2022-03-17 09:35:36 -04:00
James Bardin
25f4c0d3dd filter attribute refresh changes from plan UI
Filter the refresh changes from the normal plan UI at the attribute
level. We do this by constructing fake plans.Change records for diff
generation, reverting all attribute changes that do not match any of the
plan's ContributingResourceReferences.
2022-03-17 09:35:36 -04:00
James Bardin
0e7cec83db decode change before creating diff
This is functionally equivalent, but will allow us to filter the change
values directly for reduced drift output.
2022-03-17 09:35:36 -04:00
James Bardin
c02e8bc5b3 change plan to store individual relevant attrs
Storing individual contributing attributes will allow finer tuning of
the plan rendering.

add contributing to outputs
2022-03-17 09:35:36 -04:00
James Bardin
620caa983c globalref.Reference.ResourceAttr
Convert a global reference to a specific AbsResource and attribute pair.
The hcl.Traversal is converted to a cty.Path at this point because plan
rendering is based on cty values.
2022-03-17 09:35:36 -04:00
Alisdair McDiarmid
ad9c89fc19 cli: Fix missing identifying attributes in diff
When rendering a diff for an object value within a resource, Terraform
should always display the value of attributes which may be identifying.
At present, this is a simple rule: render attributes named "id", "name",
or "tags".

Prior to this commit, Terraform would only apply this rule to top-level
resource attributes and those inside nested blocks. Here we extend the
implementation to include object values in other contexts as well.
2022-03-16 10:38:52 -04:00
Alisdair McDiarmid
0764726e3e functions: Fix sum() of all strings
The sum() function accepts a collection of values which must all convert
to numbers. It is valid for this to be a collection of string values
representing numbers.

Previously the function would panic if the first element of a collection
was a non-number type, as we didn't attempt to convert it to a number
before calling the cty `Add` method.
2022-03-16 08:50:06 -04:00
Theo Chupp
d15a2bc024
fix: local variables should not be overridden by remote variables during terraform import (#29972)
* fix: local variables should not be overridden by remote variables during `terraform import`

* chore: applied the same fix in the 'internal/cloud' package

* backport changes from cloud package to remote package

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
Co-authored-by: uturunku1 <luces.huayhuaca@gmail.com>
2022-03-15 14:42:11 -07:00
Alisdair McDiarmid
b5cfc0bb8b core: Fix sensitive variable validation errors
Variable validation error message expressions which generated sensitive
values would previously crash. This commit updates the logic to align
with preconditions and postconditions, eliding sensitive error message
values and adding a separate diagnostic explaining why.
2022-03-11 13:45:04 -05:00
Alisdair McDiarmid
6db174e210 core: Fix crash for sensitive values in conditions
Precondition and postcondition blocks which evaluated expressions
resulting in sensitive values would previously crash. This commit fixes
the crashes, and adds an additional diagnostic if the error message
expression produces a sensitive value (which we also elide).
2022-03-11 13:45:04 -05:00
Alisdair McDiarmid
6cd0876596
Merge pull request #30658 from hashicorp/alisdair/preconditions-postconditions-refresh-only
core: Eval pre/postconditions in refresh-only mode
2022-03-11 13:44:51 -05:00
Alisdair McDiarmid
a103c65140 core: Eval pre/postconditions in refresh-only mode
Evaluate precondition and postcondition blocks in refresh-only mode, but
report any failures as warnings instead of errors. This ensures that any
deviation from the contract defined by condition blocks is reported as
early as possible, without preventing the completion of a state refresh
operation.

Prior to this commit, Terraform evaluated output preconditions and data
source pre/postconditions as normal in refresh-only mode, while managed
resource pre/postconditions were not evaluated at all. This omission
could lead to confusing partial condition errors, or failure to detect
undesired changes which would otherwise cause resources to become
invalid.

Reporting the failures as errors also meant that changes retrieved
during refresh could cause the refresh operation to fail. This is also
undesirable, as the primary purpose of the operation is to update local
state. Precondition/postcondition checks are still valuable here, but
should be informative rather than blocking.
2022-03-11 13:32:40 -05:00
James Bardin
45e2a410f7
Merge pull request #30656 from hashicorp/jbardin/always-validate
Always validate the graph
2022-03-11 10:37:30 -05:00