From ac23580df2a87e6656021b1d5b3dab1bb53d15e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Jan 2026 11:59:27 +0000 Subject: [PATCH] fix: handle non-default VPC in security group creation When creating security groups, the code now: - Prefers the default VPC if available - Falls back to the first available VPC if no default exists - Provides clear error if no VPCs are available - Logs which VPC is being used This fixes the error: "No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC." --- .../lib/aws-ec2-client.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/Cloud-Computer-Control-Panel/lib/aws-ec2-client.ts b/apps/Cloud-Computer-Control-Panel/lib/aws-ec2-client.ts index 9aa279b..9f77b8b 100644 --- a/apps/Cloud-Computer-Control-Panel/lib/aws-ec2-client.ts +++ b/apps/Cloud-Computer-Control-Panel/lib/aws-ec2-client.ts @@ -440,9 +440,18 @@ export async function createOrGetDokploySecurityGroup( return { groupId: existingGroups[0].groupId } } - // Get default VPC + // Get VPC - prefer default VPC, but fall back to first available VPC const vpcs = await describeVpcs(accessKeyId, secretAccessKey, region) const defaultVpc = vpcs.find((v) => v.isDefault) + const targetVpc = defaultVpc || vpcs[0] + + if (!targetVpc) { + throw new Error("No VPC available in this region. Please create a VPC first.") + } + + console.log( + `[EC2] Using VPC ${targetVpc.vpcId} (${defaultVpc ? "default" : "first available"}) for security group`, + ) // Create security group const { groupId } = await createSecurityGroup( @@ -451,7 +460,7 @@ export async function createOrGetDokploySecurityGroup( region, "dokploy-sg", "Dokploy security group - SSH, HTTP, HTTPS, and port 3000", - defaultVpc?.vpcId, + targetVpc.vpcId, ) if (!groupId) {