-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1522 from hashicorp/mkam/TF-20798/project-owned-v…
…arsets Add support for project-owned variable sets
- Loading branch information
Showing
9 changed files
with
250 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,64 @@ resource "tfe_variable" "test-b" { | |
} | ||
``` | ||
|
||
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters