Skip to content

Commit 01abda0

Browse files
authored
Merge pull request #1035 from hashicorp/Netra2104/TF-7898-add_excluded_workspace_ids_to_policy_set
Add excluded_workspace_ids to policy sets data source
2 parents cd7fe71 + 8695677 commit 01abda0

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
BUG FIXES:
44
* `r/tfe_team_project_access`: Fixes a panic that occurs when the client is configured against an older TFE release, by @sebasslash [1011](https://github.com/hashicorp/terraform-provider-tfe/pull/1011)
55
* The provider no longer makes two service discovery requests per provider config, by @brandonc [1034](https://github.com/hashicorp/terraform-provider-tfe/pull/1034)
6+
* `d/tfe_policy_set`: Add `excluded_workspace_ids` attribute, by @Netra2104 [1035](https://github.com/hashicorp/terraform-provider-tfe/pull/1035)
67

78
FEATURES:
89
* `d/tfe_organization_membership`: Add `organization_membership_id` attribute, by @laurenolivia [997](https://github.com/hashicorp/terraform-provider-tfe/pull/997)

internal/provider/data_source_policy_set.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ func dataSourceTFEPolicySet() *schema.Resource {
9898
Computed: true,
9999
},
100100

101+
"excluded_workspace_ids": {
102+
Type: schema.TypeSet,
103+
Elem: &schema.Schema{Type: schema.TypeString},
104+
Computed: true,
105+
},
106+
101107
"project_ids": {
102108
Type: schema.TypeSet,
103109
Elem: &schema.Schema{Type: schema.TypeString},
@@ -170,6 +176,12 @@ func dataSourceTFEPolicySetRead(d *schema.ResourceData, meta interface{}) error
170176
}
171177
d.Set("workspace_ids", workspaceIDs)
172178

179+
var excludedWorkspaceIDs []interface{}
180+
for _, excludedWorkspace := range policySet.WorkspaceExclusions {
181+
excludedWorkspaceIDs = append(excludedWorkspaceIDs, excludedWorkspace.ID)
182+
}
183+
d.Set("excluded_workspace_ids", excludedWorkspaceIDs)
184+
173185
var projectIDs []interface{}
174186
if !policySet.Global {
175187
for _, project := range policySet.Projects {

internal/provider/data_source_policy_set_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func TestAccTFEPolicySetDataSource_basic(t *testing.T) {
4545
"data.tfe_policy_set.bar", "policy_ids.#", "1"),
4646
resource.TestCheckResourceAttr(
4747
"data.tfe_policy_set.bar", "workspace_ids.#", "1"),
48+
resource.TestCheckResourceAttr(
49+
"data.tfe_policy_set.bar", "excluded_workspace_ids.#", "1"),
4850
resource.TestCheckResourceAttr(
4951
"data.tfe_policy_set.bar", "project_ids.#", "1"),
5052
resource.TestCheckResourceAttr(
@@ -90,6 +92,8 @@ func TestAccTFEPolicySetDataSourceOPA_basic(t *testing.T) {
9092
"data.tfe_policy_set.bar", "overridable", "true"),
9193
resource.TestCheckResourceAttr(
9294
"data.tfe_policy_set.bar", "workspace_ids.#", "1"),
95+
resource.TestCheckResourceAttr(
96+
"data.tfe_policy_set.bar", "excluded_workspace_ids.#", "1"),
9397
resource.TestCheckResourceAttr(
9498
"data.tfe_policy_set.bar", "project_ids.#", "1"),
9599
resource.TestCheckResourceAttr(
@@ -149,6 +153,8 @@ func TestAccTFEPolicySetDataSource_vcs(t *testing.T) {
149153
"data.tfe_policy_set.bar", "policy_ids.#", "0"),
150154
resource.TestCheckResourceAttr(
151155
"data.tfe_policy_set.bar", "workspace_ids.#", "0"),
156+
resource.TestCheckResourceAttr(
157+
"data.tfe_policy_set.bar", "excluded_workspace_ids.#", "0"),
152158
resource.TestCheckResourceAttr(
153159
"data.tfe_policy_set.bar", "project_ids.#", "0"),
154160
resource.TestCheckResourceAttr(
@@ -204,14 +210,18 @@ resource "tfe_policy_set" "foobar" {
204210
organization = local.organization_name
205211
policy_ids = [tfe_sentinel_policy.foo.id]
206212
workspace_ids = [tfe_workspace.foobar.id]
207-
208213
}
209214
210215
resource "tfe_project_policy_set" "foobar" {
211216
policy_set_id = tfe_policy_set.foobar.id
212217
project_id = tfe_project.foobar.id
213218
}
214219
220+
resource "tfe_workspace_policy_set_exclusion" "foobar" {
221+
policy_set_id = tfe_policy_set.foobar.id
222+
workspace_id = tfe_workspace.foobar.id
223+
}
224+
215225
data "tfe_policy_set" "bar" {
216226
name = tfe_policy_set.foobar.name
217227
organization = local.organization_name
@@ -248,6 +258,11 @@ resource "tfe_project_policy_set" "foobar" {
248258
project_id = tfe_project.foobar.id
249259
}
250260
261+
resource "tfe_workspace_policy_set_exclusion" "foobar" {
262+
policy_set_id = tfe_policy_set.foobar.id
263+
workspace_id = tfe_workspace.foobar.id
264+
}
265+
251266
data "tfe_policy_set" "bar" {
252267
name = tfe_policy_set.foobar.name
253268
organization = local.organization_name

website/docs/d/policy_set.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The following arguments are supported:
3737
* `kind` - The policy-as-code framework for the policy. Valid values are "sentinel" and "opa".
3838
* `overridable` - Whether users can override this policy when it fails during a run. Only valid for OPA policies.
3939
* `workspace_ids` - IDs of the workspaces that use the policy set.
40+
* `excluded_workspace_ids` - IDs of the workspaces that do not use the policy set.
4041
* `project_ids` - IDs of the projects that use the policy set.
4142
* `policy_ids` - IDs of the policies attached to the policy set.
4243
* `policies_path` - The sub-path within the attached VCS repository when using `vcs_repo`.

0 commit comments

Comments
 (0)