Commit Graph

31330 Commits

Author SHA1 Message Date
Brandon Croft
14628b9246
Update cloudproto1.pb.go 2023-07-25 09:30:25 -06:00
Brandon Croft
e5ce25099c
Apply suggestions from code review
Co-authored-by: Sebastian Rivera <sebastian.rivera@hashicorp.com>
2023-07-25 09:28:32 -06:00
Brandon Croft
9bb566dcdb
Update cloudplugin type casting to simplify adding future versions 2023-07-25 09:28:32 -06:00
Brandon Croft
2c3d134705
Adds cloud subcommand with some toy options 2023-07-25 09:28:32 -06:00
Brandon Croft
7111fd1170
Adds cloudproto1 to make protobuf 2023-07-25 09:28:31 -06:00
Brandon Croft
a806f6220a
Tests the cloudplugin1 gRPC client 2023-07-25 09:28:31 -06:00
Brandon Croft
539e140d3e
Introduces cloudproto1 plugin interface 2023-07-25 09:28:31 -06:00
Brandon Croft
fec1ca69ac
Fix console godoc 2023-07-25 09:28:30 -06:00
Sebastian Rivera
dceb8453af
Merge pull request #33492 from hashicorp/cli-team/saved-cloud-plans
Implement saved cloud plans
2023-07-25 10:29:19 -04:00
Sebastian Rivera
08e58fd484 Fix saved plan test regressions, fixtures 2023-07-25 10:22:46 -04:00
Graham Davison
5588603822
Merge pull request #33534 from hashicorp/s3/update-configschema
S3 Backend: Converts from `legacy/helper/schema` to `configschema`
2023-07-24 17:46:09 -07:00
Graham Davison
8564a5bf0e Fixes type of parameter skip_credentials_validation 2023-07-24 17:36:51 -07:00
Sebastian Rivera
31cf55fe12 Reword error message when using local exec 2023-07-24 14:12:44 -04:00
Nick Fagerlund
1cbc95ce56 Use wrapped types to clean up error reporting in show command
Since terraform show can accept three different kinds of file to act on, its
error messages were starting to become untidy and unhelpful. The main issue was
that if we successfully identified the file type but then ran into some problem
while reading or processing it, the "real" error would be obscured by some other
useless errors (since a file of one type is necessarily invalid as the other
types).

This commit tries to winnow it down to just one best error message, in the
"happy path" case where we know what we're dealing with but hit a snag. (If we
still have no idea, then we fall back to dumping everything.)
2023-07-24 14:12:44 -04:00
Nick Fagerlund
f98f920b67 Add error wrapper types to highlight bad plan/state data
This commit uses Go's error wrapping features to transparently add some optional
info to certain planfile/state read errors. Specifically, we wrap errors when we
think we've identified the file type but are somehow unable to use it.

Callers that aren't interested in what we think about our input can just ignore
the wrapping; callers that ARE interested can use `errors.As()`.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
1f35173192 Tests: Add tests for (*Cloud).ShowPlanForRun() 2023-07-24 14:12:44 -04:00
Nick Fagerlund
7f6b827987 Modify tfe client mocks to meet some new requirements
- Add plausible unredacted plan json for `plan-json-{basic,full}` testdata --
  Created by just running the relevant terraform commands locally.

- Add plan-json-no-changes testdata --
  The unredacted json was organically grown, but I edited the log and redacted
  json by hand to match what I observed from a real but unrelated
  planned-and-finished run in TFC.

- Add plan-json-basic-no-unredacted testdata --
  This mimics a lack of admin permissions, resulting in a 404.

- Hook up `MockPlans.ReadJSONOutput` to test fixtures, when present.
  This method has been implemented for ages, and has had a backing store for
  unredacted plan json, but has been effectively a no-op since nothing ever
  fills that backing store. So, when creating a mock plan, make an attempt to
  read unredacted json and stow it in the mocks on success.

- Make it possible to get the entire MockClient for a test backend
  In order to test some things, I'm going to need to mess with the internal
  state of runs and plans beyond what the go-tfe client API allows. I could add
  magic special-casing to the mock API methods, or I could locate the
  shenanigans next to the test that actually exploits it. The latter seems more
  comprehensible, but I need access to the full mock client struct in order to
  mess with its interior.

