Skip to content

Commit

Permalink
Merge branch 'main' into TF-1450-policies
Browse files Browse the repository at this point in the history
# Conflicts:
#	policy_set.go
  • Loading branch information
mrinalirao committed Nov 2, 2022
2 parents 9e2a6f6 + af0a606 commit 7aaf233
Show file tree
Hide file tree
Showing 13 changed files with 526 additions and 37 deletions.
14 changes: 11 additions & 3 deletions CHANGELOG.md
Expand Up @@ -2,9 +2,20 @@

## Enhancements

* Add OPA support to the Policy Set API's by @mrinalirao [#575](https://github.com/hashicorp/go-tfe/pull/575)

# v1.12.0

## Enhancements

* Add `search[wildcard-name]` to `WorkspaceListOptions` by @laurenolivia [#569](https://github.com/hashicorp/go-tfe/pull/569)
* Add `NotificationTriggerAssessmentCheckFailed` notification trigger type by @rexredinger [#549](https://github.com/hashicorp/go-tfe/pull/549)
* Add `RemoteTFEVersion()` to the `Client` interface, which exposes the `X-TFE-Version` header set by a remote TFE instance by @sebasslash [#563](https://github.com/hashicorp/go-tfe/pull/563)
* Validate the module version as a version instead of an ID [#409](https://github.com/hashicorp/go-tfe/pull/409)
* Add `AllowForceDeleteWorkspaces` setting to `Organizations` by @JarrettSpiker [#539](https://github.com/hashicorp/go-tfe/pull/539)
* Add `SafeDelete` and `SafeDeleteID` APIs to `Workspaces` by @JarrettSpiker [#539](https://github.com/hashicorp/go-tfe/pull/539)
* Add `ForceExecute()` to `Runs` to allow force executing a run by @annawinkler [#570](https://github.com/hashicorp/go-tfe/pull/570)
* Pre-plan and Pre-Apply Run Tasks are now generally available (beta comments removed) by @glennsarti [#555](https://github.com/hashicorp/go-tfe/pull/555)

# v1.11.0

Expand All @@ -13,9 +24,6 @@
* Add `Query` and `Status` fields to `OrganizationMembershipListOptions` to allow filtering memberships by status or username by @sebasslash [#550](https://github.com/hashicorp/go-tfe/pull/550)
* Add `ListForWorkspace` method to `VariableSets` interface to enable fetching variable sets associated with a workspace by @tstapler [#552](https://github.com/hashicorp/go-tfe/pull/552)
* Add `NotificationTriggerAssessmentDrifted` and `NotificationTriggerAssessmentFailed` notification trigger types by @lawliet89 [#542](https://github.com/hashicorp/go-tfe/pull/542)
* Add `AllowForceDeleteWorkspaces` setting to `Organizations` by @JarrettSpiker [#539](https://github.com/hashicorp/go-tfe/pull/539)
* Add `SafeDelete` and `SafeDeleteID` APIs to `Workspaces` by @JarrettSpiker [#539](https://github.com/hashicorp/go-tfe/pull/539)


## Bug Fixes
* Fix marshalling of run variables in `RunCreateOptions`. The `Variables` field type in `Run` struct has changed from `[]*RunVariable` to `[]*RunVariableAttr` by @Uk1288 [#531](https://github.com/hashicorp/go-tfe/pull/531)
Expand Down
7 changes: 4 additions & 3 deletions helper_test.go
Expand Up @@ -499,7 +499,7 @@ func createPolicySetParameter(t *testing.T, client *Client, ps *PolicySet) (*Pol
var psCleanup func()

if ps == nil {
ps, psCleanup = createPolicySet(t, client, nil, nil, nil)
ps, psCleanup = createPolicySet(t, client, nil, nil, nil, "")
}

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

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

if org == nil {
Expand All @@ -537,6 +537,7 @@ func createPolicySet(t *testing.T, client *Client, org *Organization, policies [
Name: String(randomString(t)),
Policies: policies,
Workspaces: workspaces,
Kind: kind,
})
if err != nil {
t.Fatal(err)
Expand All @@ -559,7 +560,7 @@ func createPolicySetVersion(t *testing.T, client *Client, ps *PolicySet) (*Polic
var psCleanup func()

if ps == nil {
ps, psCleanup = createPolicySet(t, client, nil, nil, nil)
ps, psCleanup = createPolicySet(t, client, nil, nil, nil, "")
}

ctx := context.Background()
Expand Down
14 changes: 14 additions & 0 deletions mocks/run_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions policy_check_integration_test.go
Expand Up @@ -31,7 +31,7 @@ func TestPolicyChecksList(t *testing.T) {
defer policyCleanup2()
wTest, wsCleanup := createWorkspace(t, client, orgTest)
defer wsCleanup()
createPolicySet(t, client, orgTest, []*Policy{pTest1, pTest2}, []*Workspace{wTest})
createPolicySet(t, client, orgTest, []*Policy{pTest1, pTest2}, []*Workspace{wTest}, "")

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

pTest, _ := createUploadedPolicy(t, client, true, orgTest)
wTest, _ := createWorkspace(t, client, orgTest)
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest})
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest}, "")

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

wTest, wTestCleanup := createWorkspace(t, client, orgTest)
defer wTestCleanup()
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest})
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest}, "")
rTest, tTestCleanup := createPolicyCheckedRun(t, client, wTest)
defer tTestCleanup()

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

wTest, wTestCleanup := createWorkspace(t, client, orgTest)
defer wTestCleanup()
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest})
createPolicySet(t, client, orgTest, []*Policy{pTest}, []*Workspace{wTest}, "")
rTest, rTestCleanup := createPolicyCheckedRun(t, client, wTest)
defer rTestCleanup()

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

rTest, rTestCleanup := createPolicyCheckedRun(t, client, wTest)
defer rTestCleanup()
Expand Down
36 changes: 25 additions & 11 deletions policy_set.go
Expand Up @@ -11,7 +11,7 @@ import (
var _ PolicySets = (*policySets)(nil)

// PolicyKind is an indicator of the underlying technology that the policy or policy set supports.
// There are two Policykinds documented in the enum.
// There are two kinds documented in the enum.
type PolicyKind string

const (
Expand Down Expand Up @@ -70,16 +70,18 @@ type PolicySetList struct {

// PolicySet represents a Terraform Enterprise policy set.
type PolicySet struct {
ID string `jsonapi:"primary,policy-sets"`
Name string `jsonapi:"attr,name"`
Description string `jsonapi:"attr,description"`
Global bool `jsonapi:"attr,global"`
PoliciesPath string `jsonapi:"attr,policies-path"`
PolicyCount int `jsonapi:"attr,policy-count"`
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
WorkspaceCount int `jsonapi:"attr,workspace-count"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
ID string `jsonapi:"primary,policy-sets"`
Name string `jsonapi:"attr,name"`
Description string `jsonapi:"attr,description"`
Kind PolicyKind `jsonapi:"attr,kind"`
Overridable *bool `jsonapi:"attr,overridable"`
Global bool `jsonapi:"attr,global"`
PoliciesPath string `jsonapi:"attr,policies-path"`
PolicyCount int `jsonapi:"attr,policy-count"`
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
WorkspaceCount int `jsonapi:"attr,workspace-count"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`

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

// **Note: This field is still in BETA and subject to change.**
// Optional: A kind string used to filter the results by the policy set kind.
Kind PolicyKind `url:"filter[kind],omitempty"`

// Optional: A list of relations to include. See available resources
// https://www.terraform.io/cloud-docs/api-docs/policy-sets#available-related-resources
Include []PolicySetIncludeOpt `url:"include,omitempty"`
Expand Down Expand Up @@ -145,6 +151,14 @@ type PolicySetCreateOptions struct {
// Optional: Whether or not the policy set is global.
Global *bool `jsonapi:"attr,global,omitempty"`

// **Note: This field is still in BETA and subject to change.**
// Optional: The underlying technology that the policy set supports
Kind PolicyKind `jsonapi:"attr,kind,omitempty"`

// **Note: This field is still in BETA and subject to change.**
// Optional: Whether or not users can override this policy when it fails during a run. Only valid for OPA policies.
Overridable *bool `jsonapi:"attr,overridable,omitempty"`

// Optional: The sub-path within the attached VCS repository to ingress. All
// files and directories outside of this sub-path will be ignored.
// This option may only be specified when a VCS repo is present.
Expand Down

0 comments on commit 7aaf233

Please sign in to comment.