Skip to content

Commit

Permalink
check for empty instance ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Oren committed Feb 18, 2023
1 parent 66bb716 commit 101af9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stackit/internal/resources/data-services/instance/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func (r Resource) Create(ctx context.Context, req resource.CreateRequest, resp *

// set state
plan.ID = types.StringValue(res.JSON202.InstanceID)
if plan.ID.ValueString() == "" {
resp.Diagnostics.AddError("received an empty instance ID", fmt.Sprintf("invalid instance id: %+v", *res.JSON202))
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), res.JSON202.InstanceID)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), plan.ProjectID.ValueString())...)
if resp.Diagnostics.HasError() {
return
}
Expand Down
4 changes: 4 additions & 0 deletions stackit/internal/resources/mongodb-flex/instance/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (r Resource) Create(ctx context.Context, req resource.CreateRequest, resp *

instanceID := *res.JSON202.ID
plan.ID = types.StringValue(instanceID)
if instanceID == "" {
resp.Diagnostics.AddError("received an empty instance ID", fmt.Sprintf("invalid instance id: %+v", *res.JSON202))
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), instanceID)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), plan.ProjectID.ValueString())...)
if resp.Diagnostics.HasError() {
Expand Down

0 comments on commit 101af9e

Please sign in to comment.