Skip to content

Commit af0a606

Browse files
authored
Merge pull request #575 from hashicorp/TF-1450
Add OPA support for Policy Set API's
2 parents 804748d + 15525b2 commit af0a606

8 files changed

+397
-32
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Unreleased
2+
3+
## Enhancements
4+
5+
* Add OPA support to the Policy Set API's by @mrinalirao [#575](https://github.com/hashicorp/go-tfe/pull/575)
6+
17
# v1.12.0
28

39
## Enhancements

helper_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func createPolicySetParameter(t *testing.T, client *Client, ps *PolicySet) (*Pol
499499
var psCleanup func()
500500

501501
if ps == nil {
502-
ps, psCleanup = createPolicySet(t, client, nil, nil, nil)
502+
ps, psCleanup = createPolicySet(t, client, nil, nil, nil, "")
503503
}
504504

505505
ctx := context.Background()
@@ -525,7 +525,7 @@ func createPolicySetParameter(t *testing.T, client *Client, ps *PolicySet) (*Pol
525525
}
526526
}
527527

528-
func createPolicySet(t *testing.T, client *Client, org *Organization, policies []*Policy, workspaces []*Workspace) (*PolicySet, func()) {
528+
func createPolicySet(t *testing.T, client *Client, org *Organization, policies []*Policy, workspaces []*Workspace, kind PolicyKind) (*PolicySet, func()) {
529529
var orgCleanup func()
530530

531531
if org == nil {
@@ -537,6 +537,7 @@ func createPolicySet(t *testing.T, client *Client, org *Organization, policies [
537537
Name: String(randomString(t)),
538538
Policies: policies,
539539
Workspaces: workspaces,
540+
Kind: kind,
540541
})
541542
if err != nil {
542543
t.Fatal(err)
@@ -559,7 +560,7 @@ func createPolicySetVersion(t *testing.T, client *Client, ps *PolicySet) (*Polic
559560
var psCleanup func()
560561

561562
if ps == nil {
562-
ps, psCleanup = createPolicySet(t, client, nil, nil, nil)
563+
ps, psCleanup = createPolicySet(t, client, nil, nil, nil, "")
563564
}
564565

565566
ctx := context.Background()

policy_check_integration_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestPolicyChecksList(t *testing.T) {
3131
defer policyCleanup2()
3232
wTest, wsCleanup := createWorkspace(t, client, orgTest)
3333
defer wsCleanup()
34-
createPolicySet(t, client, orgTest, []*Policy{pTest1, pTest2}, []*Workspace{wTest})
34+
createPolicySet(t, client, orgTest, []*Policy{pTest1, pTest2}, []*Workspace{wTest}, "")
3535

3636
rTest, runCleanup := createPolicyCheckedRun(t, client, wTest)
3737
defer runCleanup()
@@ -95,7 +95,7 @@ func TestPolicyChecksRead(t *testing.T) {
9595

9696
pTest, _ := createUploadedPolicy(t, client, true, orgTest)
9797
wTest, _ := createWorkspace(t, client, orgTest)
98-
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest})
98+
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest}, "")
9999

100100
rTest, _ := createPolicyCheckedRun(t, client, wTest)
101101
require.Equal(t, 1, len(rTest.PolicyChecks))
@@ -142,7 +142,7 @@ func TestPolicyChecksOverride(t *testing.T) {
142142

143143
wTest, wTestCleanup := createWorkspace(t, client, orgTest)
144144
defer wTestCleanup()
145-
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest})
145+
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest}, "")
146146
rTest, tTestCleanup := createPolicyCheckedRun(t, client, wTest)
147147
defer tTestCleanup()
148148

@@ -167,7 +167,7 @@ func TestPolicyChecksOverride(t *testing.T) {
167167

168168
wTest, wTestCleanup := createWorkspace(t, client, orgTest)
169169
defer wTestCleanup()
170-
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest})
170+
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest}, "")
171171
rTest, rTestCleanup := createPolicyCheckedRun(t, client, wTest)
172172
defer rTestCleanup()
173173

