Skip to content

Commit 46cce5a

Browse files
authored
Merge pull request #994 from hashicorp/Netra2104/TF-5323-add-project-ids-to-variable-set-data-source
Add project_ids to variable set data source
2 parents 1ad2646 + f3c8026 commit 46cce5a

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Unreleased
22

3+
FEATURES:
4+
* `d/tfe_variable_set`: Add `project_ids` attribute, by @Netra2104 [994](https://github.com/hashicorp/terraform-provider-tfe/pull/994)
5+
36
## v0.48.0 (August 7, 2023)
47

58
BUG FIXES:

tfe/data_source_variable_set.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func dataSourceTFEVariableSet() *schema.Resource {
4848
Computed: true,
4949
Elem: &schema.Schema{Type: schema.TypeString},
5050
},
51+
52+
"project_ids": {
53+
Type: schema.TypeSet,
54+
Optional: true,
55+
Computed: true,
56+
Elem: &schema.Schema{Type: schema.TypeString},
57+
},
5158
},
5259
}
5360
}
@@ -104,6 +111,12 @@ func dataSourceTFEVariableSetRead(d *schema.ResourceData, meta interface{}) erro
104111
}
105112
d.Set("variable_ids", variables)
106113

114+
var projects []interface{}
115+
for _, project := range vs.Projects {
116+
projects = append(projects, project.ID)
117+
}
118+
d.Set("project_ids", projects)
119+
107120
d.SetId(vs.ID)
108121
return nil
109122
}

tfe/data_source_variable_set_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func TestAccTFEVariableSetsDataSource_full(t *testing.T) {
5656
"data.tfe_variable_set.foobar", "workspace_ids.#", "1"),
5757
resource.TestCheckResourceAttr(
5858
"data.tfe_variable_set.foobar", "variable_ids.#", "1"),
59+
resource.TestCheckResourceAttr(
60+
"data.tfe_variable_set.foobar", "project_ids.#", "1"),
5961
),
6062
},
6163
},
@@ -94,13 +96,23 @@ resource "tfe_workspace" "foobar" {
9496
organization = tfe_organization.foobar.id
9597
}
9698
99+
resource "tfe_project" "foobar" {
100+
name = "project-foo-%d"
101+
organization = tfe_organization.foobar.id
102+
}
103+
97104
resource "tfe_variable_set" "foobar" {
98105
name = "varset-foo-%d"
99106
description = "a description"
100107
organization = tfe_organization.foobar.id
101108
workspace_ids = [tfe_workspace.foobar.id]
102109
}
103110
111+
resource "tfe_project_variable_set" "foobar" {
112+
variable_set_id = tfe_variable_set.foobar.id
113+
project_id = tfe_project.foobar.id
114+
}
115+
104116
resource "tfe_variable" "envfoo" {
105117
key = "vfoo"
106118
value = "bar"
@@ -112,5 +124,5 @@ data "tfe_variable_set" "foobar" {
112124
name = tfe_variable_set.foobar.name
113125
organization = tfe_variable_set.foobar.organization
114126
depends_on = [tfe_variable.envfoo]
115-
}`, rInt, rInt, rInt)
127+
}`, rInt, rInt, rInt, rInt)
116128
}

website/docs/d/variable_set.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ The following arguments are supported:
3636
* `global` - Whether or not the variable set applies to all workspaces in the organization.
3737
* `workspace_ids` - IDs of the workspaces that use the variable set.
3838
* `variable_ids` - IDs of the variables attached to the variable set.
39+
* `project_ids` - IDs of the projects that use the variable set.

0 commit comments

Comments
 (0)