func()

in teamcity/group_role_assignment.go [120:162]


func (r *groupRoleAssignmentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
	var state groupRoleAssignmentResourceModel
	diags := req.State.Get(ctx, &state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	// Get group to verify role assignment still exists
	group, err := r.client.GetGroup(state.GroupId.ValueString())
	if err != nil {
		resp.Diagnostics.AddError(
			"Error reading group",
			err.Error(),
		)
		return
	}

	if group == nil {
		resp.State.RemoveResource(ctx)
		return
	}

	// Check if role assignment still exists
	found := false
	if group.Roles != nil {
		for _, role := range group.Roles.RoleAssignment {
			if role.Id == state.RoleId.ValueString() && role.Scope == state.Scope.ValueString() {
				found = true
				break
			}
		}
	}

	if !found {
		resp.State.RemoveResource(ctx)
		return
	}

	// Role assignment exists, keep current state
	diags = resp.State.Set(ctx, state)
	resp.Diagnostics.Append(diags...)
}