From 101af9eef8825875b286112f44019d66df93da0a Mon Sep 17 00:00:00 2001 From: Dean Oren Date: Sat, 18 Feb 2023 11:00:23 +0100 Subject: [PATCH] check for empty instance ID --- stackit/internal/resources/data-services/instance/actions.go | 5 +++++ stackit/internal/resources/mongodb-flex/instance/actions.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/stackit/internal/resources/data-services/instance/actions.go b/stackit/internal/resources/data-services/instance/actions.go index d10c5d33..5973faf1 100644 --- a/stackit/internal/resources/data-services/instance/actions.go +++ b/stackit/internal/resources/data-services/instance/actions.go @@ -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 } diff --git a/stackit/internal/resources/mongodb-flex/instance/actions.go b/stackit/internal/resources/mongodb-flex/instance/actions.go index e62f1f09..5f923916 100644 --- a/stackit/internal/resources/mongodb-flex/instance/actions.go +++ b/stackit/internal/resources/mongodb-flex/instance/actions.go @@ -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() {