Skip to content

Commit 9fc6b18

Browse files
committed
Add parent project ID to varset data source
1 parent e189f23 commit 9fc6b18

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

internal/provider/data_source_variable_set.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ func dataSourceTFEVariableSet() *schema.Resource {
6565
Computed: true,
6666
Elem: &schema.Schema{Type: schema.TypeString},
6767
},
68+
69+
"parent_project_id": {
70+
Type: schema.TypeString,
71+
Optional: true,
72+
Computed: true,
73+
},
6874
},
6975
}
7076
}
@@ -100,6 +106,10 @@ func dataSourceTFEVariableSetRead(d *schema.ResourceData, meta interface{}) erro
100106
d.Set("global", vs.Global)
101107
d.Set("priority", vs.Priority)
102108

109+
if vs.Parent != nil && vs.Parent.Project != nil {
110+
d.Set("parent_project_id", vs.Parent.Project.ID)
111+
}
112+
103113
// Only now include vars and workspaces to cut down on request load.
104114
readOptions := tfe.VariableSetReadOptions{
105115
Include: &[]tfe.VariableSetIncludeOpt{tfe.VariableSetWorkspaces, tfe.VariableSetVars},

internal/provider/data_source_variable_set_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ func TestAccTFEVariableSetsDataSource_full(t *testing.T) {
6767
)
6868
}
6969

70+
func TestAccTFEVariableSetsDataSource_ProjectOwned(t *testing.T) {
71+
skipUnlessBeta(t)
72+
73+
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
74+
orgName := fmt.Sprintf("org-%d", rInt)
75+
76+
resource.Test(t, resource.TestCase{
77+
PreCheck: func() { testAccPreCheck(t) },
78+
ProtoV5ProviderFactories: testAccMuxedProviders,
79+
Steps: []resource.TestStep{
80+
{
81+
Config: testAccTFEVariableSetsDataSourceConfig_ProjectOwned(rInt),
82+
Check: resource.ComposeAggregateTestCheckFunc(
83+
resource.TestCheckResourceAttrSet("data.tfe_variable_set.project_owned", "id"),
84+
resource.TestCheckResourceAttr(
85+
"data.tfe_variable_set.project_owned", "organization", orgName),
86+
resource.TestCheckResourceAttrPair(
87+
"data.tfe_variable_set.project_owned", "parent_project_id", "tfe_project.foobar", "id"),
88+
),
89+
},
90+
},
91+
},
92+
)
93+
}
94+
7095
func testAccTFEVariableSetsDataSourceConfig_basic(rInt int) string {
7196
return fmt.Sprintf(`
7297
resource "tfe_organization" "foobar" {
@@ -130,3 +155,27 @@ func testAccTFEVariableSetsDataSourceConfig_full(rInt int) string {
130155
depends_on = [tfe_variable.envfoo, tfe_project_variable_set.foobar]
131156
}`, rInt, rInt, rInt, rInt)
132157
}
158+
159+
func testAccTFEVariableSetsDataSourceConfig_ProjectOwned(rInt int) string {
160+
return fmt.Sprintf(`
161+
resource "tfe_organization" "foobar" {
162+
name = "org-%d"
163+
164+
}
165+
resource "tfe_project" "foobar" {
166+
organization = tfe_organization.foobar.id
167+
name = "project-%d"
168+
}
169+
170+
resource "tfe_variable_set" "project_owned" {
171+
name = "project_owned_variable_set_test"
172+
organization = tfe_organization.foobar.id
173+
parent_project_id = tfe_project.foobar.id
174+
}
175+
176+
data "tfe_variable_set" "project_owned" {
177+
name = tfe_variable_set.project_owned.name
178+
organization = tfe_variable_set.project_owned.organization
179+
}
180+
`, rInt, rInt)
181+
}

website/docs/d/variable_set.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ The following arguments are supported:
3838
* `workspace_ids` - IDs of the workspaces that use the variable set.
3939
* `variable_ids` - IDs of the variables attached to the variable set.
4040
* `project_ids` - IDs of the projects that use the variable set.
41+
* `parent_project_id` - ID of the project that owns the variable set. This feature is currently in beta and is not available to all users.

0 commit comments

Comments
 (0)