Skip to content

Commit

Permalink
Merge branch 'main' into ay/feat/acceptance-tests/resource/agents
Browse files Browse the repository at this point in the history
  • Loading branch information
MaraisKruger authored Nov 13, 2024
2 parents a8fc7b3 + 6e45bd5 commit bc28618
Show file tree
Hide file tree
Showing 3 changed files with 631 additions and 32 deletions.
28 changes: 12 additions & 16 deletions internal/provider/resources/agent_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &agentGroupAssignmentResource{}
_ resource.ResourceWithConfigure = &agentGroupAssignmentResource{}
Expand All @@ -25,12 +24,6 @@ type agentGroupAssignmentResourceModel struct {
GroupID types.String `tfsdk:"group_id"`
}

type AgentGroupAssignmentResponseModel struct {
UID string // <assignment_uid>
GroupUID string // <group_uid:str>,
AgentUID string // <agent_uid:str>
}

func NewAgentGroupAssignmentResource() resource.Resource {
return &agentGroupAssignmentResource{}
}
Expand Down Expand Up @@ -103,7 +96,6 @@ func (r *agentGroupAssignmentResource) Create(
req resource.CreateRequest,
resp *resource.CreateResponse,
) {
// Retrieve values from plan
var plan agentGroupAssignmentResourceModel
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
Expand All @@ -129,12 +121,10 @@ func (r *agentGroupAssignmentResource) Create(
return
}

// Update the state to match the plan
plan.ID = types.StringValue(agentGroupAssignment.Id)
plan.GroupID = types.StringValue(agentGroupAssignment.Group.Id)
plan.AgentID = types.StringValue(agentGroupAssignment.Agent.Id)

// Set state to fully populated data
diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
Expand All @@ -147,7 +137,6 @@ func (r *agentGroupAssignmentResource) Read(
req resource.ReadRequest,
resp *resource.ReadResponse,
) {
// Get current state
var state agentGroupAssignmentResourceModel
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
Expand All @@ -174,12 +163,10 @@ func (r *agentGroupAssignmentResource) Read(
}
agentGroupAssignment := agentGroupAssignmentResponse.Items[0]

// Update state from client response
state.ID = types.StringValue(agentGroupAssignment.Id)
state.GroupID = types.StringValue(agentGroupAssignment.Group.Id)
state.AgentID = types.StringValue(agentGroupAssignment.Agent.Id)

// Set refreshed state
diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
Expand All @@ -192,7 +179,6 @@ func (r *agentGroupAssignmentResource) Update(
req resource.UpdateRequest,
resp *resource.UpdateResponse,
) {
// Retrieve values from plan
var plan agentGroupAssignmentResourceModel
diags := req.Plan.Get(ctx, &plan)
diags.AddError("operation not supported", "updating an agent group assignment is not supported")
Expand All @@ -207,15 +193,25 @@ func (r *agentGroupAssignmentResource) Delete(
req resource.DeleteRequest,
resp *resource.DeleteResponse,
) {
// Retrieve values from state
var state agentGroupAssignmentResourceModel
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Delete existing agentGroupAssignment using the plan_id
request := r.client.ConfigurationAPI.
AgentGroupAssignmentDelete(ctx, state.ID.ValueString())
_, response, err := util.RetryFor429(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
resp.Diagnostics.AddError(
util.GenerateErrorSummary("delete", "uxi_agent_group_assignment"),
errorDetail,
)
return
}
}

func (r *agentGroupAssignmentResource) ImportState(
Expand Down
Loading

0 comments on commit bc28618

Please sign in to comment.