Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: only display compute addons if cloud provider supports them (#27599)

Paul Cioanca90d9d6cb1e7c
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
index a2e528f84d1..c4be80a973e 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
@@ -1,7 +1,3 @@
-import { components } from 'api-types'
-
-type DesiredInstanceSize = components['schemas']['DesiredInstanceSize']
-
// [Joshen] Obtained from https://gist.github.com/tadast/8827699
export const COUNTRY_LAT_LON = {
AF: { lat: 33, lon: 65 },
@@ -256,82 +252,3 @@ export const COUNTRY_LAT_LON = {
ZM: { lat: -15, lon: 30 },
ZW: { lat: -20, lon: 30 },
}
-
-export const INSTANCE_SIZE_SPECS: Record<
- DesiredInstanceSize,
- { label: string; ram: string; cpu: string; price: string }
-> = {
- micro: {
- label: 'Micro',
- ram: '1 GB',
- cpu: '2-core ARM',
- price: '$0.01344/hour (~$10/month)',
- },
- small: {
- label: 'Small',
- ram: '2 GB',
- cpu: '2-core ARM',
- price: '$0.0206/hour (~$15/month)',
- },
- medium: {
- label: 'Medium',
- ram: '4 GB',
- cpu: '2-core ARM',
- price: '$0.0822/hour (~$60/month)',
- },
- large: {
- label: 'Large',
- ram: '8 GB',
- cpu: '2-core ARM',
- price: '$0.1517/hour (~$110/month)',
- },
- xlarge: {
- label: 'XL',
- ram: '16 GB',
- cpu: '4-core ARM',
- price: '$0.2877/hour (~$210/month)',
- },
- '2xlarge': {
- label: '2XL',
- ram: '32 GB',
- cpu: '8-core ARM',
- price: '$0.562/hour (~$410/month)',
- },
- '4xlarge': {
- label: '4XL',
- ram: '64 GB',
- cpu: '16-core ARM',
- price: '$1.32/hour (~$960/month)',
- },
- '8xlarge': {
- label: '8XL',
- ram: '128 GB',
- cpu: '32-core ARM',
- price: '$2.562/hour (~$1,870/month)',
- },
- '12xlarge': {
- label: '12XL',
- ram: '192 GB',
- cpu: '48-core ARM',
- price: '$3.836/hour (~$2,800/month)',
- },
- '16xlarge': {
- label: '16XL',
- ram: '256 GB',
- cpu: '64-core ARM',
- price: '$5.12/hour (~$3,730/month)',
- },
-}
-
-export const AVAILABLE_SIZES: DesiredInstanceSize[] = [
- 'micro',
- 'small',
- 'medium',
- 'large',
- 'xlarge',
- '2xlarge',
- '4xlarge',
- '8xlarge',
- '12xlarge',
- '16xlarge',
-]
diff --git a/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx b/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
index 607a29210b7..9183d83a560 100644
--- a/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
@@ -115,7 +115,20 @@ const ComputeInstanceSidePanel = () => {
const availableOptions = useMemo(() => {
const computeOptions =
- availableAddons.find((addon) => addon.type === 'compute_instance')?.variants ?? []
+ availableAddons
+ .find((addon) => addon.type === 'compute_instance')
+ ?.variants.filter((option) => {
+ if (!selectedProject?.cloud_provider) {
+ return true
+ }
+
+ const meta = option.meta as ProjectAddonVariantMeta
+
+ return (
+ !meta.supported_cloud_providers ||
+ meta.supported_cloud_providers.includes(selectedProject.cloud_provider)
+ )
+ }) ?? []
// Backwards comp until API is deployed
if (!hasMicroOptionFromApi) {
diff --git a/apps/studio/data/subscriptions/types.ts b/apps/studio/data/subscriptions/types.ts
index a47351d1549..43c81ecb94b 100644
--- a/apps/studio/data/subscriptions/types.ts
+++ b/apps/studio/data/subscriptions/types.ts
@@ -28,6 +28,7 @@ export interface ProjectAddonVariantMeta {
connections_direct?: number
connections_pooler?: number
backup_duration_days?: number
+ supported_cloud_providers?: string[]
}
export type ProjectSelectedAddon = components['schemas']['SelectedAddonResponse']
diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsx
index 3a6ac03bb37..2f4e629e30b 100644
--- a/apps/studio/pages/new/[slug].tsx
+++ b/apps/studio/pages/new/[slug].tsx
@@ -24,6 +24,7 @@ import { useProjectsQuery } from 'data/projects/projects-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import generator from 'generate-password-browser'
import { useCheckPermissions, useFlag, withAuth } from 'hooks'
+import { getCloudProviderArchitecture } from 'lib/cloudprovider-utils'
import {
AWS_REGIONS_DEFAULT,
CloudProvider,
@@ -92,77 +93,94 @@ const sizes: DesiredInstanceSize[] = [
const instanceSizeSpecs: Record<
DesiredInstanceSize,
- { label: string; ram: string; cpu: string; priceHourly: number; priceMonthly: number }
+ {
+ label: string
+ ram: string
+ cpu: string
+ priceHourly: number
+ priceMonthly: number
+ cloud_providers: string[]
+ }
> = {
micro: {
label: 'Micro',
ram: '1 GB',
- cpu: '2-core ARM',
+ cpu: '2-core',
priceHourly: 0.01344,
priceMonthly: 10,
+ cloud_providers: [PROVIDERS.AWS.id, PROVIDERS.FLY.id],
},
small: {
label: 'Small',
ram: '2 GB',
- cpu: '2-core ARM',
+ cpu: '2-core',
priceHourly: 0.0206,
priceMonthly: 15,
+ cloud_providers: [PROVIDERS.AWS.id, PROVIDERS.FLY.id],
},
medium: {
label: 'Medium',
ram: '4 GB',
- cpu: '2-core ARM',
+ cpu: '2-core',
priceHourly: 0.0822,
priceMonthly: 60,
+ cloud_providers: [PROVIDERS.AWS.id, PROVIDERS.FLY.id],
},
large: {
label: 'Large',
ram: '8 GB',
- cpu: '2-core ARM',
+ cpu: '2-core',
priceHourly: 0.1517,
priceMonthly: 110,
+ cloud_providers: [PROVIDERS.AWS.id, PROVIDERS.FLY.id],
},
xlarge: {
label: 'XL',
ram: '16 GB',
- cpu: '4-core ARM',
+ cpu: '4-core',
priceHourly: 0.2877,
priceMonthly: 210,
+ cloud_providers: [PROVIDERS.AWS.id, PROVIDERS.FLY.id],
},
'2xlarge': {
label: '2XL',
ram: '32 GB',
- cpu: '8-core ARM',
+ cpu: '8-core',
priceHourly: 0.562,
priceMonthly: 410,
+ cloud_providers: [PROVIDERS.AWS.id, PROVIDERS.FLY.id],
},
'4xlarge': {
label: '4XL',
ram: '64 GB',
- cpu: '16-core ARM',
+ cpu: '16-core',
priceHourly: 1.32,
priceMonthly: 960,
+ cloud_providers: [PROVIDERS.AWS.id, PROVIDERS.FLY.id],
},
'8xlarge': {
label: '8XL',
ram: '128 GB',
- cpu: '32-core ARM',
+ cpu: '32-core',
priceHourly: 2.562,
priceMonthly: 1870,
+ cloud_providers: [PROVIDERS.AWS.id],
},
'12xlarge': {
label: '12XL',
ram: '192 GB',
- cpu: '48-core ARM',
+ cpu: '48-core',
priceHourly: 3.836,
priceMonthly: 2800,
+ cloud_providers: [PROVIDERS.AWS.id],
},
'16xlarge': {
label: '16XL',
ram: '256 GB',
- cpu: '64-core ARM',
+ cpu: '64-core',
priceHourly: 5.12,
priceMonthly: 3730,
+ cloud_providers: [PROVIDERS.AWS.id],
},
}
@@ -608,32 +626,42 @@ const Wizard: NextPageWithLayout = () => {
</SelectTrigger_Shadcn_>
<SelectContent_Shadcn_>
<SelectGroup_Shadcn_>
- {sizes.map((option) => {
- return (
- <SelectItem_Shadcn_ key={option} value={option}>
- <div className="flex flex-row i gap-2">
- <div className="text-center w-[80px]">
- <Badge
- variant={option === 'micro' ? 'default' : 'brand'}
- className="rounded-md w-16 text-center flex justify-center font-mono uppercase"
- >
- {instanceSizeSpecs[option].label}
- </Badge>
- </div>
- <div className="text-sm">
- <span className="text-foreground">
- {instanceSizeSpecs[option].ram} RAM /{' '}
- {instanceSizeSpecs[option].cpu} CPU
- </span>
- <p className="text-xs text-muted instance-details">
- ${instanceSizeSpecs[option].priceHourly}/hour (~$
- {instanceSizeSpecs[option].priceMonthly}/month)
- </p>
- </div>
- </div>
- </SelectItem_Shadcn_>
+ {sizes
+ .filter((option) =>
+ instanceSizeSpecs[option].cloud_providers.includes(
+ form.getValues('cloudProvider') as CloudProvider
+ )
)
- })}
+ .map((option) => {
+ return (
+ <SelectItem_Shadcn_ key={option} value={option}>
+ <div className="flex flex-row i gap-2">
+ <div className="text-center w-[80px]">
+ <Badge
+ variant={option === 'micro' ? 'default' : 'brand'}
+ className="rounded-md w-16 text-center flex justify-center font-mono uppercase"
+ >
+ {instanceSizeSpecs[option].label}
+ </Badge>
+ </div>
+ <div className="text-sm">
+ <span className="text-foreground">
+ {instanceSizeSpecs[option].ram} RAM /{' '}
+ {instanceSizeSpecs[option].cpu}{' '}
+ {getCloudProviderArchitecture(
+ form.getValues('cloudProvider') as CloudProvider
+ )}{' '}
+ CPU
+ </span>
+ <p className="text-xs text-muted instance-details">
+ ${instanceSizeSpecs[option].priceHourly}/hour (~$
+ {instanceSizeSpecs[option].priceMonthly}/month)
+ </p>
+ </div>
+ </div>
+ </SelectItem_Shadcn_>
+ )
+ })}
</SelectGroup_Shadcn_>
</SelectContent_Shadcn_>
</Select_Shadcn_>