diff --git a/CHANGELOG.md b/CHANGELOG.md index ef8d843e5..166e6da87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,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 [#497](https://github.com/hashicorp/go-tfe/pull/497) * Allow FileTriggersEnabled to be set to false when Git tags are present by @mjyocca @hashimoon [#468] (https://github.com/hashicorp/go-tfe/pull/468) # v1.6.0 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) {