Skip to content

Commit 2740507

Browse files
committed
added the data source
1 parent 23a944c commit 2740507

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

internal/provider/data_source_policy_set.go

Lines changed: 14 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,14 @@ func dataSourceTFEPolicySetRead(d *schema.ResourceData, meta interface{}) error
170176
}
171177
d.Set("workspace_ids", workspaceIDs)
172178

179+
var excludedWorkspaceIDs []interface{}
180+
if !policySet.Global {
181+
for _, excludedWorkspace := range policySet.WorkspaceExclusions {
182+
excludedWorkspaceIDs = append(excludedWorkspaceIDs, excludedWorkspace.ID)
183+
}
184+
}
185+
d.Set("excluded_workspace_ids", excludedWorkspaceIDs)
186+
173187
var projectIDs []interface{}
174188
if !policySet.Global {
175189
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" {
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" {
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)