Skip to content

Commit b9656c1

Browse files
authored
TF-5569 add support for custom project permissions (#983)
* Add customizable project level permissions in dataSourceTFETeamProjectAccess * Add customizable project level permission in resourceTFETeamProjectAccess
1 parent 3bdc853 commit b9656c1

8 files changed

+875
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ FEATURES:
99
* `d/tfe_saml_settings`: Add PrivateKey (sensitive), SignatureSigningMethod, and SignatureDigestMethod attributes, by @karvounis-form3 [970](https://github.com/hashicorp/terraform-provider-tfe/pull/970)
1010
* **New Resource**: `r/tfe_project_policy_set` is a new resource to attach/detach an existing `project` to an existing `policy set`, by @Netra2104 [972](https://github.com/hashicorp/terraform-provider-tfe/pull/972)
1111
* `d/tfe_policy_set`: Add `project_ids` attribute, by @Netra2104 [974](https://github.com/hashicorp/terraform-provider-tfe/pull/974/files)
12+
* `r/tfe_team_project_access`: Add a `custom` option to the `access` attribute as well as `project_access` and `workspace_access` attributes with
13+
various customizable permissions options to apply to a project and all of the workspaces therein, by @rberecka [983](https://github.com/hashicorp/terraform-provider-tfe/pull/983)
14+
* `d/team_project_access`: Add a `custom` option to the `access` attribute as well as `project_access` and `workspace_access` attributes, by @rberecka [983](https://github.com/hashicorp/terraform-provider-tfe/pull/983)
1215

1316
NOTES:
1417
* The provider is now using go-tfe [v1.30.0](https://github.com/hashicorp/go-tfe/releases/tag/v1.30.0), by @karvounis-form3 [970](https://github.com/hashicorp/terraform-provider-tfe/pull/970)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/hashicorp/go-multierror v1.1.1 // indirect
1313
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
1414
github.com/hashicorp/go-slug v0.12.0
15-
github.com/hashicorp/go-tfe v1.31.0
15+
github.com/hashicorp/go-tfe v1.32.0
1616
github.com/hashicorp/go-version v1.6.0
1717
github.com/hashicorp/hcl v1.0.0
1818
github.com/hashicorp/hcl/v2 v2.17.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZn
5656
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
5757
github.com/hashicorp/go-slug v0.12.0 h1:y1ArGp5RFF85uvD8nq5VZug/bup/kGN5Ft4xFOQ5GPM=
5858
github.com/hashicorp/go-slug v0.12.0/go.mod h1:JZVtycnZZbiJ4oxpJ/zfhyfBD8XxT4f0uOSyjNLCqFY=
59-
github.com/hashicorp/go-tfe v1.31.0 h1:R1CokrAVBHxrsvRw1vKes7RQxTRTWcula7gjQK7Jfsk=
60-
github.com/hashicorp/go-tfe v1.31.0/go.mod h1:vcfy2u52JQ4sYLFi941qcQXQYfUq2RjEW466tZ+m97Y=
59+
github.com/hashicorp/go-tfe v1.32.0 h1:wyUQJHPrqF5IwD5Y4YJFTlU3A08LXoJ2PLF7x80febU=
60+
github.com/hashicorp/go-tfe v1.32.0/go.mod h1:vcfy2u52JQ4sYLFi941qcQXQYfUq2RjEW466tZ+m97Y=
6161
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
6262
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
6363
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

tfe/data_source_team_project_access.go

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package tfe
55

66
import (
77
"context"
8+
89
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
910

1011
tfe "github.com/hashicorp/go-tfe"
@@ -30,18 +31,88 @@ func dataSourceTFETeamProjectAccess() *schema.Resource {
3031
Type: schema.TypeString,
3132
Required: true,
3233
},
34+
35+
"project_access": {
36+
Type: schema.TypeList,
37+
Computed: true,
38+
Elem: &schema.Resource{
39+
Schema: map[string]*schema.Schema{
40+
"settings": {
41+
Type: schema.TypeString,
42+
Computed: true,
43+
},
44+
45+
"teams": {
46+
Type: schema.TypeString,
47+
Computed: true,
48+
},
49+
},
50+
},
51+
},
52+
53+
"workspace_access": {
54+
Type: schema.TypeList,
55+
Computed: true,
56+
Elem: &schema.Resource{
57+
Schema: map[string]*schema.Schema{
58+
"create": {
59+
Type: schema.TypeBool,
60+
Computed: true,
61+
},
62+
63+
"locking": {
64+
Type: schema.TypeBool,
65+
Computed: true,
66+
},
67+
68+
"move": {
69+
Type: schema.TypeBool,
70+
Computed: true,
71+
},
72+
73+
"delete": {
74+
Type: schema.TypeBool,
75+
Computed: true,
76+
},
77+
78+
"run_tasks": {
79+
Type: schema.TypeBool,
80+
Computed: true,
81+
},
82+
83+
"runs": {
84+
Type: schema.TypeString,
85+
Computed: true,
86+
},
87+
88+
"sentinel_mocks": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
},
92+
93+
"state_versions": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
},
97+
98+
"variables": {
99+
Type: schema.TypeString,
100+
Computed: true,
101+
},
102+
},
103+
},
104+
},
33105
},
34106
}
35107
}
36108

37109
func dataSourceTFETeamProjectAccessRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
38110
config := meta.(ConfiguredClient)
39-
40111
// Get the team ID.
41112
teamID := d.Get("team_id").(string)
42-
43113
// Get the project
44114
projectID := d.Get("project_id").(string)
115+
45116
proj, err := config.Client.Projects.Read(ctx, projectID)
46117
if err != nil {
47118
return diag.Errorf(

tfe/data_source_team_project_access_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,55 @@ func TestAccTFETeamProjectAccessDataSource_basic(t *testing.T) {
3737
})
3838
}
3939

40+
func TestAccTFETeamProjectCustomAccessDataSource_basic(t *testing.T) {
41+
tfeClient, err := getClientUsingEnv()
42+
if err != nil {
43+
t.Fatal(err)
44+
}
45+
46+
org, orgCleanup := createBusinessOrganization(t, tfeClient)
47+
t.Cleanup(orgCleanup)
48+
49+
resource.Test(t, resource.TestCase{
50+
PreCheck: func() { testAccPreCheck(t) },
51+
Providers: testAccProviders,
52+
Steps: []resource.TestStep{
53+
{
54+
Config: testAccTFETeamProjectCustomAccessDataSourceConfig(org.Name),
55+
Check: resource.ComposeAggregateTestCheckFunc(
56+
resource.TestCheckResourceAttrSet("data.tfe_team_project_access.foobar_custom", "id"),
57+
resource.TestCheckResourceAttrSet("data.tfe_team_project_access.foobar_custom", "team_id"),
58+
resource.TestCheckResourceAttrSet("data.tfe_team_project_access.foobar_custom", "project_id"),
59+
resource.TestCheckResourceAttr(
60+
"data.tfe_team_project_access.foobar_custom", "access", "custom"),
61+
resource.TestCheckResourceAttr(
62+
"data.tfe_team_project_access.foobar_custom", "project_access.0.settings", "delete"),
63+
resource.TestCheckResourceAttr(
64+
"data.tfe_team_project_access.foobar_custom", "project_access.0.teams", "manage"),
65+
resource.TestCheckResourceAttr(
66+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.state_versions", "write"),
67+
resource.TestCheckResourceAttr(
68+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.sentinel_mocks", "read"),
69+
resource.TestCheckResourceAttr(
70+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.runs", "apply"),
71+
resource.TestCheckResourceAttr(
72+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.variables", "write"),
73+
resource.TestCheckResourceAttr(
74+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.create", "true"),
75+
resource.TestCheckResourceAttr(
76+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.locking", "true"),
77+
resource.TestCheckResourceAttr(
78+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.move", "true"),
79+
resource.TestCheckResourceAttr(
80+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.delete", "false"),
81+
resource.TestCheckResourceAttr(
82+
"data.tfe_team_project_access.foobar_custom", "workspace_access.0.run_tasks", "false"),
83+
),
84+
},
85+
},
86+
})
87+
}
88+
4089
func testAccTFETeamProjectAccessDataSourceConfig(organization string) string {
4190
return fmt.Sprintf(`
4291
resource "tfe_team" "foobar" {
@@ -61,3 +110,43 @@ data "tfe_team_project_access" "foobar" {
61110
depends_on = [tfe_team_project_access.foobar]
62111
}`, organization, organization)
63112
}
113+
114+
func testAccTFETeamProjectCustomAccessDataSourceConfig(organization string) string {
115+
return fmt.Sprintf(`
116+
resource "tfe_team" "foobar_custom" {
117+
name = "team-test2"
118+
organization = "%s"
119+
}
120+
121+
resource "tfe_project" "foobar_custom" {
122+
name = "projecttest2"
123+
organization = "%s"
124+
}
125+
126+
resource "tfe_team_project_access" "foobar_custom" {
127+
access = "custom"
128+
team_id = tfe_team.foobar_custom.id
129+
project_id = tfe_project.foobar_custom.id
130+
project_access {
131+
settings = "delete"
132+
teams = "manage"
133+
}
134+
workspace_access {
135+
state_versions = "write"
136+
sentinel_mocks = "read"
137+
runs = "apply"
138+
variables = "write"
139+
create = true
140+
locking = true
141+
move = true
142+
delete = false
143+
run_tasks = false
144+
}
145+
}
146+
147+
data "tfe_team_project_access" "foobar_custom" {
148+
team_id = tfe_team.foobar_custom.id
149+
project_id = tfe_project.foobar_custom.id
150+
depends_on = [tfe_team_project_access.foobar_custom]
151+
}`, organization, organization)
152+
}

0 commit comments

Comments
 (0)