Commit Graph

90 Commits

Author SHA1 Message Date
Sebastian Rivera 52c5f9f6b7 Updated for latest go-tfe run task changes 2022-02-25 15:32:16 -05:00
Sebastian Rivera 126d6df088 Added run task support for post plan run stage, removed pre apply
This commit stems from the change to make post plan the default run task stage, at the
time of this commit's writing! Since pre apply is under internal revision, we have removed
the block that polls the pre apply stage until the team decides to re-add support for pre apply
run tasks.
2022-02-24 14:06:57 -05:00
uturunku1 383da4893b use new enum string for task stages 2022-02-24 14:06:57 -05:00
Brandon Croft aa0dda81b4 Fall back to reading latest run without task_stages
Older versions of TFE will not allow "task_stages" as an include parameter. In this case, fall back to reading the Run without additional options.
2022-02-24 14:06:57 -05:00
uturunku1 a9da859ee5 rename variables to something more descriptive 2022-02-24 14:03:02 -05:00
uturunku1 77946af472 pull latest changes from go-tfe branch and use use new field name that previously was incorrectly named TaskStage 2022-02-24 14:03:00 -05:00
uturunku1 8090b23db7 delete unused function 2022-02-24 14:02:37 -05:00
Brandon Croft 0b8bb29a61 [cloud] refactor integration context and add code documentation 2022-02-24 14:02:37 -05:00
Brandon Croft 791c36c504 [cloud] report run tasks by name instead of assuming pre_apply 2022-02-24 14:02:37 -05:00
uturunku1 6b5da4d43c [cloud] run tasks output formatting 2022-02-24 14:02:37 -05:00
Brandon Croft 2938ec43fa [cloud] handle unreachable run tasks 2022-02-24 14:02:37 -05:00
uturunku1 3e9ae69a12 [cloud] run tasks integration
This change will await the completion of pre-apply run tasks if they
exist on a run and then report the results.

It also adds an abstraction when interacting with cloud integrations such
as policy checking and cost estimation that simplify and unify output,
although I did not go so far as to refactor those callers to use it yet.
2022-02-24 14:02:35 -05:00
Barrett Clark d196d2870a Refactor cloud table test runs
As the cloud e2e tests evolved some common patters became apparent. This
standardizes and consolidates the patterns into a common test runner
that takes the table tests and runs them in parallel. Some tests also
needed to be converted to utilize table tests.
2021-12-20 16:36:06 -06:00
Barrett Clark c647b41d65 Add parallelism back into the tests
Running tests in parallel can help speed up overall test execution. Go
blocks parent tests while child tests run, so it does not fully fan out
as you might expect. It is noticably faster, though. Running 4 or more
concurrent processes knocks over a minute off the total execution time.
2021-12-15 11:37:49 -06:00
Barrett Clark 7aeaec9b48 Update tests for new prompts
* Remove double question to migrate
* Remove parallelism (it has been flaky)
* Add subtests to apply_auto_approve_test (it was overlooked before)
2021-11-17 14:20:44 -08:00
Barrett Clark 27aa51687e Fix cloud e2e tests for updated migration flow 2021-11-17 14:20:44 -08:00
Martin Atkins bac59d2480 command/init: Be explicit that some options are not relevant for Cloud
There are a few command line options for "terraform init" which are only
relevant when working with traditional backends, with the Cloud
integration previously just mostly ignoring them, or sometimes misbehaving
slightly due to them creating an unreasonable situation.

Now we'll catch these and return explicit errors, in order to be clear
that these options are not needed nor supported in Cloud mode.
2021-11-17 14:20:44 -08:00
Martin Atkins c28b57b4d6 cloud/e2e: Additional context for failing to find expected output
This just gives a little extra information to work with when trying to
understand why a test failed. It doesn't change what any of the tests are
actually trying to test.
2021-11-17 14:20:44 -08:00
Martin Atkins e5172fea95 cloud: DetectConfigChangeType helper
This aims to encapsulate the somewhat-weird logic we currently use to
distinguish between the various "terraform init" situations involving
Terraform Cloud mode, in the hope of making codepaths that branch based
on this slightly easier to read.

This isn't yet used, but uses of it will follow in subsequent commits.
2021-11-17 14:20:44 -08:00
Barrett Clark a146a2746e Add clarifying commend and e2e test
This pull request focuses on removing the prompt to rename the default
workspace when it is empty. Functionality already exists to not migrate
an empty workspace. This commit adds some clarifying language in the
comment where we do the evaluation to know whether to ask for a new name
or not. I also added an end to end test, which I should have added to
begin with.
2021-11-16 13:05:26 -06:00
Omar Ismail 9b675f8b70 Add skip for cloud e2e tests when env vars missing 2021-11-15 10:36:19 -05:00
Omar Ismail 57a4b51e87 remove build tags for cloud e2e 2021-11-11 16:33:26 -05:00
Barrett Clark 5ef82ddd2f Cloud: fix e2e tests
- Fix tests and remove commented code
- Remove parallel for some flaky tests
- Add README
2021-11-11 14:37:21 -05:00
Brandon Croft 1f01ba4dbc
fix(run variables): support all variable types (map, list, bool, number, null, string)
All run variables remain encoded as strings in the API but will now be expressed as an HCL value to be evaluated correctly by the remote terraform. Previously, only strings were supported.

Examples:
string: `"quoted literal"` (strings must be quoted)
map:  `{ foo = "bar" }`
list: `["foo", "bar"]`
bool: `true`
null: `null`
number: `0.0001`

