-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for project-owned variable sets #1522
Changes from all commits
e189f23
9fc6b18
42d1547
857ff6b
53a3f84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,31 @@ func TestAccTFEVariableSetsDataSource_full(t *testing.T) { | |
) | ||
} | ||
|
||
func TestAccTFEVariableSetsDataSource_ProjectOwned(t *testing.T) { | ||
skipUnlessBeta(t) | ||
|
||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
orgName := fmt.Sprintf("org-%d", rInt) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV5ProviderFactories: testAccMuxedProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTFEVariableSetsDataSourceConfig_ProjectOwned(rInt), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.tfe_variable_set.project_owned", "id"), | ||
resource.TestCheckResourceAttr( | ||
"data.tfe_variable_set.project_owned", "organization", orgName), | ||
resource.TestCheckResourceAttrPair( | ||
"data.tfe_variable_set.project_owned", "parent_project_id", "tfe_project.foobar", "id"), | ||
), | ||
}, | ||
}, | ||
}, | ||
) | ||
} | ||
|
||
func testAccTFEVariableSetsDataSourceConfig_basic(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_organization" "foobar" { | ||
|
@@ -130,3 +155,27 @@ func testAccTFEVariableSetsDataSourceConfig_full(rInt int) string { | |
depends_on = [tfe_variable.envfoo, tfe_project_variable_set.foobar] | ||
}`, rInt, rInt, rInt, rInt) | ||
} | ||
|
||
func testAccTFEVariableSetsDataSourceConfig_ProjectOwned(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_organization" "foobar" { | ||
name = "org-%d" | ||
email = "[email protected]" | ||
} | ||
resource "tfe_project" "foobar" { | ||
organization = tfe_organization.foobar.id | ||
name = "project-%d" | ||
} | ||
|
||
resource "tfe_variable_set" "project_owned" { | ||
name = "project_owned_variable_set_test" | ||
organization = tfe_organization.foobar.id | ||
parent_project_id = tfe_project.foobar.id | ||
} | ||
|
||
data "tfe_variable_set" "project_owned" { | ||
name = tfe_variable_set.project_owned.name | ||
organization = tfe_variable_set.project_owned.organization | ||
} | ||
`, rInt, rInt) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,34 @@ func TestAccTFEVariableSet_import(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccTFEVariableSet_project_owned(t *testing.T) { | ||
skipUnlessBeta(t) | ||
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckTFEVariableSetDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testACCTFEVariableSet_ProjectOwned(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair( | ||
"tfe_variable_set.project_owned", "parent_project_id", "tfe_project.foobar", "id"), | ||
), | ||
}, | ||
|
||
{ | ||
Config: testACCTFEVariableSet_UpdateProjectOwned(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair( | ||
"tfe_variable_set.project_owned", "parent_project_id", "tfe_project.updated", "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckTFEVariableSetExists( | ||
n string, variableSet *tfe.VariableSet) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
|
@@ -325,3 +353,49 @@ func testAccTFEVariableSet_update(rInt int) string { | |
organization = tfe_organization.foobar.id | ||
}`, rInt) | ||
} | ||
|
||
func testACCTFEVariableSet_ProjectOwned(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_organization" "foobar" { | ||
name = "tst-terraform-%d" | ||
email = "[email protected]" | ||
} | ||
|
||
resource "tfe_project" "foobar" { | ||
organization = tfe_organization.foobar.id | ||
name = "tst-terraform-%d" | ||
} | ||
|
||
resource "tfe_variable_set" "project_owned" { | ||
name = "project_owned_variable_set_test" | ||
description = "a project-owned test variable set" | ||
organization = tfe_organization.foobar.id | ||
parent_project_id = tfe_project.foobar.id | ||
}`, rInt, rInt) | ||
} | ||
|
||
func testACCTFEVariableSet_UpdateProjectOwned(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "tfe_organization" "foobar" { | ||
name = "tst-terraform-%d" | ||
email = "[email protected]" | ||
} | ||
|
||
resource "tfe_project" "foobar" { | ||
organization = tfe_organization.foobar.id | ||
name = "tst-terraform-%d" | ||
} | ||
|
||
resource "tfe_project" "updated" { | ||
organization = tfe_organization.foobar.id | ||
name = "updated-%d" | ||
} | ||
|
||
resource "tfe_variable_set" "project_owned" { | ||
name = "project_owned_variable_set_test" | ||
description = "a project-owned test variable set" | ||
organization = tfe_organization.foobar.id | ||
global = false | ||
parent_project_id = tfe_project.updated.id | ||
}`, rInt, rInt, rInt) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,64 @@ resource "tfe_variable" "test-b" { | |
} | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if adding both makes the example section too long, but I thought it would be valuable to make it clear that a project-owned varset doesn't necessarily/automatically apply itself to the project and that it can be scoped to workspaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely, great idea to make that behavior clear. |
||
Creating a project-owned variable set that is applied to all workspaces in the project: | ||
|
||
```hcl | ||
resource "tfe_organization" "test" { | ||
name = "my-org-name" | ||
email = "[email protected]" | ||
} | ||
|
||
resource "tfe_project" "test" { | ||
organization = tfe_organization.test.name | ||
name = "projectname" | ||
} | ||
|
||
resource "tfe_variable_set" "test" { | ||
name = "Project-owned Varset" | ||
description = "Varset that is owned and managed by a project." | ||
organization = tfe_organization.test.name | ||
parent_project_id = tfe_project.test.id | ||
} | ||
|
||
resource "tfe_project_variable_set" "test" { | ||
project_id = tfe_project.test.id | ||
variable_set_id = tfe_variable_set.test.id | ||
} | ||
``` | ||
|
||
Creating a project-owned variable set that is applied to specific workspaces: | ||
|
||
```hcl | ||
resource "tfe_organization" "test" { | ||
name = "my-org-name" | ||
email = "[email protected]" | ||
} | ||
|
||
resource "tfe_project" "test" { | ||
organization = tfe_organization.test.name | ||
name = "projectname" | ||
} | ||
|
||
resource "tfe_workspace" "test" { | ||
name = "my-workspace-name" | ||
organization = tfe_organization.test.name | ||
project_id = tfe_project.test.id | ||
} | ||
|
||
resource "tfe_variable_set" "test" { | ||
name = "Project-owned Varset" | ||
description = "Varset that is owned and managed by a project." | ||
organization = tfe_organization.test.name | ||
parent_project_id = tfe_project.test.id | ||
} | ||
|
||
resource "tfe_workspace_variable_set" "test" { | ||
workspace_id = tfe_workspace.test.id | ||
variable_set_id = tfe_variable_set.test.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
@@ -139,6 +197,8 @@ The following arguments are supported: | |
Must not be set if `global` is set. This argument is mutually exclusive with using the resource | ||
[tfe_workspace_variable_set](workspace_variable_set.html) which is the preferred method of associating a workspace | ||
with a variable set. | ||
* `parent_project_id` - (Optional) ID of the project that should own the variable set. If set, than the value of `global` must be `false`. | ||
To assign whether a variable set should be applied to a project, use the [`tfe_project_variable_set`](project_variable_set.html) resource. | ||
|
||
## Attributes Reference | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ description: |- | |
|
||
# tfe_workspace_variable_set | ||
|
||
Adds and removes variable sets from a workspace | ||
Adds and removes a workspace from a variable set's scope. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed for consistency with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, especially because making it consistent on the project side to read "Adds and removes variable sets from a project" could be ambiguous. |
||
|
||
-> **Note:** `tfe_variable_set` has a deprecated argument `workspace_ids` that should not be used alongside this resource. They attempt to manage the same attachments and are mutually exclusive. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