-
Notifications
You must be signed in to change notification settings - Fork 1
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 #20 from d-strobel/feat/resource-local_group_member
Feat/resource local group member
- Loading branch information
Showing
11 changed files
with
307 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
page_title: "windows_local_group_member Resource - terraform-provider-windows" | ||
subcategory: "Local" | ||
description: |- | ||
Manage group member for local security groups | ||
--- | ||
# windows_local_group_member (Resource) | ||
|
||
<!-- resource description generated from schema --> | ||
Manage group member for local security groups. | ||
<!-- examples generated from example files --> | ||
## Example Usage | ||
|
||
```terraform | ||
resource "windows_local_user" "this" { | ||
name = "test-user" | ||
} | ||
resource "windows_local_group" "this" { | ||
name = "test-group" | ||
} | ||
resource "windows_local_group_member" "this" { | ||
group_id = windows_local_group.this.id | ||
member_id = windows_local_user.this.id | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `group_id` (String) The ID of the local security group you want to add the member to. Changing this forces a new resource to be created. | ||
- `member_id` (String) The ID of the principal you want to add as a member to the group. Supported object types are local users or groups. Changing this forces a new resource to be created. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
data "windows_local_users" "all" {} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resource "windows_local_user" "this" { | ||
name = "test-user" | ||
} | ||
|
||
resource "windows_local_group" "this" { | ||
name = "test-group" | ||
} | ||
|
||
resource "windows_local_group_member" "this" { | ||
group_id = windows_local_group.this.id | ||
member_id = windows_local_user.this.id | ||
} |
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
49 changes: 49 additions & 0 deletions
49
internal/generate/resource_local_group_member/local_group_member_resource_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package local | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"terraform-provider-windows/internal/generate/resource_local_group_member" | ||
|
||
"github.com/d-strobel/gowindows" | ||
"github.com/d-strobel/gowindows/windows/local" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ resource.Resource = (*localGroupMemberResource)(nil) | ||
|
||
func NewLocalGroupMemberResource() resource.Resource { | ||
return &localGroupMemberResource{} | ||
} | ||
|
||
type localGroupMemberResource struct { | ||
client *gowindows.Client | ||
} | ||
|
||
func (r *localGroupMemberResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_local_group_member" | ||
} | ||
|
||
func (r *localGroupMemberResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { | ||
resp.Schema = resource_local_group_member.LocalGroupMemberResourceSchema(ctx) | ||
resp.Schema.Description = `Manage group member for local security groups.` | ||
} | ||
|
||
func (r *localGroupMemberResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(*gowindows.Client) | ||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Resource Configure Type", | ||
fmt.Sprintf("Expected *gowindows.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
return | ||
} | ||
|
||
r.client = client | ||
} | ||
|
||
func (r *localGroupMemberResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { | ||
var data resource_local_group_member.LocalGroupMemberModel | ||
|
||
// Read Terraform plan data into the model | ||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// Create API call logic | ||
params := local.GroupMemberCreateParams{ | ||
SID: data.GroupId.ValueString(), | ||
Member: data.MemberId.ValueString(), | ||
} | ||
|
||
if err := r.client.Local.GroupMemberCreate(ctx, params); err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create local group member, got error: %s", err)) | ||
return | ||
} | ||
|
||
// Create the ID for the resource | ||
data.Id = types.StringValue(fmt.Sprintf("%s/member/%s", data.GroupId.ValueString(), data.MemberId.ValueString())) | ||
|
||
// Save data into Terraform state | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func (r *localGroupMemberResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { | ||
var data resource_local_group_member.LocalGroupMemberModel | ||
|
||
// Read Terraform prior state data into the model | ||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// Read API call logic | ||
params := local.GroupMemberReadParams{ | ||
SID: data.GroupId.ValueString(), | ||
Member: data.MemberId.ValueString(), | ||
} | ||
|
||
if _, err := r.client.Local.GroupMemberRead(ctx, params); err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete local group member, got error: %s", err)) | ||
return | ||
} | ||
|
||
// Save updated data into Terraform state | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func (r *localGroupMemberResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { | ||
// Update is not needed in this resource | ||
} | ||
|
||
func (r *localGroupMemberResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { | ||
var data resource_local_group_member.LocalGroupMemberModel | ||
|
||
// Read Terraform prior state data into the model | ||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// Delete API call logic | ||
params := local.GroupMemberDeleteParams{ | ||
SID: data.GroupId.ValueString(), | ||
Member: data.MemberId.ValueString(), | ||
} | ||
|
||
if err := r.client.Local.GroupMemberDelete(ctx, params); err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete local group member, got error: %s", err)) | ||
return | ||
} | ||
} |
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