diff --git a/lxd/instances_post.go b/lxd/instances_post.go index 7d5cd4e6255c..5a15f6b632dd 100644 --- a/lxd/instances_post.go +++ b/lxd/instances_post.go @@ -1240,15 +1240,6 @@ func instancesPost(d *Daemon, r *http.Request) response.Response { } } - if !clusterNotification { - // Check that the project's limits are not violated. Note this check is performed after - // automatically generated config values (such as ones from an InstanceType) have been set. - err = project.AllowInstanceCreation(s.GlobalConfig, tx, targetProjectName, req) - if err != nil { - return err - } - } - return nil }) if err != nil { @@ -1320,6 +1311,15 @@ func instancesPost(d *Daemon, r *http.Request) response.Response { return operations.ForwardedOperationResponse(targetProjectName, &opAPI) } + // Check that the project's limits are not violated. Note this check is performed after + // automatically generated config values (such as ones from an InstanceType) have been set. + err = s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error { + return project.AllowInstanceCreation(s.GlobalConfig, tx, targetProjectName, req) + }) + if err != nil { + return response.SmartError(err) + } + switch req.Source.Type { case "image": return createFromImage(s, r, *targetProject, profiles, sourceImage, sourceImageRef, &req)