Skip to content

Commit

Permalink
feat: Add manage_state to terrakube_team (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyz authored Oct 4, 2024
1 parent 7b3c4f1 commit 6810948
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
9 changes: 7 additions & 2 deletions docs/resources/team.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ description: |-
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
Expand All @@ -29,13 +30,17 @@ resource "terrakube_team" "team" {

### Required

- `name` (String) Team name
- `organization_id` (String) Terrakube organization id

### Optional

- `manage_module` (Boolean) Allow to manage modules
- `manage_provider` (Boolean) Allow to manage providers
- `manage_state` (Boolean) Allow to manage Terraform/OpenTofu state
- `manage_template` (Boolean) Allow to manage templates
- `manage_vcs` (Boolean) Allow to manage vcs connections
- `manage_workspace` (Boolean) Allow to manage workspaces
- `name` (String) Team name
- `organization_id` (String) Terrakube organization id

### Read-Only

Expand Down
3 changes: 2 additions & 1 deletion examples/resources/terrakube_team/resource.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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
}
}
1 change: 1 addition & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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"`
Expand Down
37 changes: 30 additions & 7 deletions internal/provider/team_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"terraform-provider-terrakube/internal/client"

"github.com/google/jsonapi"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"

Expand All @@ -35,6 +36,7 @@ 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"`
Expand Down Expand Up @@ -68,25 +70,41 @@ func (r *TeamResource) Schema(ctx context.Context, req resource.SchemaRequest, r
Required: true,
Description: "Team name",
},
"manage_state": schema.BoolAttribute{
Optional: true,
Description: "Allow to manage Terraform/OpenTofu state",
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_workspace": schema.BoolAttribute{
Required: true,
Optional: true,
Description: "Allow to manage workspaces",
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_module": schema.BoolAttribute{
Required: true,
Optional: true,
Description: "Allow to manage modules",
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_provider": schema.BoolAttribute{
Required: true,
Optional: true,
Description: "Allow to manage providers",
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_vcs": schema.BoolAttribute{
Required: true,
Optional: true,
Description: "Allow to manage vcs connections",
Computed: true,
Default: booldefault.StaticBool(false),
},
"manage_template": schema.BoolAttribute{
Required: true,
Optional: true,
Description: "Allow to manage templates",
Computed: true,
Default: booldefault.StaticBool(false),
},
},
}
Expand Down Expand Up @@ -136,11 +154,12 @@ 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.ManageTemplate.ValueBool(),
ManageVcs: plan.ManageVcs.ValueBool(),
}

var out = new(bytes.Buffer)
Expand Down Expand Up @@ -182,6 +201,7 @@ func (r *TeamResource) Create(ctx context.Context, req resource.CreateRequest, r

plan.ID = types.StringValue(newTeam.ID)
plan.Name = types.StringValue(newTeam.Name)
plan.ManageState = types.BoolValue(newTeam.ManageState)
plan.ManageWorkspace = types.BoolValue(newTeam.ManageWorkspace)
plan.ManageModule = types.BoolValue(newTeam.ManageModule)
plan.ManageVcs = types.BoolValue(newTeam.ManageVcs)
Expand Down Expand Up @@ -231,6 +251,7 @@ func (r *TeamResource) Read(ctx context.Context, req resource.ReadRequest, resp

tflog.Info(ctx, "Body Response", map[string]any{"bodyResponse": string(bodyResponse)})

state.ManageState = types.BoolValue(team.ManageState)
state.ManageWorkspace = types.BoolValue(team.ManageWorkspace)
state.ManageModule = types.BoolValue(team.ManageModule)
state.ManageVcs = types.BoolValue(team.ManageVcs)
Expand Down Expand Up @@ -258,11 +279,12 @@ 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.ManageTemplate.ValueBool(),
ManageVcs: plan.ManageVcs.ValueBool(),
ID: state.ID.ValueString(),
Name: state.Name.ValueString(),
}
Expand Down Expand Up @@ -327,6 +349,7 @@ func (r *TeamResource) Update(ctx context.Context, req resource.UpdateRequest, r

plan.ID = types.StringValue(state.ID.ValueString())
plan.Name = types.StringValue(state.Name.ValueString())
plan.ManageState = types.BoolValue(team.ManageState)
plan.ManageWorkspace = types.BoolValue(team.ManageWorkspace)
plan.ManageModule = types.BoolValue(team.ManageModule)
plan.ManageVcs = types.BoolValue(team.ManageVcs)
Expand Down

0 comments on commit 6810948

Please sign in to comment.