From 72f7d466cb9d99166f7a9d7176fde5246650625a Mon Sep 17 00:00:00 2001 From: uk1288 Date: Wed, 10 Aug 2022 12:42:37 -0400 Subject: [PATCH 1/2] add Include param to policyset list --- CHANGELOG.md | 2 +- policy_set.go | 4 ++++ policy_set_integration_test.go | 39 ++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9999308e8..074770371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * Adds additional Task Stage and Run Statuses for Pre-plan run tasks by @glennsarti [#469](https://github.com/hashicorp/go-tfe/pull/469) * Adds `stage` field to the create and update methods for Workspace Run Tasks by @glennsarti [#469](https://github.com/hashicorp/go-tfe/pull/469) * Adds `ResourcesProcessed`, `StateVersion`, `TerraformVersion`, `Modules`, `Providers`, and `Resources` fields to the State Version struct by @laurenolivia [#484](https://github.com/hashicorp/go-tfe/pull/484) - +* Add `Include` param field to `PolicySetListOptions` to allow policy list to include related resource data such as workspaces, policies, newest_version, or current_version by @Uk1288 [#471](https://github.com/hashicorp/go-tfe/pull/471) # v1.6.0 ## Enhancements diff --git a/policy_set.go b/policy_set.go index b2157b0f7..85207a1f7 100644 --- a/policy_set.go +++ b/policy_set.go @@ -104,6 +104,10 @@ type PolicySetListOptions struct { // Optional: A search string (partial policy set name) used to filter the results. Search string `url:"search[name],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"` } // PolicySetReadOptions are read options. diff --git a/policy_set_integration_test.go b/policy_set_integration_test.go index f1b7e6761..2fcc06f16 100644 --- a/policy_set_integration_test.go +++ b/policy_set_integration_test.go @@ -23,9 +23,14 @@ func TestPolicySetsList(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() - psTest1, psTestCleanup1 := createPolicySet(t, client, orgTest, nil, nil) + upgradeOrganizationSubscription(t, client, orgTest) + + workspace, workspaceCleanup := createWorkspace(t, client, orgTest) + defer workspaceCleanup() + + psTest1, psTestCleanup1 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}) defer psTestCleanup1() - psTest2, psTestCleanup2 := createPolicySet(t, client, orgTest, nil, nil) + psTest2, psTestCleanup2 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}) defer psTestCleanup2() t.Run("without list options", func(t *testing.T) { @@ -69,6 +74,19 @@ func TestPolicySetsList(t *testing.T) { assert.Equal(t, 1, psl.TotalCount) }) + t.Run("with include param", func(t *testing.T) { + psl, err := client.PolicySets.List(ctx, orgTest.Name, &PolicySetListOptions{ + Include: []PolicySetIncludeOpt{PolicySetWorkspaces}, + }) + require.NoError(t, err) + + assert.Equal(t, 2, len(psl.Items)) + + assert.NotNil(t, psl.Items[0].Workspaces) + assert.Equal(t, 1, len(psl.Items[0].Workspaces)) + assert.Equal(t, workspace.ID, psl.Items[0].Workspaces[0].ID) + }) + t.Run("without a valid organization", func(t *testing.T) { ps, err := client.PolicySets.List(ctx, badIdentifier, nil) assert.Nil(t, ps) @@ -84,6 +102,9 @@ func TestPolicySetsCreate(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + + upgradeOrganizationSubscription(t, client, orgTest) + var vcsPolicyID string t.Run("with valid attributes", func(t *testing.T) { @@ -245,6 +266,8 @@ func TestPolicySetsRead(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + psTest, psTestCleanup := createPolicySet(t, client, orgTest, nil, nil) defer psTestCleanup() @@ -311,6 +334,8 @@ func TestPolicySetsUpdate(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + psTest, psTestCleanup := createPolicySet(t, client, orgTest, nil, nil) defer psTestCleanup() @@ -355,6 +380,8 @@ func TestPolicySetsAddPolicies(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + pTest1, pTestCleanup1 := createPolicy(t, client, orgTest) defer pTestCleanup1() pTest2, pTestCleanup2 := createPolicy(t, client, orgTest) @@ -410,6 +437,8 @@ func TestPolicySetsRemovePolicies(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + pTest1, pTestCleanup1 := createPolicy(t, client, orgTest) defer pTestCleanup1() pTest2, pTestCleanup2 := createPolicy(t, client, orgTest) @@ -459,6 +488,8 @@ func TestPolicySetsAddWorkspaces(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + wTest1, wTestCleanup1 := createWorkspace(t, client, orgTest) defer wTestCleanup1() wTest2, wTestCleanup2 := createWorkspace(t, client, orgTest) @@ -528,6 +559,8 @@ func TestPolicySetsRemoveWorkspaces(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + wTest1, wTestCleanup1 := createWorkspace(t, client, orgTest) defer wTestCleanup1() wTest2, wTestCleanup2 := createWorkspace(t, client, orgTest) @@ -591,6 +624,8 @@ func TestPolicySetsDelete(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + psTest, _ := createPolicySet(t, client, orgTest, nil, nil) t.Run("with valid options", func(t *testing.T) { From 4a4c1d899c00dc941241ee910b9eed61b5d9d293 Mon Sep 17 00:00:00 2001 From: UKEME BASSEY Date: Wed, 10 Aug 2022 12:46:53 -0400 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 074770371..b516b2029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ * Adds additional Task Stage and Run Statuses for Pre-plan run tasks by @glennsarti [#469](https://github.com/hashicorp/go-tfe/pull/469) * Adds `stage` field to the create and update methods for Workspace Run Tasks by @glennsarti [#469](https://github.com/hashicorp/go-tfe/pull/469) * Adds `ResourcesProcessed`, `StateVersion`, `TerraformVersion`, `Modules`, `Providers`, and `Resources` fields to the State Version struct by @laurenolivia [#484](https://github.com/hashicorp/go-tfe/pull/484) -* Add `Include` param field to `PolicySetListOptions` to allow policy list to include related resource data such as workspaces, policies, newest_version, or current_version by @Uk1288 [#471](https://github.com/hashicorp/go-tfe/pull/471) +* Add `Include` param field to `PolicySetListOptions` to allow policy list to include related resource data such as workspaces, policies, newest_version, or current_version by @Uk1288 [#497](https://github.com/hashicorp/go-tfe/pull/497) + # v1.6.0 ## Enhancements