@@ -201,7 +201,7 @@ func TestPolicyChecksLogs(t *testing.T) {
201201
defer pTestCleanup()
202202
wTest, wTestCleanup := createWorkspace(t, client, orgTest)
203203
defer wTestCleanup()
204-
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest})
204+
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest}, "")
205205

206206
rTest, rTestCleanup := createPolicyCheckedRun(t, client, wTest)
207207
defer rTestCleanup()

policy_set.go

+33-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import (
1010
// Compile-time proof of interface implementation.
1111
var _ PolicySets = (*policySets)(nil)
1212

13+
// PolicyKind is an indicator of the underlying technology that the policy or policy set supports.
14+
// There are two kinds documented in the enum.
15+
type PolicyKind string
16+
17+
const (
18+
OPA PolicyKind = "opa"
19+
Sentinel PolicyKind = "sentinel"
20+
)
21+
1322
// PolicySets describes all the policy set related methods that the Terraform
1423
// Enterprise API supports.
1524
//
@@ -61,16 +70,18 @@ type PolicySetList struct {
6170

6271
// PolicySet represents a Terraform Enterprise policy set.
6372
type PolicySet struct {
64-
ID string `jsonapi:"primary,policy-sets"`
65-
Name string `jsonapi:"attr,name"`
66-
Description string `jsonapi:"attr,description"`
67-
Global bool `jsonapi:"attr,global"`
68-
PoliciesPath string `jsonapi:"attr,policies-path"`
69-
PolicyCount int `jsonapi:"attr,policy-count"`
70-
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
71-
WorkspaceCount int `jsonapi:"attr,workspace-count"`
72-
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
73-
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
73+
ID string `jsonapi:"primary,policy-sets"`
74+
Name string `jsonapi:"attr,name"`
75+
Description string `jsonapi:"attr,description"`
76+
Kind PolicyKind `jsonapi:"attr,kind"`
77+
Overridable *bool `jsonapi:"attr,overridable"`
78+
Global bool `jsonapi:"attr,global"`
79+
PoliciesPath string `jsonapi:"attr,policies-path"`
80+
PolicyCount int `jsonapi:"attr,policy-count"`
81+
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
82+
WorkspaceCount int `jsonapi:"attr,workspace-count"`
83+
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
84+
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
7485

7586
// Relations
7687
// The organization to which the policy set belongs to.
@@ -105,6 +116,10 @@ type PolicySetListOptions struct {
105116
// Optional: A search string (partial policy set name) used to filter the results.
106117
Search string `url:"search[name],omitempty"`
107118

119+
// **Note: This field is still in BETA and subject to change.**
120+
// Optional: A kind string used to filter the results by the policy set kind.
121+
Kind PolicyKind `url:"filter[kind],omitempty"`
122+
108123
// Optional: A list of relations to include. See available resources
109124
// https://www.terraform.io/cloud-docs/api-docs/policy-sets#available-related-resources
110125
Include []PolicySetIncludeOpt `url:"include,omitempty"`
@@ -136,6 +151,14 @@ type PolicySetCreateOptions struct {
136151
// Optional: Whether or not the policy set is global.
137152
Global *bool `jsonapi:"attr,global,omitempty"`
138153

154+
// **Note: This field is still in BETA and subject to change.**
155+
// Optional: The underlying technology that the policy set supports
156+
Kind PolicyKind `jsonapi:"attr,kind,omitempty"`
157+
158+
// **Note: This field is still in BETA and subject to change.**
159+
// Optional: Whether or not users can override this policy when it fails during a run. Only valid for OPA policies.
160+
Overridable *bool `jsonapi:"attr,overridable,omitempty"`
161+
139162
// Optional: The sub-path within the attached VCS repository to ingress. All
140163
// files and directories outside of this sub-path will be ignored.
141164
// This option may only be specified when a VCS repo is present.

0 commit comments

Comments
 (0)