- Fill in some missing expectations around HasChanges when retrieving a run +
  plan.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
ed27fa096e command/views/show_test: Update method arguments, add test cases 2023-07-24 14:12:44 -04:00
Nick Fagerlund
12af8518ff command/show_test: Update expected error text 2023-07-24 14:12:44 -04:00
Nick Fagerlund
3a9ce2afb1 Update show command and view to support inspecting cloud plans
One funny bit: We need to know the ViewType at the point where we ask the Cloud
backend for the plan JSON, because we need to switch between two distinctly
different formats for human show vs. `show -json`. I chose to pass that by
stashing it on the command struct; passing it as an argument would also work,
but one, the argument lists in these nested method calls were getting a little
unwieldy, and two, many of these functions had to be receiver methods anyway in
order to call methods on Meta.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
d5938f6b45 Add (*Cloud).ShowPlanForRun method to support terraform show
To do the "human" version of showing a plan, we need more than just the redacted
plan JSON itself; we also need a bunch of extra information that only the Cloud
backend is in a position to find out (since it's the only one holding a
configured go-tfe client instance). So, this method takes a run ID and hostname,
finds out everything we're going to need, and returns it wrapped up in a
RemotePlanJSON struct.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
e0af3e25e0 Add cloudplan.RemotePlanJSON wrapper struct for keeping plan metadata together 2023-07-24 14:12:44 -04:00
Nick Fagerlund
2a08a5b46e Cloud: Split private readRedactedPlan func into two
Since `terraform show -json` needs to get a raw hunk of json bytes and sling it
right back out again, it's going to be more convenient if plain `show` can ALSO
take in raw json. In order for that to happen, I need a function that basically
acts like `client.Plans.ReadJSONOutput()`, without eagerly unmarshalling that
`jsonformat.Plan` struct.

As a slight bonus, this also lets us make the tfe client mocks slightly
stupider.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
0df3c143bb New plans.Quality type for display-relevant facts about a plan
This commit replaces the existing jsonformat.PlanRendererOpt type with a new
type with identical semantics, located in the plans package.

We needed to be able to exchange the facts represented by
`jsonformat.PlanRendererOpt` across some package boundaries, but the jsonformat
package is implicated in too many dependency chains to be safe for that purpose!
So, we had to make a new one. The plans package seems safe to import from all
the places that must emit or accept this info, and already contains plans.Mode,
which is effectively a sibling of this type.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
da963a13b9 Implement plan -out for Cloud
- Don't save errored plans.
- Call op.View.PlanNextStep for terraform plan in cloud mode (We never used to
  show this footer, because we didn't support -out.)
- Create non-speculative config version if saving plan
- Rewrite TestCloud_planWithPath to expect success!
2023-07-24 14:12:44 -04:00
Nick Fagerlund
f9d937a4dd Apply a confirmable run when given a saved cloud plan (#33270)
It displays a run header with link to web UI, like starting a new plan does, then confirms the run
and streams the apply logs. If you can't apply the run (it's from a different workspace, is in an
unconfirmable state, etc. etc.), it displays an error instead.

Notable points along the way:

* Implement `WrappedPlanFile` sum type, and update planfile consumers to use it instead of a plain `planfile.Reader`.

* Enable applying a saved cloud plan

* Update TFC mocks — add org name to workspace, and minimal support for includes on MockRuns.ReadWithOptions.
2023-07-24 14:12:40 -04:00
Nick Fagerlund
9d85f18930 Add NewSavedPlanBookmark function
so we don't have to remember the format version number
2023-07-24 14:07:16 -04:00
Lauren
dcccd3b266 Add error handling and tests for saved plan bookmark load/save (#33268) 2023-07-24 14:07:16 -04:00
Nick Fagerlund
df7a1c821a Move SavedPlanBookmark to dedicated internal/cloud/cloudplan package
Having this sitting loose in `cloud` proved problematic because of circular
import dependencies. Putting it in a sub-package under cloud frees us up to
reference the type from places like `internal/backend`!
2023-07-24 14:07:16 -04:00
Lauren
717a36036d codify saved plan artifact contents (#33185) 2023-07-24 14:07:16 -04:00
Nick Fagerlund
b3f254e08d Upgrade to go-tfe v1.29.0 (for saved plan run support) 2023-07-24 14:07:16 -04:00
Brandon Croft
5fa956e1cb
Merge pull request #33432 from hashicorp/TF-7327-using-multiple-terraform-remote-state-data-sources-can-cause-race-conditions-when-the-backend-configuring-localterraform-com
Relocate localterraform.com aliasing to backend configurators
2023-07-21 15:01:22 -06:00
Brandon Croft
c1a730314d
Relocate localterraform.com aliasing to backend configurators
Previously, remote and cloud backends would automatically alias localterraform.com as the configured hostname during configuration. This turned out to be an issue with how backends could potentially be used within the builtin terraform_remote_state data source. Those data sources each configure the same service discovery with different targets for localterraform.com, and do so simultaneously, creating an occasional concurrent map read & write panic when multiple data sources are defined.

localterraform.com is obviously not useful for every backend configuration. Therefore, I relocated the alias configuration to the callers, so they may specify when to use it. The modified design adds a new method to backend.Enhanced to allow configurators to ask which aliases should be defined.
2023-07-21 09:55:41 -06:00
Liam Cervante
ad26644578
Fix flaky test in views package (#33560) 2023-07-20 18:57:35 +02:00
Liam Cervante
c91f91cc9e
testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
Liam Cervante
ca85d3bf85
Implement word wrapping in the terraform test view functions (#33547)
* Implement word wrapping in the terraform test view functions

* Update internal/command/views/test.go

Co-authored-by: CJ Horton <17039873+radditude@users.noreply.github.com>

---------

Co-authored-by: CJ Horton <17039873+radditude@users.noreply.github.com>
2023-07-20 08:29:09 +02:00
Martin Atkins
4b2b34929d version: Clean up after 1.6.0-alpha20230719 release 2023-07-19 10:58:07 -07:00
Martin Atkins
4d0966c780 version: Prepare for v1.6.0-alpha20230719 release 2023-07-19 09:41:45 -07:00
Liam Cervante
72135c462b Update CHANGELOG.md for new testing framework 2023-07-19 09:32:31 -07:00
James Bardin
62ee606752
Merge pull request #33543 from hashicorp/jbardin/get-schema-client-cache
always set schema caches from provider clients
2023-07-19 08:47:25 -04:00
Liam Cervante
6c7db16566
testing framework: refactor interrupt logic for immediate exits (#33532)
* testing framework: refactor interrupt logic

* fix formatting
2023-07-19 10:31:32 +02:00
Liam Cervante
6882dd9530
testing framework: introduce test command optional flags (#33504)
* testing framework: introduce test command optional flags

* address consistency checks
2023-07-19 10:07:46 +02:00
Liam Cervante
2cc81cfec6
testing framework: implement panic handling (#33525) 2023-07-19 09:57:09 +02:00
Liam Cervante
837716a703
testing framework: finalise expect_failures functionality (#33506) 2023-07-19 09:44:40 +02:00
James Bardin
e14b03f7b0 always set schema caches from provider clients
Allow core to always use the global schema cache, so that providers
without GetProviderSchemaOptional are not spun up repeatedly. Rather
than conditionally setting the cache, we just conditionally use the
cache in the client to work around providers without
GetProviderSchemaOptional.
2023-07-18 13:52:41 -04:00
CJ Horton
4530e36ae7
Merge pull request #32973 from hashicorp/radditude/one-version-to-rule-them-all
consolidate version information
2023-07-18 10:41:59 -07:00
James Bardin
f5d94b35a0
Merge pull request #33486 from hashicorp/jbardin/schema-cache-proto
enable schema caching and add `get_provider_schema_optional` server capability
2023-07-18 11:18:11 -04:00
CJ Horton
1e2a6be689 elaborate further on experiments and cgo 2023-07-17 11:56:13 -07:00
Graham Davison
344e9de6b9 Linting fixes 2023-07-17 11:34:33 -07:00
CJ Horton
16ae079c22 add documentation on Terraform's available build options 2023-07-17 11:22:31 -07:00