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 13, 2024
1 parent bb85c20 commit f5f3a63
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions internal/provider/integration_shodan_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,26 @@ func (r *integrationShodanResource) Read(ctx context.Context, req resource.ReadR
}

// Read API call logic
integration, err := r.client.GetClientIntegration(ctx, data.Mrn.ValueString())
if err != nil {
resp.State.RemoveResource(ctx)
return
}

model := integrationShodanResourceModel{
Mrn: types.StringValue(integration.Mrn),
Name: types.StringValue(integration.Name),
SpaceID: types.StringValue(integration.SpaceID()),
Targets: ConvertListValue(
integration.ConfigurationOptions.ShodanConfigurationOptions.Targets,
),
Credentials: &integrationShodanCredentialModel{
Token: types.StringValue(data.Credentials.Token.ValueString()),
},
}

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

func (r *integrationShodanResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down Expand Up @@ -239,7 +256,7 @@ func (r *integrationShodanResource) Update(ctx context.Context, req resource.Upd
Diagnostics.
AddError("Client Error",
fmt.Sprintf(
"Unable to update Domain integration, got error: %s", err,
"Unable to update Shodan integration, got error: %s", err,
),
)
return
Expand All @@ -266,7 +283,7 @@ func (r *integrationShodanResource) Delete(ctx context.Context, req resource.Del
Diagnostics.
AddError("Client Error",
fmt.Sprintf(
"Unable to delete Domain integration, got error: %s", err,
"Unable to delete Shodan integration, got error: %s", err,
),
)
return
Expand Down

0 comments on commit f5f3a63

Please sign in to comment.