Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OPA support for task stages #584

Merged
merged 6 commits into from Nov 14, 2022
Merged

Conversation

mrinalirao
Copy link
Contributor

@mrinalirao mrinalirao commented Nov 10, 2022

Description

Add OPA support to the go-tfe client for policy API's. OPA is still in beta phase.

This PR only contains changes to the Task Stage API.

API Docs

For a complete list of API's that were updated see : https://github.com/hashicorp/terraform-docs-common/pull/141/files

Added Api's:

-Task stage override

Testing plan

Integration tests added

External links

API Docs
JIRA
API PR

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

$ envchain local go test -run TestTaskStagesRead -v ./... -tags=integration

=== RUN   TestTaskStagesRead_Beta
--- PASS: TestTaskStagesRead_Beta (35.77s)
=== RUN   TestTaskStagesRead_Beta/without_read_options
    --- PASS: TestTaskStagesRead_Beta/without_read_options (0.20s)
=== RUN   TestTaskStagesRead_Beta/with_include_param_task_results
    --- PASS: TestTaskStagesRead_Beta/with_include_param_task_results (0.21s)
=== RUN   TestTaskStagesRead_Beta/with_include_param_task_results/task_results_are_properly_decoded
        --- PASS: TestTaskStagesRead_Beta/with_include_param_task_results/task_results_are_properly_decoded (0.00s)
=== RUN   TestTaskStagesRead_Beta/with_include_param_task_results/policy_evaluations_are_properly_decoded
        --- PASS: TestTaskStagesRead_Beta/with_include_param_task_results/policy_evaluations_are_properly_decoded (0.00s)
PASS
ok      github.com/hashicorp/go-tfe     19.201s
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]

$ envchain local go test -run TestTaskStagesList_Beta -v ./... -tags=integration

=== RUN   TestTaskStagesList_Beta
--- PASS: TestTaskStagesList_Beta (25.35s)
=== RUN   TestTaskStagesList_Beta/with_no_params
    --- PASS: TestTaskStagesList_Beta/with_no_params (0.23s)
PASS
ok      github.com/hashicorp/go-tfe     26.375s
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]

$ envchain local go test -run TestTaskStageOverride_Beta -v ./... -tags=integration

=== RUN   TestTaskStageOverride_Beta
--- PASS: TestTaskStageOverride_Beta (93.51s)
=== RUN   TestTaskStageOverride_Beta/when_the_policy_failed
    helper_test.go:1037: Polling run "run-ANbRt1ddSdRTCahK" for status included in ["post_plan_awaiting_decision" "errored"] with deadline of 2022-11-10 14:39:28.039298 +1100 AEDT m=+141.946231751
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "plan_queued"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "planning"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "planning"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "post_plan_running"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "post_plan_running"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "post_plan_running"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "post_plan_running"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "post_plan_running"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-ANbRt1ddSdRTCahK"
    helper_test.go:1049: Run "run-ANbRt1ddSdRTCahK" had status "post_plan_awaiting_decision"
    --- PASS: TestTaskStageOverride_Beta/when_the_policy_failed (41.02s)
=== RUN   TestTaskStageOverride_Beta/when_the_policy_passed
    helper_test.go:1037: Polling run "run-QRfJ7f5MdENu3mTD" for status included in ["cost_estimated" "errored"] with deadline of 2022-11-10 14:40:18.011966 +1100 AEDT m=+191.918870751
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-QRfJ7f5MdENu3mTD"
    helper_test.go:1049: Run "run-QRfJ7f5MdENu3mTD" had status "plan_queued"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-QRfJ7f5MdENu3mTD"
    helper_test.go:1049: Run "run-QRfJ7f5MdENu3mTD" had status "planning"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-QRfJ7f5MdENu3mTD"
    helper_test.go:1049: Run "run-QRfJ7f5MdENu3mTD" had status "planning"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-QRfJ7f5MdENu3mTD"
    helper_test.go:1049: Run "run-QRfJ7f5MdENu3mTD" had status "planning"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-QRfJ7f5MdENu3mTD"
    helper_test.go:1049: Run "run-QRfJ7f5MdENu3mTD" had status "post_plan_running"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-QRfJ7f5MdENu3mTD"
    helper_test.go:1049: Run "run-QRfJ7f5MdENu3mTD" had status "post_plan_running"
    helper_test.go:1043: ...
    helper_test.go:1064: Reading run "run-QRfJ7f5MdENu3mTD"
    helper_test.go:1049: Run "run-QRfJ7f5MdENu3mTD" had status "cost_estimated"
    --- PASS: TestTaskStageOverride_Beta/when_the_policy_passed (51.83s)
PASS
ok     github.com/hashicorp/go-tfe     119.055s
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]

 - Added a new API for task stage override
