Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe("cloudchamber create", () => {
runWrangler("cloudchamber create ")
).rejects.toThrowErrorMatchingInlineSnapshot(
` [Error: Processing wrangler.toml configuration:
- "instance_type" should be one of 'dev', 'basic', or 'standard', but got invalid]`
- "instance_type" should be one of 'lite', 'basic', 'standard-1', 'standard-2', 'standard-3', or 'standard-4', but got invalid]`
);
});

Expand Down
67 changes: 53 additions & 14 deletions packages/wrangler/src/cloudchamber/instance-type/instance-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import type {
} from "@cloudflare/containers-shared";

const instanceTypes = {
// dev is the default instance type when REQUIRE_INSTANCE_TYPE is set
// lite is the default instance type when REQUIRE_INSTANCE_TYPE is set
lite: {
vcpu: 0.0625,
memory_mib: 256,
disk_mb: 2000,
},
dev: {
vcpu: 0.0625,
memory_mib: 256,
Expand All @@ -25,18 +30,55 @@ const instanceTypes = {
standard: {
vcpu: 0.5,
memory_mib: 4096,
disk_mb: 4000,
disk_mb: 8000,
},
"standard-1": {
vcpu: 0.5,
memory_mib: 4096,
disk_mb: 8000,
},
"standard-2": {
vcpu: 0.5,
memory_mib: 4096,
disk_mb: 12000,
},
"standard-3": {
vcpu: 0.5,
memory_mib: 4096,
disk_mb: 16000,
},
"standard-4": {
vcpu: 4,
memory_mib: 4096,
disk_mb: 20000,
},
} as const;

const instanceTypesNames = Object.keys(instanceTypes);

// prompts for instance type
export async function promptForInstanceType(
allowSkipping: boolean
): Promise<InstanceType | undefined> {
let options = [
{ label: "dev: 1/16 vCPU, 256 MiB memory, 2 GB disk", value: "dev" },
{ label: "lite: 1/16 vCPU, 256 MiB memory, 2 GB disk", value: "lite" },
{ label: "basic: 1/4 vCPU, 1 GiB memory, 4 GB disk", value: "basic" },
{ label: "standard: 1/2 vCPU, 4 GiB memory, 4 GB disk", value: "standard" },
{
label: "standard-1: 1/2 vCPU, 4 GiB memory, 8 GB disk",
value: "standard-1",
},
{
label: "standard-2: 1/2 vCPU, 4 GiB memory, 12 GB disk",
value: "standard-2",
},
{
label: "standard-3: 1/2 vCPU, 4 GiB memory, 16 GB disk",
value: "standard-3",
},
{
label: "standard-4: 4 vCPU, 4 GiB memory, 20 GB disk",
value: "standard-4",
},
];
if (allowSkipping) {
options = [{ label: "Do not set", value: "skip" }].concat(options);
Expand All @@ -60,7 +102,7 @@ export async function promptForInstanceType(
}
}

// Checks that instance type is one of 'dev', 'basic', or 'standard' and that it is not being set alongside memory or vcpu.
// Checks that instance type is one of allowed names and that it is not being set alongside memory or vcpu.
// Returns the instance type to use if correctly set.
export function checkInstanceType(
args: {
Expand All @@ -83,15 +125,12 @@ export function checkInstanceType(
);
}

switch (instance_type) {
case "dev":
case "basic":
case "standard":
return instance_type as InstanceType;
default:
throw new UserError(
`"instance_type" field value is expected to be one of "dev", "basic", or "standard", but got "${instance_type}"`
);
if (instanceTypesNames.includes(instance_type)) {
return instance_type as InstanceType;
} else {
throw new UserError(
`"instance_type" field value is expected to be one of 'lite', 'basic', 'standard-1', 'standard-2', 'standard-3', 'standard-4', but got "${instance_type}"`
);
}
}

Expand Down
17 changes: 14 additions & 3 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ export type NormalizeAndValidateConfigArgs = {

const ENGLISH = new Intl.ListFormat("en-US");

const ALLOWED_INSTANCE_TYPES = [
"lite",
"basic",
"standard-1",
"standard-2",
"standard-3",
"standard-4",
"dev", // legacy
"standard", // legacy
Comment on lines +76 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should print a warning if these are used I think so users know they will go away at some point?

Also unsure but would it make sense to change user-provided values here from lite->dev and standard -> standard-1 and just say in the warning that you are doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah lets do this, but can do it in a follow up. Would like to get this one out and into next release

];

export function isPagesConfig(rawConfig: RawConfig): boolean {
return rawConfig.pages_build_output_dir !== undefined;
}
Expand Down Expand Up @@ -2796,7 +2807,7 @@ function validateContainerApp(
"instance_type",
containerAppOptional.instance_type,
"string",
["dev", "basic", "standard"]
ALLOWED_INSTANCE_TYPES
);
} else if (
validateOptionalProperty(
Expand Down Expand Up @@ -2871,10 +2882,10 @@ const validateCloudchamberConfig: ValidatorFn = (diagnostics, field, value) => {
if ("instance_type" in value && value.instance_type !== undefined) {
if (
typeof value.instance_type !== "string" ||
!["dev", "basic", "standard"].includes(value.instance_type)
ALLOWED_INSTANCE_TYPES.includes(value.instance_type)
) {
diagnostics.errors.push(
`"instance_type" should be one of 'dev', 'basic', or 'standard', but got ${value.instance_type}`
`"instance_type" should be one of 'lite', 'basic', 'standard-1', 'standard-2', 'standard-3', or 'standard-4', but got ${value.instance_type}`
);
}

Expand Down
Loading