Skip to content

Commit

Permalink
feat: added read functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Theuermann <[email protected]>
  • Loading branch information
mati007thm committed Dec 11, 2024
1 parent 0496f60 commit 8d79b24
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion internal/provider/integration_email_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,34 @@ func (r *integrationEmailResource) Read(ctx context.Context, req resource.ReadRe
}

// Read API call logic
integration, err := r.client.GetClientIntegration(ctx, data.Mrn.ValueString())
if err != nil {
resp.Diagnostics.
AddError("Client Error", fmt.Sprintf("Unable to read Email integration, got error: %s", err))
return
}

var recipients []integrationEmailRecipientInput
for _, recipient := range integration.ConfigurationOptions.EmailConfigurationOptions.Recipients {
recipients = append(recipients, integrationEmailRecipientInput{
Name: types.StringValue(recipient.Name),
Email: types.StringValue(recipient.Email),
IsDefault: types.BoolValue(recipient.IsDefault),
ReferenceURL: types.StringValue(recipient.ReferenceURL),
})
}

model := integrationEmailResourceModel{
Mrn: types.StringValue(integration.Mrn),
Name: types.StringValue(integration.Name),
SpaceID: types.StringValue(integration.SpaceID()),
AutoCreateTickets: types.BoolValue(integration.ConfigurationOptions.EmailConfigurationOptions.AutoCreateTickets),
AutoCloseTickets: types.BoolValue(data.AutoCreateTickets.ValueBool()),
Recipients: &recipients,
}

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
resp.Diagnostics.Append(resp.State.Set(ctx, &model)...)
}

func (r *integrationEmailResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down

0 comments on commit 8d79b24

Please sign in to comment.