@friggframework/devtools 2.0.0--canary.490.0276a54.0 → 2.0.0--canary.490.c5ad260.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/infrastructure/domains/networking/vpc-resolver.js +16 -1
- package/infrastructure/domains/networking/vpc-resolver.test.js +40 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +110 -0
- package/infrastructure/domains/shared/resource-discovery.test.js +36 -0
- package/package.json +7 -7
|
@@ -23,6 +23,7 @@ class VpcResourceResolver extends BaseResourceResolver {
|
|
|
23
23
|
*/
|
|
24
24
|
resolveVpc(appDefinition, discovery) {
|
|
25
25
|
const userIntent = appDefinition.vpc?.ownership?.vpc || 'auto';
|
|
26
|
+
const vpcManagement = appDefinition.vpc?.management; // Legacy config
|
|
26
27
|
|
|
27
28
|
// Explicit external
|
|
28
29
|
if (userIntent === 'external') {
|
|
@@ -43,12 +44,26 @@ class VpcResourceResolver extends BaseResourceResolver {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
// Auto-decide
|
|
46
|
-
|
|
47
|
+
const decision = this.resolveResourceOwnership(
|
|
47
48
|
'auto',
|
|
48
49
|
'FriggVPC',
|
|
49
50
|
'AWS::EC2::VPC',
|
|
50
51
|
discovery
|
|
51
52
|
);
|
|
53
|
+
|
|
54
|
+
// CRITICAL: If auto-resolution wants to create a VPC but management mode is 'discover' (or undefined),
|
|
55
|
+
// throw an error instead. Creating a VPC is expensive and should be explicit.
|
|
56
|
+
if (decision.ownership === ResourceOwnership.STACK &&
|
|
57
|
+
!decision.physicalId &&
|
|
58
|
+
vpcManagement !== 'create-new' &&
|
|
59
|
+
userIntent === 'auto') {
|
|
60
|
+
throw new Error(
|
|
61
|
+
'VPC discovery failed: No VPC found. ' +
|
|
62
|
+
'Either set vpc.management to "create-new" or provide vpc.vpcId with vpc.management "use-existing".'
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return decision;
|
|
52
67
|
}
|
|
53
68
|
|
|
54
69
|
/**
|
|
@@ -109,6 +109,46 @@ describe('VpcResourceResolver', () => {
|
|
|
109
109
|
expect(decision.physicalId).toBeUndefined();
|
|
110
110
|
expect(decision.reason).toContain('No existing resource found');
|
|
111
111
|
});
|
|
112
|
+
|
|
113
|
+
it('should throw error when auto mode finds no VPC and management is not create-new', () => {
|
|
114
|
+
const appDefinition = {
|
|
115
|
+
vpc: {
|
|
116
|
+
enable: true,
|
|
117
|
+
// No management specified - defaults to discover
|
|
118
|
+
// No ownership specified - defaults to auto
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const discovery = {
|
|
122
|
+
stackManaged: [],
|
|
123
|
+
external: [],
|
|
124
|
+
fromCloudFormation: false
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// Should throw error instead of trying to create VPC
|
|
128
|
+
expect(() => resolver.resolveVpc(appDefinition, discovery)).toThrow(
|
|
129
|
+
'VPC discovery failed: No VPC found'
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should allow creating VPC when management is create-new', () => {
|
|
134
|
+
const appDefinition = {
|
|
135
|
+
vpc: {
|
|
136
|
+
enable: true,
|
|
137
|
+
management: 'create-new'
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const discovery = {
|
|
141
|
+
stackManaged: [],
|
|
142
|
+
external: [],
|
|
143
|
+
fromCloudFormation: false
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Should NOT throw - create-new explicitly allows VPC creation
|
|
147
|
+
const decision = resolver.resolveVpc(appDefinition, discovery);
|
|
148
|
+
|
|
149
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
150
|
+
expect(decision.physicalId).toBeNull();
|
|
151
|
+
});
|
|
112
152
|
});
|
|
113
153
|
|
|
114
154
|
describe('resolveSecurityGroup', () => {
|
|
@@ -693,6 +693,116 @@ describe('CloudFormationDiscovery', () => {
|
|
|
693
693
|
expect(result.s3VpcEndpointId).toBe('vpce-legacy-s3');
|
|
694
694
|
expect(result.dynamoDbVpcEndpointId).toBe('vpce-legacy-ddb');
|
|
695
695
|
});
|
|
696
|
+
|
|
697
|
+
it('should extract FriggLambdaSecurityGroup from stack', async () => {
|
|
698
|
+
const mockStack = {
|
|
699
|
+
StackName: 'test-stack',
|
|
700
|
+
Outputs: [],
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const mockResources = [
|
|
704
|
+
{
|
|
705
|
+
LogicalResourceId: 'FriggLambdaSecurityGroup',
|
|
706
|
+
PhysicalResourceId: 'sg-01002240c6a446202',
|
|
707
|
+
ResourceType: 'AWS::EC2::SecurityGroup',
|
|
708
|
+
ResourceStatus: 'UPDATE_COMPLETE',
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
LogicalResourceId: 'FriggLambdaRouteTable',
|
|
712
|
+
PhysicalResourceId: 'rtb-08af43bbf0775602d',
|
|
713
|
+
ResourceType: 'AWS::EC2::RouteTable',
|
|
714
|
+
ResourceStatus: 'UPDATE_COMPLETE',
|
|
715
|
+
},
|
|
716
|
+
];
|
|
717
|
+
|
|
718
|
+
mockProvider.describeStack.mockResolvedValue(mockStack);
|
|
719
|
+
mockProvider.listStackResources.mockResolvedValue(mockResources);
|
|
720
|
+
|
|
721
|
+
const result = await cfDiscovery.discoverFromStack('test-stack');
|
|
722
|
+
|
|
723
|
+
// Lambda security group should be extracted
|
|
724
|
+
expect(result.lambdaSecurityGroupId).toBe('sg-01002240c6a446202');
|
|
725
|
+
expect(result.defaultSecurityGroupId).toBe('sg-01002240c6a446202');
|
|
726
|
+
expect(result.existingLogicalIds).toContain('FriggLambdaSecurityGroup');
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
it('should support FriggPrivateRoute naming for NAT routes', async () => {
|
|
730
|
+
const mockStack = {
|
|
731
|
+
StackName: 'test-stack',
|
|
732
|
+
Outputs: [],
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
const mockResources = [
|
|
736
|
+
{
|
|
737
|
+
LogicalResourceId: 'FriggLambdaRouteTable',
|
|
738
|
+
PhysicalResourceId: 'rtb-123',
|
|
739
|
+
ResourceType: 'AWS::EC2::RouteTable',
|
|
740
|
+
ResourceStatus: 'UPDATE_COMPLETE',
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
LogicalResourceId: 'FriggPrivateRoute',
|
|
744
|
+
PhysicalResourceId: 'rtb-123|0.0.0.0/0',
|
|
745
|
+
ResourceType: 'AWS::EC2::Route',
|
|
746
|
+
ResourceStatus: 'UPDATE_COMPLETE',
|
|
747
|
+
},
|
|
748
|
+
];
|
|
749
|
+
|
|
750
|
+
mockProvider.describeStack.mockResolvedValue(mockStack);
|
|
751
|
+
mockProvider.listStackResources.mockResolvedValue(mockResources);
|
|
752
|
+
|
|
753
|
+
const result = await cfDiscovery.discoverFromStack('test-stack');
|
|
754
|
+
|
|
755
|
+
// Both FriggNATRoute and FriggPrivateRoute should be recognized
|
|
756
|
+
expect(result.natRoute).toBe('rtb-123|0.0.0.0/0');
|
|
757
|
+
expect(result.routeTableId).toBe('rtb-123');
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
it('should extract external references from route table without stackName error', async () => {
|
|
761
|
+
const mockStack = {
|
|
762
|
+
StackName: 'test-stack',
|
|
763
|
+
Outputs: [],
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
const mockResources = [
|
|
767
|
+
{
|
|
768
|
+
LogicalResourceId: 'FriggLambdaRouteTable',
|
|
769
|
+
PhysicalResourceId: 'rtb-real-id',
|
|
770
|
+
ResourceType: 'AWS::EC2::RouteTable',
|
|
771
|
+
ResourceStatus: 'UPDATE_COMPLETE',
|
|
772
|
+
},
|
|
773
|
+
];
|
|
774
|
+
|
|
775
|
+
mockProvider.describeStack.mockResolvedValue(mockStack);
|
|
776
|
+
mockProvider.listStackResources.mockResolvedValue(mockResources);
|
|
777
|
+
|
|
778
|
+
// Mock EC2 DescribeRouteTables to return route table with VPC info
|
|
779
|
+
mockProvider.getEC2Client = jest.fn().mockReturnValue({
|
|
780
|
+
send: jest.fn().mockResolvedValue({
|
|
781
|
+
RouteTables: [{
|
|
782
|
+
RouteTableId: 'rtb-real-id',
|
|
783
|
+
VpcId: 'vpc-extracted',
|
|
784
|
+
Routes: [
|
|
785
|
+
{ NatGatewayId: 'nat-extracted', DestinationCidrBlock: '0.0.0.0/0' }
|
|
786
|
+
],
|
|
787
|
+
Associations: [
|
|
788
|
+
{ SubnetId: 'subnet-1' },
|
|
789
|
+
{ SubnetId: 'subnet-2' }
|
|
790
|
+
]
|
|
791
|
+
}]
|
|
792
|
+
})
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
const result = await cfDiscovery.discoverFromStack('test-stack');
|
|
796
|
+
|
|
797
|
+
// Should extract VPC, NAT, and subnets from route table
|
|
798
|
+
expect(result.defaultVpcId).toBe('vpc-extracted');
|
|
799
|
+
expect(result.existingNatGatewayId).toBe('nat-extracted');
|
|
800
|
+
expect(result.privateSubnetId1).toBe('subnet-1');
|
|
801
|
+
expect(result.privateSubnetId2).toBe('subnet-2');
|
|
802
|
+
|
|
803
|
+
// Should NOT throw 'stackName is not defined' error
|
|
804
|
+
expect(result).toBeDefined();
|
|
805
|
+
});
|
|
696
806
|
});
|
|
697
807
|
});
|
|
698
808
|
|
|
@@ -415,6 +415,42 @@ describe('Resource Discovery', () => {
|
|
|
415
415
|
delete process.env.SLS_STAGE;
|
|
416
416
|
});
|
|
417
417
|
|
|
418
|
+
it('should recognize routing infrastructure as useful data', async () => {
|
|
419
|
+
const appDefinition = {
|
|
420
|
+
name: 'test-app',
|
|
421
|
+
vpc: { enable: true },
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
process.env.SLS_STAGE = 'production';
|
|
425
|
+
|
|
426
|
+
// Mock CloudFormation discovery to return routing infrastructure but no VPC resource
|
|
427
|
+
const mockCloudFormationDiscovery = {
|
|
428
|
+
discoverFromStack: jest.fn().mockResolvedValue({
|
|
429
|
+
fromCloudFormationStack: true,
|
|
430
|
+
routeTableId: 'rtb-123',
|
|
431
|
+
natRoute: 'rtb-123|0.0.0.0/0',
|
|
432
|
+
vpcEndpoints: {
|
|
433
|
+
s3: 'vpce-s3',
|
|
434
|
+
dynamodb: 'vpce-ddb'
|
|
435
|
+
},
|
|
436
|
+
existingLogicalIds: ['FriggLambdaRouteTable', 'FriggNATRoute']
|
|
437
|
+
// NO defaultVpcId, NO defaultKmsKeyId, NO auroraClusterId
|
|
438
|
+
})
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const { CloudFormationDiscovery } = require('./cloudformation-discovery');
|
|
442
|
+
CloudFormationDiscovery.mockImplementation(() => mockCloudFormationDiscovery);
|
|
443
|
+
|
|
444
|
+
const result = await gatherDiscoveredResources(appDefinition);
|
|
445
|
+
|
|
446
|
+
// Should use CloudFormation data without falling back to AWS API
|
|
447
|
+
expect(result.routeTableId).toBe('rtb-123');
|
|
448
|
+
expect(result.vpcEndpoints.s3).toBe('vpce-s3');
|
|
449
|
+
|
|
450
|
+
// Should NOT call AWS API discovery
|
|
451
|
+
expect(mockVpcDiscovery.discover).not.toHaveBeenCalled();
|
|
452
|
+
});
|
|
453
|
+
|
|
418
454
|
it('should include secrets in SSM discovery by default', async () => {
|
|
419
455
|
const appDefinition = {
|
|
420
456
|
ssm: { enable: true },
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/devtools",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.490.
|
|
4
|
+
"version": "2.0.0--canary.490.c5ad260.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"frigg": "./frigg-cli/index.js"
|
|
7
7
|
},
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"@babel/eslint-parser": "^7.18.9",
|
|
17
17
|
"@babel/parser": "^7.25.3",
|
|
18
18
|
"@babel/traverse": "^7.25.3",
|
|
19
|
-
"@friggframework/core": "2.0.0--canary.490.
|
|
20
|
-
"@friggframework/schemas": "2.0.0--canary.490.
|
|
21
|
-
"@friggframework/test": "2.0.0--canary.490.
|
|
19
|
+
"@friggframework/core": "2.0.0--canary.490.c5ad260.0",
|
|
20
|
+
"@friggframework/schemas": "2.0.0--canary.490.c5ad260.0",
|
|
21
|
+
"@friggframework/test": "2.0.0--canary.490.c5ad260.0",
|
|
22
22
|
"@hapi/boom": "^10.0.1",
|
|
23
23
|
"@inquirer/prompts": "^5.3.8",
|
|
24
24
|
"axios": "^1.7.2",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"validate-npm-package-name": "^5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@friggframework/eslint-config": "2.0.0--canary.490.
|
|
50
|
-
"@friggframework/prettier-config": "2.0.0--canary.490.
|
|
49
|
+
"@friggframework/eslint-config": "2.0.0--canary.490.c5ad260.0",
|
|
50
|
+
"@friggframework/prettier-config": "2.0.0--canary.490.c5ad260.0",
|
|
51
51
|
"aws-sdk-client-mock": "^4.1.0",
|
|
52
52
|
"aws-sdk-client-mock-jest": "^4.1.0",
|
|
53
53
|
"jest": "^30.1.3",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"publishConfig": {
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "c5ad26056632a30d7ce772e3af8209e0b2d2014e"
|
|
83
83
|
}
|