@@ -18,6 +18,7 @@ import {
1818 INSTANCE_MAX_CPU ,
1919 INSTANCE_MAX_RAM_GiB ,
2020 INSTANCE_MIN_RAM_GiB ,
21+ MAX_DISKS_PER_INSTANCE ,
2122 MAX_NICS_PER_INSTANCE ,
2223 type AffinityGroupMember ,
2324 type AntiAffinityGroupMember ,
@@ -424,6 +425,10 @@ export const handlers = makeHandlers({
424425 if ( body . disks ) allDisks . push ( ...body . disks )
425426 if ( body . boot_disk ) allDisks . push ( body . boot_disk )
426427
428+ if ( allDisks . length > MAX_DISKS_PER_INSTANCE ) {
429+ throw `Cannot attach more than ${ MAX_DISKS_PER_INSTANCE } disks to an instance`
430+ }
431+
427432 for ( const diskParams of allDisks ) {
428433 if ( diskParams . type === 'create' ) {
429434 errIfExists ( db . disks , { name : diskParams . name , project_id : project . id } , 'disk' )
@@ -701,6 +706,12 @@ export const handlers = makeHandlers({
701706 if ( instance . run_state !== 'stopped' ) {
702707 throw 'Cannot attach disk to instance that is not stopped'
703708 }
709+ const attachedDisks = db . disks . filter (
710+ ( d ) => 'instance' in d . state && d . state . instance === instance . id
711+ )
712+ if ( attachedDisks . length >= MAX_DISKS_PER_INSTANCE ) {
713+ throw `Cannot attach more than ${ MAX_DISKS_PER_INSTANCE } disks to an instance`
714+ }
704715 const disk = lookup . disk ( { ...projectParams , disk : body . disk } )
705716 disk . state = {
706717 state : 'attached' ,
0 commit comments