Skip to content

Commit 59cdca7

Browse files
committed
Merge remote-tracking branch 'origin/main' into jfreda/add-team-notification-cfg-resource
2 parents 90bbd46 + 343aca1 commit 59cdca7

File tree

58 files changed

+1893
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1893
-195
lines changed

.github/actions/test-provider-tfe/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ runs:
116116
MOD_TFE: github.com/hashicorp/terraform-provider-tfe/internal/provider
117117
MOD_VERSION: github.com/hashicorp/terraform-provider-tfe/version
118118
run: |
119-
terraform --version
120119
gotestsum --junitfile summary.xml --format short-verbose -- $MOD_PROVIDER $MOD_TFE $MOD_VERSION -v -timeout=30m -run "${{ steps.test_split.outputs.run }}"
121120
122121
- name: Upload test artifacts

CHANGELOG.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@
33
FEATURES:
44
* **New Resource:** `tfe_team_notification_configuration` is a new resource for managing team notification configurations, by @jfreda ([#1540](https://github.com/hashicorp/terraform-provider-tfe/pull/1540))
55

6+
## v0.62.0
7+
8+
FEATURES:
9+
* `r/tfe_variable_set`: Add `parent_project_id` attribute, by @mkam [#1522](https://github.com/hashicorp/terraform-provider-tfe/pull/1522)
10+
11+
## v0.61.0
12+
13+
DEPRECATIONS:
14+
* `r/tfe_workspace`: `global_remote_state` and `remote_state_consumer_ids` have been **deprecated** and moved to `tfe_workspace_settings` (see ENHANCEMENTS below for more details)
15+
16+
FEATURES:
17+
* `r/tfe_audit_trail_token` is a new resource for managing audit trail tokens in organization, by @glensarti and @c4po [1533](https://github.com/hashicorp/terraform-provider-tfe/pull/1533)
18+
619
## v0.60.1
720

821
BUG FIXES:
922
* `r/tfe_policy`: enforcement level can be updated on OPA policies by @glennsarti [#1521](https://github.com/hashicorp/terraform-provider-tfe/pull/1521)
1023

24+
ENHANCEMENTS:
25+
* `r/tfe_workspace_settings`: `global_remote_state` and `remote_state_consumer_ids` can now be managed using `tfe_workspace_settings`. This enhancement avoids the possibility of a mutual dependency between two or more workspaces that may access each others' state by @brandonc [#1524](https://github.com/hashicorp/terraform-provider-tfe/pull/1524)
26+
1127
## v0.60.0
1228

1329
BUG FIXES:
@@ -22,9 +38,6 @@ FEATURES:
2238

2339
## v0.59.0
2440

25-
FEATURES:
26-
* `r/tfe_audit_trail_token` is a new resource for managing audit trail tokens in organization, by @c4po [1488](https://github.com/hashicorp/terraform-provider-tfe/pull/1488)
27-
2841
## BREAKING CHANGES
2942

3043
* `r/tfe_team`: Default "secret" visibility has been removed from tfe_team because it now requires explicit or owner access. The default, "organization", is now computed by the platform. by @brandonc [#1439](https://github.com/hashicorp/terraform-provider-tfe/pull/1439)

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<img alt="Terraform" src="https://www.datocms-assets.com/2885/1629941242-logo-terraform-main.svg" width="600px">
22

3-
43
# HCP Terraform and Terraform Enterprise Provider
54

65
The official Terraform provider for [HCP Terraform and Terraform Enterprise](https://www.hashicorp.com/products/terraform).
@@ -29,7 +28,7 @@ Declare the provider in your configuration and `terraform init` will automatical
2928
terraform {
3029
required_providers {
3130
tfe = {
32-
version = "~> 0.60.1"
31+
version = "~> 0.62.0"
3332
}
3433
}
3534
}
@@ -45,7 +44,7 @@ The above snippet using `required_providers` is for Terraform 0.13+; if you are
4544

4645
```hcl
4746
provider "tfe" {
48-
version = "~> 0.60.1"
47+
version = "~> 0.62.0"
4948
...
5049
}
5150
```

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+
}

internal/provider/resource_tfe_variable_set.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package provider
1010

1111
import (
12+
"context"
1213
"fmt"
1314
"log"
1415
"regexp"
@@ -29,7 +30,16 @@ func resourceTFEVariableSet() *schema.Resource {
2930
StateContext: schema.ImportStatePassthroughContext,
3031
},
3132

32-
CustomizeDiff: customizeDiffIfProviderDefaultOrganizationChanged,
33+
CustomizeDiff: func(c context.Context, d *schema.ResourceDiff, meta interface{}) error {
34+
if err := customizeDiffIfProviderDefaultOrganizationChanged(c, d, meta); err != nil {
35+
return err
36+
}
37+
38+
if err := validateParentProjectID(d); err != nil {
39+
return err
40+
}
41+
return nil
42+
},
3343

3444
Schema: map[string]*schema.Schema{
3545
"name": {
@@ -68,6 +78,13 @@ func resourceTFEVariableSet() *schema.Resource {
6878
Computed: true,
6979
Elem: &schema.Schema{Type: schema.TypeString},
7080
},
81+
82+
"parent_project_id": {
83+
Type: schema.TypeString,
84+
Optional: true,
85+
Computed: true,
86+
ForceNew: true,
87+
},
7188
},
7289
}
7390
}
@@ -89,6 +106,14 @@ func resourceTFEVariableSetCreate(d *schema.ResourceData, meta interface{}) erro
89106
Priority: tfe.Bool(d.Get("priority").(bool)),
90107
}
91108

109+
if parentProject, ok := d.GetOk("parent_project_id"); ok {
110+
options.Parent = &tfe.Parent{
111+
Project: &tfe.Project{
112+
ID: parentProject.(string),
113+
},
114+
}
115+
}
116+
92117
if description, descriptionSet := d.GetOk("description"); descriptionSet {
93118
options.Description = tfe.String(description.(string))
94119
}
@@ -151,6 +176,10 @@ func resourceTFEVariableSetRead(d *schema.ResourceData, meta interface{}) error
151176
}
152177
d.Set("workspace_ids", wids)
153178

179+
if variableSet.Parent != nil && variableSet.Parent.Project != nil {
180+
d.Set("parent_project_id", variableSet.Parent.Project.ID)
181+
}
182+
154183
return nil
155184
}
156185

@@ -168,7 +197,7 @@ func resourceTFEVariableSetUpdate(d *schema.ResourceData, meta interface{}) erro
168197
log.Printf("[DEBUG] Update variable set: %s", d.Id())
169198
_, err := config.Client.VariableSets.Update(ctx, d.Id(), &options)
170199
if err != nil {
171-
return fmt.Errorf("Error updateing variable %s: %w", d.Id(), err)
200+
return fmt.Errorf("Error updating variable %s: %w", d.Id(), err)
172201
}
173202
}
174203

@@ -212,3 +241,19 @@ func resourceTFEVariableSetDelete(d *schema.ResourceData, meta interface{}) erro
212241
func warnWorkspaceIdsDeprecation() {
213242
log.Printf("[WARN] The workspace_ids field of tfe_variable_set is deprecated as of release 0.33.0 and may be removed in a future version. The preferred method of associating a variable set to a workspace is by using the tfe_workspace_variable_set resource.")
214243
}
244+
245+
func validateParentProjectID(d *schema.ResourceDiff) error {
246+
_, ok := d.GetOk("parent_project_id")
247+
if !ok {
248+
return nil
249+
}
250+
251+
// If parent_project_id is set, global must be false
252+
if global, ok := d.GetOk("global"); ok {
253+
if global.(bool) {
254+
return fmt.Errorf("global must be 'false' when setting parent_project_id")
255+
}
256+
}
257+
258+
return nil
259+
}

internal/provider/resource_tfe_variable_set_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ func TestAccTFEVariableSet_import(t *testing.T) {
144144
})
145145
}
146146

147+
func TestAccTFEVariableSet_project_owned(t *testing.T) {
148+
skipUnlessBeta(t)
149+
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
150+
151+
resource.Test(t, resource.TestCase{
152+
PreCheck: func() { testAccPreCheck(t) },
153+
Providers: testAccProviders,
154+
CheckDestroy: testAccCheckTFEVariableSetDestroy,
155+
Steps: []resource.TestStep{
156+
{
157+
Config: testACCTFEVariableSet_ProjectOwned(rInt),
158+
Check: resource.ComposeTestCheckFunc(
159+
resource.TestCheckResourceAttrPair(
160+
"tfe_variable_set.project_owned", "parent_project_id", "tfe_project.foobar", "id"),
161+
),
162+
},
163+
164+
{
165+
Config: testACCTFEVariableSet_UpdateProjectOwned(rInt),
166+
Check: resource.ComposeTestCheckFunc(
167+
resource.TestCheckResourceAttrPair(
168+
"tfe_variable_set.project_owned", "parent_project_id", "tfe_project.updated", "id"),
169+
),
170+
},
171+
},
172+
})
173+
}
174+
147175
func testAccCheckTFEVariableSetExists(
148176
n string, variableSet *tfe.VariableSet) resource.TestCheckFunc {
149177
return func(s *terraform.State) error {
@@ -325,3 +353,49 @@ func testAccTFEVariableSet_update(rInt int) string {
325353
organization = tfe_organization.foobar.id
326354
}`, rInt)
327355
}
356+
357+
func testACCTFEVariableSet_ProjectOwned(rInt int) string {
358+
return fmt.Sprintf(`
359+
resource "tfe_organization" "foobar" {
360+
name = "tst-terraform-%d"
361+
362+
}
363+
364+
resource "tfe_project" "foobar" {
365+
organization = tfe_organization.foobar.id
366+
name = "tst-terraform-%d"
367+
}
368+
369+
resource "tfe_variable_set" "project_owned" {
370+
name = "project_owned_variable_set_test"
371+
description = "a project-owned test variable set"
372+
organization = tfe_organization.foobar.id
373+
parent_project_id = tfe_project.foobar.id
374+
}`, rInt, rInt)
375+
}
376+
377+
func testACCTFEVariableSet_UpdateProjectOwned(rInt int) string {
378+
return fmt.Sprintf(`
379+
resource "tfe_organization" "foobar" {
380+
name = "tst-terraform-%d"
381+
382+
}
383+
384+
resource "tfe_project" "foobar" {
385+
organization = tfe_organization.foobar.id
386+
name = "tst-terraform-%d"
387+
}
388+
389+
resource "tfe_project" "updated" {
390+
organization = tfe_organization.foobar.id
391+
name = "updated-%d"
392+
}
393+
394+
resource "tfe_variable_set" "project_owned" {
395+
name = "project_owned_variable_set_test"
396+
description = "a project-owned test variable set"
397+
organization = tfe_organization.foobar.id
398+
global = false
399+
parent_project_id = tfe_project.updated.id
400+
}`, rInt, rInt, rInt)
401+
}

internal/provider/resource_tfe_workspace.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ func resourceTFEWorkspace() *schema.Resource {
5151
return err
5252
}
5353

54-
if err := validateRemoteState(c, d); err != nil {
55-
return err
56-
}
57-
5854
if err := validateTagNames(c, d); err != nil {
5955
return err
6056
}
@@ -156,16 +152,18 @@ func resourceTFEWorkspace() *schema.Resource {
156152
},
157153

158154
"global_remote_state": {
159-
Type: schema.TypeBool,
160-
Optional: true,
161-
Computed: true,
155+
Type: schema.TypeBool,
156+
Optional: true,
157+
Computed: true,
158+
Deprecated: "Use resource `tfe_workspace_settings` to modify the workspace `global_remote_state`. `global_remote_state` on `tfe_workspace` is no longer validated properly and will be removed in a future release of the provider.",
162159
},
163160

164161
"remote_state_consumer_ids": {
165-
Type: schema.TypeSet,
166-
Optional: true,
167-
Computed: true,
168-
Elem: &schema.Schema{Type: schema.TypeString},
162+
Type: schema.TypeSet,
163+
Optional: true,
164+
Computed: true,
165+
Elem: &schema.Schema{Type: schema.TypeString},
166+
Deprecated: "Use resource `tfe_workspace_settings` to modify the workspace `remote_state_consumer_ids`. `remote_state_consumer_ids` on `tfe_workspace` is no longer validated properly on this resource and This attribute will be removed in a future release of the provider.",
169167
},
170168

171169
"assessments_enabled": {
@@ -1032,23 +1030,6 @@ func validateTagNames(_ context.Context, d *schema.ResourceDiff) error {
10321030
return nil
10331031
}
10341032

1035-
func validateRemoteState(_ context.Context, d *schema.ResourceDiff) error {
1036-
// If remote state consumers aren't set, the global setting can be either value and it
1037-
// doesn't matter.
1038-
_, ok := d.GetOk("remote_state_consumer_ids")
1039-
if !ok {
1040-
return nil
1041-
}
1042-
1043-
if globalRemoteState, ok := d.GetOk("global_remote_state"); ok {
1044-
if globalRemoteState.(bool) {
1045-
return fmt.Errorf("global_remote_state must be 'false' when setting remote_state_consumer_ids")
1046-
}
1047-
}
1048-
1049-
return nil
1050-
}
1051-
10521033
func resourceTFEWorkspaceImporter(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
10531034
config := meta.(ConfiguredClient)
10541035

0 commit comments

Comments
 (0)