Skip to content

Commit

Permalink
feat: Adding new manage_collection and manage_team permission
Browse files Browse the repository at this point in the history
  • Loading branch information
alfespa17 committed Dec 10, 2024
1 parent 7a8839c commit 315a65b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 48 deletions.
20 changes: 12 additions & 8 deletions docs/resources/team.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ Create a team and bind it to an organization. Allows for fined grained access ma

```terraform
resource "terrakube_team" "team" {
name = "TERRAKUBE_SUPER_ADMIN"
organization_id = data.terrakube_organization.org.id
manage_state = false
manage_workspace = false
manage_module = false
manage_provider = true
manage_vcs = true
manage_template = true
name = "TERRAKUBE_SUPER_ADMIN"
organization_id = data.terrakube_organization.org.id
manage_state = false
manage_workspace = false
manage_module = false
manage_provider = true
manage_vcs = true
manage_template = true
manage_job = true
manage_collection = true
}
```

Expand All @@ -35,6 +37,8 @@ resource "terrakube_team" "team" {

### Optional

- `manage_collection` (Boolean) Allow to manage variables collection
- `manage_job` (Boolean) Allow to manage and trigger jobs
- `manage_module` (Boolean) Allow to manage modules
- `manage_provider` (Boolean) Allow to manage providers
- `manage_state` (Boolean) Allow to manage Terraform/OpenTofu state
Expand Down
18 changes: 10 additions & 8 deletions examples/resources/terrakube_team/resource.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
resource "terrakube_team" "team" {
name = "TERRAKUBE_SUPER_ADMIN"
organization_id = data.terrakube_organization.org.id
manage_state = false
manage_workspace = false
manage_module = false
manage_provider = true
manage_vcs = true
manage_template = true
name = "TERRAKUBE_SUPER_ADMIN"
organization_id = data.terrakube_organization.org.id
manage_state = false
manage_workspace = false
manage_module = false
manage_provider = true
manage_vcs = true
manage_template = true
manage_job = true
manage_collection = true
}
18 changes: 10 additions & 8 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ type OrganizationTagEntity struct {
}

type TeamEntity struct {
ID string `jsonapi:"primary,team"`
Name string `jsonapi:"attr,name"`
ManageState bool `jsonapi:"attr,manageState"`
ManageWorkspace bool `jsonapi:"attr,manageWorkspace"`
ManageModule bool `jsonapi:"attr,manageModule"`
ManageProvider bool `jsonapi:"attr,manageProvider"`
ManageVcs bool `jsonapi:"attr,manageVcs"`
ManageTemplate bool `jsonapi:"attr,manageTemplate"`
ID string `jsonapi:"primary,team"`
Name string `jsonapi:"attr,name"`
ManageState bool `jsonapi:"attr,manageState"`
ManageWorkspace bool `jsonapi:"attr,manageWorkspace"`
ManageModule bool `jsonapi:"attr,manageModule"`
ManageProvider bool `jsonapi:"attr,manageProvider"`
ManageVcs bool `jsonapi:"attr,manageVcs"`
ManageTemplate bool `jsonapi:"attr,manageTemplate"`
ManageJob bool `jsonapi:"attr,manageJob"`
ManageCollection bool `jsonapi:"attr,manageCollection"`
}

type TeamTokenEntity struct {
Expand Down
72 changes: 48 additions & 24 deletions internal/provider/team_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ type TeamResource struct {
}

type TeamResourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
OrganizationId types.String `tfsdk:"organization_id"`
ManageState types.Bool `tfsdk:"manage_state"`
ManageWorkspace types.Bool `tfsdk:"manage_workspace"`
ManageModule types.Bool `tfsdk:"manage_module"`
ManageProvider types.Bool `tfsdk:"manage_provider"`
ManageVcs types.Bool `tfsdk:"manage_vcs"`
ManageTemplate types.Bool `tfsdk:"manage_template"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
OrganizationId types.String `tfsdk:"organization_id"`
ManageState types.Bool `tfsdk:"manage_state"`
ManageWorkspace types.Bool `tfsdk:"manage_workspace"`
ManageModule types.Bool `tfsdk:"manage_module"`
ManageProvider types.Bool `tfsdk:"manage_provider"`
ManageVcs types.Bool `tfsdk:"manage_vcs"`
ManageTemplate types.Bool `tfsdk:"manage_template"`
ManageJob types.Bool `tfsdk:"manage_job"`
ManageCollection types.Bool `tfsdk:"manage_collection"`
}

func NewTeamResource() resource.Resource {
Expand Down Expand Up @@ -78,6 +80,18 @@ func (r *TeamResource) Schema(ctx context.Context, req resource.SchemaRequest, r
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_job": schema.BoolAttribute{
Optional: true,
Description: "Allow to manage and trigger jobs",
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_collection": schema.BoolAttribute{
Optional: true,
Description: "Allow to manage variables collection",
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_workspace": schema.BoolAttribute{
Optional: true,
Description: "Allow to manage workspaces",
Expand Down Expand Up @@ -155,13 +169,15 @@ func (r *TeamResource) Create(ctx context.Context, req resource.CreateRequest, r
}

bodyRequest := &client.TeamEntity{
Name: plan.Name.ValueString(),
ManageState: plan.ManageState.ValueBool(),
ManageWorkspace: plan.ManageWorkspace.ValueBool(),
ManageModule: plan.ManageModule.ValueBool(),
ManageProvider: plan.ManageProvider.ValueBool(),
ManageTemplate: plan.ManageTemplate.ValueBool(),
ManageVcs: plan.ManageVcs.ValueBool(),
Name: plan.Name.ValueString(),
ManageState: plan.ManageState.ValueBool(),
ManageWorkspace: plan.ManageWorkspace.ValueBool(),
ManageModule: plan.ManageModule.ValueBool(),
ManageProvider: plan.ManageProvider.ValueBool(),
ManageTemplate: plan.ManageTemplate.ValueBool(),
ManageVcs: plan.ManageVcs.ValueBool(),
ManageJob: plan.ManageJob.ValueBool(),
ManageCollection: plan.ManageCollection.ValueBool(),
}

var out = new(bytes.Buffer)
Expand Down Expand Up @@ -209,6 +225,8 @@ func (r *TeamResource) Create(ctx context.Context, req resource.CreateRequest, r
plan.ManageVcs = types.BoolValue(newTeam.ManageVcs)
plan.ManageProvider = types.BoolValue(newTeam.ManageProvider)
plan.ManageTemplate = types.BoolValue(newTeam.ManageTemplate)
plan.ManageJob = types.BoolValue(newTeam.ManageJob)
plan.ManageCollection = types.BoolValue(newTeam.ManageCollection)

tflog.Info(ctx, "Team Resource Created", map[string]any{"success": true})

Expand Down Expand Up @@ -259,6 +277,8 @@ func (r *TeamResource) Read(ctx context.Context, req resource.ReadRequest, resp
state.ManageVcs = types.BoolValue(team.ManageVcs)
state.ManageProvider = types.BoolValue(team.ManageProvider)
state.ManageTemplate = types.BoolValue(team.ManageTemplate)
state.ManageJob = types.BoolValue(team.ManageJob)
state.ManageCollection = types.BoolValue(team.ManageCollection)

// Set refreshed state
diags = resp.State.Set(ctx, &state)
Expand All @@ -281,14 +301,16 @@ func (r *TeamResource) Update(ctx context.Context, req resource.UpdateRequest, r
}

bodyRequest := &client.TeamEntity{
ManageState: plan.ManageState.ValueBool(),
ManageWorkspace: plan.ManageWorkspace.ValueBool(),
ManageModule: plan.ManageModule.ValueBool(),
ManageProvider: plan.ManageProvider.ValueBool(),
ManageTemplate: plan.ManageTemplate.ValueBool(),
ManageVcs: plan.ManageVcs.ValueBool(),
ID: state.ID.ValueString(),
Name: state.Name.ValueString(),
ManageState: plan.ManageState.ValueBool(),
ManageWorkspace: plan.ManageWorkspace.ValueBool(),
ManageModule: plan.ManageModule.ValueBool(),
ManageProvider: plan.ManageProvider.ValueBool(),
ManageTemplate: plan.ManageTemplate.ValueBool(),
ManageVcs: plan.ManageVcs.ValueBool(),
ManageJob: plan.ManageJob.ValueBool(),
ManageCollection: plan.ManageCollection.ValueBool(),
ID: state.ID.ValueString(),
Name: state.Name.ValueString(),
}

var out = new(bytes.Buffer)
Expand Down Expand Up @@ -357,6 +379,8 @@ func (r *TeamResource) Update(ctx context.Context, req resource.UpdateRequest, r
plan.ManageVcs = types.BoolValue(team.ManageVcs)
plan.ManageProvider = types.BoolValue(team.ManageProvider)
plan.ManageTemplate = types.BoolValue(team.ManageTemplate)
plan.ManageJob = types.BoolValue(team.ManageJob)
plan.ManageCollection = types.BoolValue(team.ManageCollection)

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}
Expand Down

0 comments on commit 315a65b

Please sign in to comment.