@@ -15,15 +15,16 @@ import type { SetRequired } from 'type-fest'
1515
1616import {
1717 api ,
18+ DEFAULT_VPC_NAME ,
1819 diskCan ,
1920 genName ,
20- hasDefaultVpc ,
2121 INSTANCE_MAX_CPU ,
2222 INSTANCE_MAX_RAM_GiB ,
2323 isUnicastPool ,
2424 MAX_DISK_SIZE_GiB ,
2525 poolHasIpVersion ,
2626 q ,
27+ qErrorsAllowed ,
2728 queryClient ,
2829 useApiMutation ,
2930 usePrefetchedQuery ,
@@ -234,6 +235,21 @@ const baseDefaultValues: InstanceCreateInput = {
234235 floatingIps : [ ] ,
235236}
236237
238+ // We disable the default_* NIC types in the form if either
239+ // the default VPC or default subnet is missing.
240+ // (Both use the name `default`).
241+ const defaultSubnetView = ( project : string ) =>
242+ qErrorsAllowed (
243+ api . vpcSubnetView ,
244+ { path : { subnet : DEFAULT_VPC_NAME } , query : { project, vpc : DEFAULT_VPC_NAME } } ,
245+ {
246+ errorsExpected : {
247+ explanation : 'the project may not have a default VPC and subnet.' ,
248+ statusCode : 404 ,
249+ } ,
250+ }
251+ )
252+
237253export async function clientLoader ( { params } : Route . ClientLoaderArgs ) {
238254 const { project } = params
239255 await Promise . all ( [
@@ -247,6 +263,7 @@ export async function clientLoader({ params }: Route.ClientLoaderArgs) {
247263 q ( api . floatingIpList , { query : { project, limit : ALL_ISH } } )
248264 ) ,
249265 queryClient . prefetchQuery ( q ( api . vpcList , { query : { project, limit : ALL_ISH } } ) ) ,
266+ queryClient . prefetchQuery ( defaultSubnetView ( project ) ) ,
250267 ] )
251268 return null
252269}
@@ -421,13 +438,15 @@ export default function CreateInstanceForm() {
421438 const { data : vpcs } = usePrefetchedQuery (
422439 q ( api . vpcList , { query : { project, limit : ALL_ISH } } )
423440 )
441+ const { data : defaultSubnet } = usePrefetchedQuery ( defaultSubnetView ( project ) )
442+ const defaultNetworkingAvailable = defaultSubnet . type === 'success'
424443
425444 // Determine default network interface type:
426- // - If a default VPC exists : default to dual-stack (API default, works with both IPv4 and IPv6 subnets)
445+ // - If a default VPC and subnet exist : default to dual-stack (API default, works with both IPv4 and IPv6 subnets)
427446 // - Otherwise: default to 'none' (user must create a VPC first or use custom NICs)
428447 // Note: Decoupled from external IP pool configuration, as NIC IP stack and external IPs are separate concerns
429448 const defaultNetworkInterfaceType : InstanceNetworkInterfaceAttachment [ 'type' ] =
430- hasDefaultVpc ( vpcs . items ) ? 'default_dual_stack' : 'none'
449+ defaultNetworkingAvailable ? 'default_dual_stack' : 'none'
431450
432451 const defaultSource =
433452 siloImages . length > 0 ? 'siloImage' : projectImages . length > 0 ? 'projectImage' : 'disk'
@@ -840,6 +859,7 @@ export default function CreateInstanceForm() {
840859 isSubmitting = { isSubmitting }
841860 unicastPools = { unicastPools }
842861 vpcs = { vpcs . items }
862+ defaultNetworkingAvailable = { defaultNetworkingAvailable }
843863 />
844864 < FormDivider />
845865 < Form . Heading id = "advanced" > Advanced</ Form . Heading >
@@ -879,11 +899,13 @@ const NetworkingSection = ({
879899 isSubmitting,
880900 unicastPools,
881901 vpcs,
902+ defaultNetworkingAvailable,
882903} : {
883904 control : Control < InstanceCreateInput >
884905 isSubmitting : boolean
885906 unicastPools : UnicastIpPool [ ]
886907 vpcs : Vpc [ ]
908+ defaultNetworkingAvailable : boolean
887909} ) => {
888910 const networkInterfaces = useWatch ( { control, name : 'networkInterfaces' } )
889911 const [ floatingIpModalOpen , setFloatingIpModalOpen ] = useState ( false )
@@ -966,7 +988,12 @@ const NetworkingSection = ({
966988 { vpcMessage && (
967989 < Message className = "mb-4 max-w-lg" variant = "notice" content = { vpcMessage } />
968990 ) }
969- < NetworkInterfaceField control = { control } disabled = { isSubmitting } vpcs = { vpcs } />
991+ < NetworkInterfaceField
992+ control = { control }
993+ disabled = { isSubmitting }
994+ vpcs = { vpcs }
995+ defaultNetworkingAvailable = { defaultNetworkingAvailable }
996+ />
970997
971998 < div className = "flex flex-1 flex-col gap-4" >
972999 < h2 className = "text-sans-md flex items-center" >
0 commit comments