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

Support for Policy Evaluation and Policy set outcome API's #583

Merged
merged 3 commits into from Nov 10, 2022

Conversation

mrinalirao
Copy link
Contributor

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 Policy Evaluations and Policy Set Outcome API's.

API Docs

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

Added Api's:

  • List Policy Evaluations in the task stage
  • List Policy Set Outcomes in a Policy Evaluation
  • Read a Policy Set Outcome by ID

Testing plan

Integration tests added

External links

API Docs
JIRA
API PR

Output from tests

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

=== RUN   TestPolicyEvaluationList_Beta
=== RUN   TestPolicyEvaluationList_Beta/with_no_params
=== RUN   TestPolicyEvaluationList_Beta/with_a_invalid_policy_evaluation_ID
--- PASS: TestPolicyEvaluationList_Beta (14.43s)
    --- PASS: TestPolicyEvaluationList_Beta/with_no_params (1.58s)
    --- PASS: TestPolicyEvaluationList_Beta/with_a_invalid_policy_evaluation_ID (0.00s)
PASS
ok      github.com/hashicorp/go-tfe     15.405s
?       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 TestPolicySetOutcomeList_Beta -v ./... -tags=integration

=== RUN   TestPolicySetOutcomeList_Beta
    helper_test.go:1007: Polling run "run-FxstkYuPXYpR9uax" for status included in ["cost_estimated" "errored"] with deadline of 2022-11-10 11:49:31.612407 +1100 AEDT m=+143.711234960
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "plan_queued"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "planning"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "planning"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "planning"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "post_plan_running"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "post_plan_running"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "post_plan_running"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "post_plan_running"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "post_plan_running"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "cost_estimating"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-FxstkYuPXYpR9uax"
    helper_test.go:1019: Run "run-FxstkYuPXYpR9uax" had status "cost_estimated"
--- PASS: TestPolicySetOutcomeList_Beta (69.26s)
=== RUN   TestPolicySetOutcomeList_Beta/with_no_params
    --- PASS: TestPolicySetOutcomeList_Beta/with_no_params (16.89s)
=== RUN   TestPolicySetOutcomeList_Beta/with_non-matching_filters
    --- PASS: TestPolicySetOutcomeList_Beta/with_non-matching_filters (2.90s)
=== RUN   TestPolicySetOutcomeList_Beta/with_matching_filters
    --- PASS: TestPolicySetOutcomeList_Beta/with_matching_filters (2.44s)
PASS

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

=== RUN   TestPolicySetOutcomeRead_Beta
    helper_test.go:1007: Polling run "run-44s7vV1kQ6H5pTir" for status included in ["cost_estimated" "errored"] with deadline of 2022-11-10 12:00:39.978661 +1100 AEDT m=+139.208576626
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "plan_queued"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "planning"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "planning"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "planning"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "planning"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "post_plan_running"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "post_plan_running"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "cost_estimating"
    helper_test.go:1013: ...
    helper_test.go:1034: Reading run "run-44s7vV1kQ6H5pTir"
    helper_test.go:1019: Run "run-44s7vV1kQ6H5pTir" had status "cost_estimated"
--- PASS: TestPolicySetOutcomeRead_Beta (142.16s)
=== RUN   TestPolicySetOutcomeRead_Beta/with_a_valid_policy_set_outcome_ID
    --- PASS: TestPolicySetOutcomeRead_Beta/with_a_valid_policy_set_outcome_ID (89.92s)
=== RUN   TestPolicySetOutcomeRead_Beta/with_a_invalid_policy_set_outcome_ID
    --- PASS: TestPolicySetOutcomeRead_Beta/with_a_invalid_policy_set_outcome_ID (13.68s)
PASS

  - List Policy evaluations in a task stage
  - List/Read Policy set outcomes in a policy evaluation
@mrinalirao mrinalirao requested a review from a team as a code owner November 10, 2022 01:27
helper_test.go Outdated Show resolved Hide resolved
policy_evaluation.go Outdated Show resolved Hide resolved
policy_evaluation.go Outdated Show resolved Hide resolved
task_stages.go Outdated Show resolved Hide resolved
cam-stitt
cam-stitt previously approved these changes Nov 10, 2022
policy_evaluation.go Outdated Show resolved Hide resolved
glennsarti
glennsarti previously approved these changes Nov 10, 2022
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@mrinalirao mrinalirao merged commit f2188c9 into main Nov 10, 2022
@mrinalirao mrinalirao deleted the mr/TF-1450-policy-evaluation branch November 10, 2022 22:15
@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

4 participants