This requires the API to anticipate that all run variables will be HCL values
2021-11-11 10:36:01 -07:00
Brandon Croft 9441666d9a
Merge pull request #29903 from hashicorp/pull-mock-gotfe-changes
Pull changes made to mocks in go-tfe
2021-11-11 10:12:09 -07:00
Chris Arcand 21750037d5 cloud: Help output typos 2021-11-08 22:07:37 -06:00
uturunku1 58304b678c import path to go mocks in tfe 2021-11-08 08:58:56 -08:00
Luces Huayhuaca 4e3218b4d5
cloud: convert uses of worspaces.operations into workspaces.executionMode (#29844)
* convert uses of worspaces.operations into workspaces.executionMode

The cloud package currently uses a deprecated API on workspaces to determine a workspace's execution mode.

Deprecated: Operations (boolean)
New hotness: Execution mode (string - "local", "remote", or "agent")

More details: https://www.terraform.io/docs/cloud/api/workspaces.html#request-body

All uses of Operations field coming from the client (within the cloud package) should be converted to the appropriate ExecutionMode equivalent.
Also, we need to update all acknowledgment of operations field on the tests that are testing the behavior of workspaces.

Co-authored-by: Nick Fagerlund <nick.fagerlund@gmail.com>

Co-authored-by: Nick Fagerlund <nick.fagerlund@gmail.com>
2021-11-08 07:20:15 -08:00
Omar Ismail 1da7031855 cloud: Add tags to workspace if necessary when fetching state 2021-11-02 16:18:17 -05:00
Barrett Clark 9c13521d76 Allow cloud tests to be run in parallel
Add the `-parallel N` switch to tell the tests to run in N processes:

```
TFE_TOKEN=$TFE_TOKEN TFE_HOSTNAME=$TFE_HOSTNAME TF_ACC=1 go test -v \
  -tags=e2e ./internal/cloud/e2e/... -parallel 4
```
2021-11-01 13:58:29 -05:00
Nick Fagerlund 02e62c9851
Cloud: Init without erroring when no workspaces match the `tags` (#29835)
Previously, `terraform init` was throwing an error if you configured the cloud
block with `tags` and there weren't any tagged workspaces yet. Confusing and
alienating, since that that's a fairly normal situation! Basically TFC was
handling an empty list of workspaces worse than other backends, because it
doesn't support an unnamed default workspace.

This commit catches that condition during `Meta.selectBackend()` and asks the
user to pick a name for their first tagged workspace. If they cancel out, we
still error, but if we know what name they want, we can handle it the same way
as a nonexistent workspace specified in `name` -- just pass it to
`Meta.SetWorkspace()`, and let the workspace get implicitly created when
`InitCommand.Run()` eventually calls `StateMgr()`.
2021-11-01 10:20:15 -07:00
Alisdair McDiarmid a61bd8a96b cloud: Fix prerelease version constraint checks 2021-11-01 11:12:58 -04:00
Chris Arcand 14260a5b4c Adjust default workspace naming prompt
The previous version is a little overdramatic and somewhat accusatory.
Just lay it out how it is: TFC needs workspaces to be named.
2021-10-28 19:29:21 -05:00
Brandon Croft 6d9c919f55 adds X-Terraform-Integration header
This can help differentiate cloud integration API requests from normal remote backend requests
2021-10-28 19:29:20 -05:00
Chris Arcand 3d23a8e062 cloud: Fix version check regression
When the 'select the exact version if possible' behavior was added, the
version check below it was never updated to take the newly updated
version in to account, resulting in a failed version check even as the
remote workspace updated to the correct version necessary.
2021-10-28 19:29:20 -05:00
Chris Arcand 652a68715f cloud/e2e: Misc test fixes 2021-10-28 19:29:20 -05:00
Chris Arcand f881c2d794 cloud: Skip E2E tests without an exact version 2021-10-28 19:29:20 -05:00
Chris Arcand e364ef2905 cloud/e2e: Disable cost estimation
E2E tests including cost estimation should indeed be added, but the
default case should be disabled; lots of cycles lost to pointless cost
estimates on null and random resources.
2021-10-28 19:29:19 -05:00
Omar Ismail fc5863844c Cloud migration: ignore backend version check when empty worksapces 2021-10-28 19:29:19 -05:00
Nick Fagerlund fabd8eb0b6 Fix broken rename behavior in tfe_client_mock.go
The delete + assign at the end of `Update` and `UpdateByID` are meant to handle
renaming a workspace — (remove old name), (insert new name).

However, `UpdateByID` was doing (remove new name), (insert new name) and leaving
the old name in place. This commit changes it to match `Update` by grabbing the
original name off the workspace object _before_ potentially renaming it.
2021-10-28 19:29:18 -05:00
Chris Arcand 50997d9a32 Restore API version checking, with internal usage accounted for 2021-10-28 19:29:18 -05:00
Nick Fagerlund cb26cbba22 Add tests for cloud.StateMgr() when TFC lacks local tf version
Alas, there's not a very good way to test the message we're supposed to print to
the console in this situation; we just don't appear to have a mock terminal that
the test can read from. But we can at least test that the function returns
without erroring under the exact conditions where it was erroring before.

Note that the behaviors of mc.Workspaces.Update and UpdateByID were already
starting to drift, so I consolidated their actual attribute update logic into a
helper function before they drifted much further.
2021-10-28 19:29:18 -05:00
Nick Fagerlund c99f5972de cloud.StateMgr(): Set terraform version AFTER creating workspace
Previously, if the remote TFC/TFE instance doesn't happen to have a tool_version
record whose name exactly matches the value of `tfversion.String()`, Terraform
would be completely blocked from using the `terraform workspace new` command
(when configured with the tags strategy) — the API would give a 422 to the
whole create request.

This commit changes the StateMgr() function to do the work in two passes; first
create the workspace (which should work fine regardless), THEN update the
Terraform version and print a warning to the terminal if it fails (which 99% of
the time is a benign failure with little impact on your future CLI usage).
2021-10-28 19:29:18 -05:00
Chris Arcand aace0015c2 cloud: Fix E2E variables test 2021-10-28 19:29:17 -05:00
Brandon Croft 64fbb0b613 remove reference to AccessInternalTools 2021-10-28 19:29:17 -05:00
Chris Arcand 12a4af3e72 Temporarily skip API version checking 2021-10-28 19:29:16 -05:00
Barrett Clark ab304d831f Found another path to backend init error
There are actually a few different ways to get to this message.

1. Blank state — no previous terraform applied. Start with a cloud block.
1. Implicit local — start with no backend specified. This actually goes
   through the same code execution path as the first scenario.
1. Explicit local — start with a backend local block that has been
   applied, then change from the local backend to a cloud block. This
   will recognize the state, and is a different path through the code in
   the meta backend.

This commit handles the last case. The messaging has also been tweaked.

End to end test included as well.
2021-10-28 19:29:16 -05:00
Omar Ismail 5ff2495ffa Update HasResource to HasManagedResourceInstanceObjects 2021-10-28 19:29:15 -05:00
Omar Ismail 86f93a2cbc Cloud UX test fixes 2021-10-28 19:29:15 -05:00
Omar Ismail dfb4609be2 Backend State Migration from cloud to cloud.
* Add test for tfc to tfc mgiration
* Fix old tests, and remove unused code.
2021-10-28 19:29:15 -05:00