@mrinalirao mrinalirao requested a review from a team as a code owner November 10, 2022 03:51
Base automatically changed from mr/TF-1450-policy-evaluation to main November 10, 2022 22:15
run.go Outdated Show resolved Hide resolved
task_stages.go Outdated Show resolved Hide resolved
@mrinalirao
Copy link
Contributor Author

Added test for passing optional comment into the Override API:

$ envchain local go test -run TestTaskStageOverride_Beta -v ./... -tags=integration

=== RUN   TestTaskStageOverride_Beta
--- PASS: TestTaskStageOverride_Beta (201.95s)
=== RUN   TestTaskStageOverride_Beta/when_the_policy_failed
    helper_test.go:1038: Polling run "run-JRmxhdQ9MS4jaz56" for status included in ["post_plan_awaiting_decision" "errored"] with deadline of 2022-11-11 14:19:36.167376 +1100 AEDT m=+151.096747460
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "plan_queued"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-JRmxhdQ9MS4jaz56"
    helper_test.go:1050: Run "run-JRmxhdQ9MS4jaz56" had status "post_plan_awaiting_decision"
    --- PASS: TestTaskStageOverride_Beta/when_the_policy_failed (82.70s)
=== RUN   TestTaskStageOverride_Beta/when_the_policy_failed_with_options
    helper_test.go:1038: Polling run "run-cn4CBHJ2nricvEb4" for status included in ["post_plan_awaiting_decision" "errored"] with deadline of 2022-11-11 14:21:01.832324 +1100 AEDT m=+236.761400418
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-cn4CBHJ2nricvEb4"
    helper_test.go:1050: Run "run-cn4CBHJ2nricvEb4" had status "plan_queued"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-cn4CBHJ2nricvEb4"
    helper_test.go:1050: Run "run-cn4CBHJ2nricvEb4" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-cn4CBHJ2nricvEb4"
    helper_test.go:1050: Run "run-cn4CBHJ2nricvEb4" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-cn4CBHJ2nricvEb4"
    helper_test.go:1050: Run "run-cn4CBHJ2nricvEb4" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-cn4CBHJ2nricvEb4"
    helper_test.go:1050: Run "run-cn4CBHJ2nricvEb4" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-cn4CBHJ2nricvEb4"
    helper_test.go:1050: Run "run-cn4CBHJ2nricvEb4" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-cn4CBHJ2nricvEb4"
    helper_test.go:1050: Run "run-cn4CBHJ2nricvEb4" had status "post_plan_awaiting_decision"
&{ts-HPyoDwZhyZknXz1B post_plan running {0001-01-01 00:00:00 +0000 UTC 2022-11-11 03:19:27 +0000 +0000 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC} 2022-11-11 03:19:01.522 +0000 UTC 2022-11-11 03:19:27.335 +0000 UTC 0x1400000fe60 0x140002341f0 0x1400056c900 [] [0x140002701e0]}
    --- PASS: TestTaskStageOverride_Beta/when_the_policy_failed_with_options (77.08s)
=== RUN   TestTaskStageOverride_Beta/when_the_policy_passed
    helper_test.go:1038: Polling run "run-NbLgbVuBbkbDmyBu" for status included in ["cost_estimated" "errored"] with deadline of 2022-11-11 14:22:09.554191 +1100 AEDT m=+304.483033335
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "plan_queued"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "planning"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "post_plan_running"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "cost_estimating"
    helper_test.go:1044: ...
    helper_test.go:1065: Reading run "run-NbLgbVuBbkbDmyBu"
    helper_test.go:1050: Run "run-NbLgbVuBbkbDmyBu" had status "cost_estimated"
    --- PASS: TestTaskStageOverride_Beta/when_the_policy_passed (41.56s)
PASS

glennsarti
glennsarti previously approved these changes Nov 14, 2022
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have the one question about is-overridable attribute.

What is your expectation about the release timing of this, given that is it still feature flagged in the API?

run.go Outdated Show resolved Hide resolved
task_stages.go Show resolved Hide resolved
task_stages.go Outdated Show resolved Hide resolved
@mrinalirao
Copy link
Contributor Author

What is your expectation about the release timing of this, given that is it still feature flagged in the API?

We would want to release this now since we want to use this version of the client for adding OPA support to both the provider and the cli. We are targeting to get the provider out before year end holidays and the cli before the end of Jan. Once OPA goes to GA, we will come back to this to remove the beta notes.

@mrinalirao mrinalirao merged commit 0f28f32 into main Nov 14, 2022
@mrinalirao mrinalirao deleted the mr/TF-1450-policy-override branch November 14, 2022 23:06
@github-actions
Copy link

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants