@friggframework/devtools 2.0.0--canary.461.849e166.0 → 2.0.0--canary.474.aa465e4.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/ARCHITECTURE.md +487 -0
- package/infrastructure/domains/database/aurora-builder.js +234 -57
- package/infrastructure/domains/database/aurora-builder.test.js +7 -2
- package/infrastructure/domains/database/aurora-resolver.js +210 -0
- package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
- package/infrastructure/domains/database/migration-builder.js +256 -215
- package/infrastructure/domains/database/migration-builder.test.js +5 -111
- package/infrastructure/domains/database/migration-resolver.js +163 -0
- package/infrastructure/domains/database/migration-resolver.test.js +337 -0
- package/infrastructure/domains/integration/integration-builder.js +258 -84
- package/infrastructure/domains/integration/integration-resolver.js +170 -0
- package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
- package/infrastructure/domains/networking/vpc-builder.js +856 -135
- package/infrastructure/domains/networking/vpc-builder.test.js +10 -6
- package/infrastructure/domains/networking/vpc-resolver.js +324 -0
- package/infrastructure/domains/networking/vpc-resolver.test.js +501 -0
- package/infrastructure/domains/security/kms-builder.js +179 -22
- package/infrastructure/domains/security/kms-resolver.js +96 -0
- package/infrastructure/domains/security/kms-resolver.test.js +216 -0
- package/infrastructure/domains/shared/base-resolver.js +186 -0
- package/infrastructure/domains/shared/base-resolver.test.js +305 -0
- package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +26 -1
- package/infrastructure/domains/shared/types/app-definition.js +205 -0
- package/infrastructure/domains/shared/types/discovery-result.js +106 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
- package/infrastructure/domains/shared/types/index.js +46 -0
- package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
- package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
- package/package.json +6 -6
- package/infrastructure/REFACTOR.md +0 -532
- package/infrastructure/TRANSFORMATION-VISUAL.md +0 -239
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration Resource Resolver
|
|
3
|
+
*
|
|
4
|
+
* Resolves migration resource ownership based on user intent and discovered resources.
|
|
5
|
+
*
|
|
6
|
+
* Migration resources:
|
|
7
|
+
* - S3 bucket for migration status tracking
|
|
8
|
+
* - SQS queue for migration jobs
|
|
9
|
+
*
|
|
10
|
+
* Ownership Resolution Logic:
|
|
11
|
+
* - User sets 'stack' → Create resources in CloudFormation stack
|
|
12
|
+
* - User sets 'external' → Use existing resources (discovered)
|
|
13
|
+
* - User sets 'auto' (or unspecified):
|
|
14
|
+
* - If resources found in stack → Use stack resources (STACK)
|
|
15
|
+
* - If resources found externally → Use external resources (EXTERNAL)
|
|
16
|
+
* - If nothing found → Create in stack (STACK)
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const BaseResourceResolver = require('../shared/base-resolver');
|
|
20
|
+
const { ResourceOwnership } = require('../shared/types');
|
|
21
|
+
|
|
22
|
+
class MigrationResourceResolver extends BaseResourceResolver {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Resolve S3 migration status bucket ownership
|
|
29
|
+
* @param {Object} appDefinition - Application definition
|
|
30
|
+
* @param {Object} discovery - Structured discovery result
|
|
31
|
+
* @returns {Object} Ownership decision with metadata
|
|
32
|
+
*/
|
|
33
|
+
resolveBucket(appDefinition, discovery) {
|
|
34
|
+
// Get user intent from app definition
|
|
35
|
+
const userIntent = appDefinition.migration?.ownership?.bucket || ResourceOwnership.AUTO;
|
|
36
|
+
|
|
37
|
+
// Check if bucket exists in CloudFormation stack
|
|
38
|
+
const inStack = this.isInStack('FriggMigrationStatusBucket', discovery);
|
|
39
|
+
|
|
40
|
+
if (userIntent === ResourceOwnership.STACK) {
|
|
41
|
+
// Explicit: Create/manage in stack
|
|
42
|
+
const stackResource = inStack ? this.findInStack('FriggMigrationStatusBucket', discovery) : null;
|
|
43
|
+
return this.createStackDecision(
|
|
44
|
+
stackResource?.physicalId || null,
|
|
45
|
+
inStack ? 'Found FriggMigrationStatusBucket in CloudFormation stack' : 'Will create FriggMigrationStatusBucket in stack'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (userIntent === ResourceOwnership.EXTERNAL) {
|
|
50
|
+
// Explicit: Use external bucket
|
|
51
|
+
const external = this.findExternal('AWS::S3::Bucket', discovery);
|
|
52
|
+
if (!external) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
'ownership.bucket=external but no S3 bucket discovered. ' +
|
|
55
|
+
'Provide migrationStatusBucket in discoveredResources or set ownership.bucket=stack'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return this.createExternalDecision(
|
|
59
|
+
external.physicalId,
|
|
60
|
+
'Using external S3 bucket per ownership.bucket=external'
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// AUTO resolution
|
|
65
|
+
if (inStack) {
|
|
66
|
+
const stackResource = this.findInStack('FriggMigrationStatusBucket', discovery);
|
|
67
|
+
return this.createStackDecision(
|
|
68
|
+
stackResource.physicalId,
|
|
69
|
+
'Found FriggMigrationStatusBucket in CloudFormation stack'
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Check for external bucket
|
|
74
|
+
const external = this.findExternal('AWS::S3::Bucket', discovery);
|
|
75
|
+
if (external) {
|
|
76
|
+
return this.createExternalDecision(
|
|
77
|
+
external.physicalId,
|
|
78
|
+
'Found external S3 bucket via discovery'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// No bucket found - create in stack
|
|
83
|
+
return this.createStackDecision(
|
|
84
|
+
null,
|
|
85
|
+
'No existing migration bucket - will create in stack'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Resolve SQS migration queue ownership
|
|
91
|
+
* @param {Object} appDefinition - Application definition
|
|
92
|
+
* @param {Object} discovery - Structured discovery result
|
|
93
|
+
* @returns {Object} Ownership decision with metadata
|
|
94
|
+
*/
|
|
95
|
+
resolveQueue(appDefinition, discovery) {
|
|
96
|
+
// Get user intent from app definition
|
|
97
|
+
const userIntent = appDefinition.migration?.ownership?.queue || ResourceOwnership.AUTO;
|
|
98
|
+
|
|
99
|
+
// Check if queue exists in CloudFormation stack
|
|
100
|
+
const inStack = this.isInStack('DbMigrationQueue', discovery);
|
|
101
|
+
|
|
102
|
+
if (userIntent === ResourceOwnership.STACK) {
|
|
103
|
+
// Explicit: Create/manage in stack
|
|
104
|
+
const stackResource = inStack ? this.findInStack('DbMigrationQueue', discovery) : null;
|
|
105
|
+
return this.createStackDecision(
|
|
106
|
+
stackResource?.physicalId || null,
|
|
107
|
+
inStack ? 'Found DbMigrationQueue in CloudFormation stack' : 'Will create DbMigrationQueue in stack'
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (userIntent === ResourceOwnership.EXTERNAL) {
|
|
112
|
+
// Explicit: Use external queue
|
|
113
|
+
const external = this.findExternal('AWS::SQS::Queue', discovery);
|
|
114
|
+
if (!external) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
'ownership.queue=external but no SQS queue discovered. ' +
|
|
117
|
+
'Provide migrationQueueUrl in discoveredResources or set ownership.queue=stack'
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return this.createExternalDecision(
|
|
121
|
+
external.physicalId,
|
|
122
|
+
'Using external SQS queue per ownership.queue=external'
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// AUTO resolution
|
|
127
|
+
if (inStack) {
|
|
128
|
+
const stackResource = this.findInStack('DbMigrationQueue', discovery);
|
|
129
|
+
return this.createStackDecision(
|
|
130
|
+
stackResource.physicalId,
|
|
131
|
+
'Found DbMigrationQueue in CloudFormation stack'
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Check for external queue
|
|
136
|
+
const external = this.findExternal('AWS::SQS::Queue', discovery);
|
|
137
|
+
if (external) {
|
|
138
|
+
return this.createExternalDecision(
|
|
139
|
+
external.physicalId,
|
|
140
|
+
'Found external SQS queue via discovery'
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// No queue found - create in stack
|
|
145
|
+
return this.createStackDecision(
|
|
146
|
+
null,
|
|
147
|
+
'No existing migration queue - will create in stack'
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Resolve all migration resources
|
|
153
|
+
* Convenience method for resolving all migration resource ownership
|
|
154
|
+
*/
|
|
155
|
+
resolveAll(appDefinition, discovery) {
|
|
156
|
+
return {
|
|
157
|
+
bucket: this.resolveBucket(appDefinition, discovery),
|
|
158
|
+
queue: this.resolveQueue(appDefinition, discovery),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = { MigrationResourceResolver };
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
const { MigrationResourceResolver } = require('./migration-resolver');
|
|
2
|
+
const { ResourceOwnership, createEmptyDiscoveryResult } = require('../shared/types');
|
|
3
|
+
|
|
4
|
+
describe('MigrationResourceResolver', () => {
|
|
5
|
+
let resolver;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
resolver = new MigrationResourceResolver();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('resolveBucket', () => {
|
|
12
|
+
describe('Explicit ownership intent', () => {
|
|
13
|
+
it('should respect ownership.bucket=stack when specified', () => {
|
|
14
|
+
const appDefinition = {
|
|
15
|
+
migration: {
|
|
16
|
+
ownership: { bucket: 'stack' }
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const discovery = createEmptyDiscoveryResult();
|
|
20
|
+
|
|
21
|
+
const decision = resolver.resolveBucket(appDefinition, discovery);
|
|
22
|
+
|
|
23
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
24
|
+
expect(decision.physicalId).toBeNull();
|
|
25
|
+
expect(decision.reason).toContain('Will create FriggMigrationStatusBucket in stack');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should respect ownership.bucket=external when bucket discovered', () => {
|
|
29
|
+
const appDefinition = {
|
|
30
|
+
migration: {
|
|
31
|
+
ownership: { bucket: 'external' }
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const discovery = createEmptyDiscoveryResult();
|
|
35
|
+
discovery.external.push({
|
|
36
|
+
physicalId: 'my-migration-bucket',
|
|
37
|
+
resourceType: 'AWS::S3::Bucket',
|
|
38
|
+
source: 'aws-discovery'
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const decision = resolver.resolveBucket(appDefinition, discovery);
|
|
42
|
+
|
|
43
|
+
expect(decision.ownership).toBe(ResourceOwnership.EXTERNAL);
|
|
44
|
+
expect(decision.physicalId).toBe('my-migration-bucket');
|
|
45
|
+
expect(decision.reason).toContain('external');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should error when ownership.bucket=external but no bucket discovered', () => {
|
|
49
|
+
const appDefinition = {
|
|
50
|
+
migration: {
|
|
51
|
+
ownership: { bucket: 'external' }
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const discovery = createEmptyDiscoveryResult();
|
|
55
|
+
|
|
56
|
+
expect(() => resolver.resolveBucket(appDefinition, discovery))
|
|
57
|
+
.toThrow('ownership.bucket=external but no S3 bucket discovered');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('Auto resolution (ownership.bucket=auto)', () => {
|
|
62
|
+
it('should use stack bucket when found in CloudFormation', () => {
|
|
63
|
+
const appDefinition = {
|
|
64
|
+
migration: {
|
|
65
|
+
ownership: { bucket: 'auto' }
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const discovery = createEmptyDiscoveryResult();
|
|
69
|
+
discovery.fromCloudFormation = true;
|
|
70
|
+
discovery.stackManaged.push({
|
|
71
|
+
logicalId: 'FriggMigrationStatusBucket',
|
|
72
|
+
physicalId: 'stack-migration-bucket',
|
|
73
|
+
resourceType: 'AWS::S3::Bucket'
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const decision = resolver.resolveBucket(appDefinition, discovery);
|
|
77
|
+
|
|
78
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
79
|
+
expect(decision.physicalId).toBe('stack-migration-bucket');
|
|
80
|
+
expect(decision.reason).toContain('Found FriggMigrationStatusBucket in CloudFormation stack');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should use external bucket when found via discovery', () => {
|
|
84
|
+
const appDefinition = {
|
|
85
|
+
migration: {
|
|
86
|
+
ownership: { bucket: 'auto' }
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const discovery = createEmptyDiscoveryResult();
|
|
90
|
+
discovery.external.push({
|
|
91
|
+
physicalId: 'external-migration-bucket',
|
|
92
|
+
resourceType: 'AWS::S3::Bucket',
|
|
93
|
+
source: 'aws-discovery'
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const decision = resolver.resolveBucket(appDefinition, discovery);
|
|
97
|
+
|
|
98
|
+
expect(decision.ownership).toBe(ResourceOwnership.EXTERNAL);
|
|
99
|
+
expect(decision.physicalId).toBe('external-migration-bucket');
|
|
100
|
+
expect(decision.reason).toContain('Found external S3 bucket via discovery');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should create new bucket when none found', () => {
|
|
104
|
+
const appDefinition = {
|
|
105
|
+
migration: {
|
|
106
|
+
ownership: { bucket: 'auto' }
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const discovery = createEmptyDiscoveryResult();
|
|
110
|
+
|
|
111
|
+
const decision = resolver.resolveBucket(appDefinition, discovery);
|
|
112
|
+
|
|
113
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
114
|
+
expect(decision.physicalId).toBeNull();
|
|
115
|
+
expect(decision.reason).toContain('No existing migration bucket - will create in stack');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('Default behavior (no ownership specified)', () => {
|
|
120
|
+
it('should default to auto resolution', () => {
|
|
121
|
+
const appDefinition = {};
|
|
122
|
+
const discovery = createEmptyDiscoveryResult();
|
|
123
|
+
|
|
124
|
+
const decision = resolver.resolveBucket(appDefinition, discovery);
|
|
125
|
+
|
|
126
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
127
|
+
expect(decision.reason).toContain('No existing migration bucket - will create in stack');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('resolveQueue', () => {
|
|
133
|
+
describe('Explicit ownership intent', () => {
|
|
134
|
+
it('should respect ownership.queue=stack when specified', () => {
|
|
135
|
+
const appDefinition = {
|
|
136
|
+
migration: {
|
|
137
|
+
ownership: { queue: 'stack' }
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const discovery = createEmptyDiscoveryResult();
|
|
141
|
+
|
|
142
|
+
const decision = resolver.resolveQueue(appDefinition, discovery);
|
|
143
|
+
|
|
144
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
145
|
+
expect(decision.physicalId).toBeNull();
|
|
146
|
+
expect(decision.reason).toContain('Will create DbMigrationQueue in stack');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should respect ownership.queue=external when queue discovered', () => {
|
|
150
|
+
const appDefinition = {
|
|
151
|
+
migration: {
|
|
152
|
+
ownership: { queue: 'external' }
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const discovery = createEmptyDiscoveryResult();
|
|
156
|
+
discovery.external.push({
|
|
157
|
+
physicalId: 'https://sqs.us-east-1.amazonaws.com/123456789/my-migration-queue',
|
|
158
|
+
resourceType: 'AWS::SQS::Queue',
|
|
159
|
+
source: 'aws-discovery'
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const decision = resolver.resolveQueue(appDefinition, discovery);
|
|
163
|
+
|
|
164
|
+
expect(decision.ownership).toBe(ResourceOwnership.EXTERNAL);
|
|
165
|
+
expect(decision.physicalId).toBe('https://sqs.us-east-1.amazonaws.com/123456789/my-migration-queue');
|
|
166
|
+
expect(decision.reason).toContain('external');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should error when ownership.queue=external but no queue discovered', () => {
|
|
170
|
+
const appDefinition = {
|
|
171
|
+
migration: {
|
|
172
|
+
ownership: { queue: 'external' }
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const discovery = createEmptyDiscoveryResult();
|
|
176
|
+
|
|
177
|
+
expect(() => resolver.resolveQueue(appDefinition, discovery))
|
|
178
|
+
.toThrow('ownership.queue=external but no SQS queue discovered');
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('Auto resolution (ownership.queue=auto)', () => {
|
|
183
|
+
it('should use stack queue when found in CloudFormation', () => {
|
|
184
|
+
const appDefinition = {
|
|
185
|
+
migration: {
|
|
186
|
+
ownership: { queue: 'auto' }
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const discovery = createEmptyDiscoveryResult();
|
|
190
|
+
discovery.fromCloudFormation = true;
|
|
191
|
+
discovery.stackManaged.push({
|
|
192
|
+
logicalId: 'DbMigrationQueue',
|
|
193
|
+
physicalId: 'https://sqs.us-east-1.amazonaws.com/123456789/stack-migration-queue',
|
|
194
|
+
resourceType: 'AWS::SQS::Queue'
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const decision = resolver.resolveQueue(appDefinition, discovery);
|
|
198
|
+
|
|
199
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
200
|
+
expect(decision.physicalId).toBe('https://sqs.us-east-1.amazonaws.com/123456789/stack-migration-queue');
|
|
201
|
+
expect(decision.reason).toContain('Found DbMigrationQueue in CloudFormation stack');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should use external queue when found via discovery', () => {
|
|
205
|
+
const appDefinition = {
|
|
206
|
+
migration: {
|
|
207
|
+
ownership: { queue: 'auto' }
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const discovery = createEmptyDiscoveryResult();
|
|
211
|
+
discovery.external.push({
|
|
212
|
+
physicalId: 'https://sqs.us-east-1.amazonaws.com/123456789/external-migration-queue',
|
|
213
|
+
resourceType: 'AWS::SQS::Queue',
|
|
214
|
+
source: 'aws-discovery'
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const decision = resolver.resolveQueue(appDefinition, discovery);
|
|
218
|
+
|
|
219
|
+
expect(decision.ownership).toBe(ResourceOwnership.EXTERNAL);
|
|
220
|
+
expect(decision.physicalId).toBe('https://sqs.us-east-1.amazonaws.com/123456789/external-migration-queue');
|
|
221
|
+
expect(decision.reason).toContain('Found external SQS queue via discovery');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should create new queue when none found', () => {
|
|
225
|
+
const appDefinition = {
|
|
226
|
+
migration: {
|
|
227
|
+
ownership: { queue: 'auto' }
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const discovery = createEmptyDiscoveryResult();
|
|
231
|
+
|
|
232
|
+
const decision = resolver.resolveQueue(appDefinition, discovery);
|
|
233
|
+
|
|
234
|
+
expect(decision.ownership).toBe(ResourceOwnership.STACK);
|
|
235
|
+
expect(decision.physicalId).toBeNull();
|
|
236
|
+
expect(decision.reason).toContain('No existing migration queue - will create in stack');
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('resolveAll', () => {
|
|
242
|
+
it('should return decisions for all migration resources', () => {
|
|
243
|
+
const appDefinition = {
|
|
244
|
+
database: {
|
|
245
|
+
postgres: {
|
|
246
|
+
enable: true
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const discovery = createEmptyDiscoveryResult();
|
|
251
|
+
|
|
252
|
+
const decisions = resolver.resolveAll(appDefinition, discovery);
|
|
253
|
+
|
|
254
|
+
expect(decisions).toHaveProperty('bucket');
|
|
255
|
+
expect(decisions).toHaveProperty('queue');
|
|
256
|
+
expect(decisions.bucket.ownership).toBe(ResourceOwnership.STACK);
|
|
257
|
+
expect(decisions.queue.ownership).toBe(ResourceOwnership.STACK);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('Real-world scenarios', () => {
|
|
262
|
+
it('should handle managementMode=managed scenario (create resources)', () => {
|
|
263
|
+
// In managed mode, we want to create resources in stack
|
|
264
|
+
const appDefinition = {
|
|
265
|
+
managementMode: 'managed',
|
|
266
|
+
migration: {
|
|
267
|
+
ownership: { bucket: 'stack', queue: 'stack' }
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const discovery = createEmptyDiscoveryResult();
|
|
271
|
+
|
|
272
|
+
const decisions = resolver.resolveAll(appDefinition, discovery);
|
|
273
|
+
|
|
274
|
+
expect(decisions.bucket.ownership).toBe(ResourceOwnership.STACK);
|
|
275
|
+
expect(decisions.bucket.physicalId).toBeNull();
|
|
276
|
+
expect(decisions.queue.ownership).toBe(ResourceOwnership.STACK);
|
|
277
|
+
expect(decisions.queue.physicalId).toBeNull();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('should handle existing stack resources (reuse)', () => {
|
|
281
|
+
// Stack already has migration resources from previous deployment
|
|
282
|
+
const appDefinition = {
|
|
283
|
+
migration: {
|
|
284
|
+
ownership: { bucket: 'auto', queue: 'auto' }
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const discovery = createEmptyDiscoveryResult();
|
|
288
|
+
discovery.fromCloudFormation = true;
|
|
289
|
+
discovery.stackManaged.push({
|
|
290
|
+
logicalId: 'FriggMigrationStatusBucket',
|
|
291
|
+
physicalId: 'my-stack-bucket',
|
|
292
|
+
resourceType: 'AWS::S3::Bucket'
|
|
293
|
+
});
|
|
294
|
+
discovery.stackManaged.push({
|
|
295
|
+
logicalId: 'DbMigrationQueue',
|
|
296
|
+
physicalId: 'https://sqs.us-east-1.amazonaws.com/123/my-queue',
|
|
297
|
+
resourceType: 'AWS::SQS::Queue'
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const decisions = resolver.resolveAll(appDefinition, discovery);
|
|
301
|
+
|
|
302
|
+
expect(decisions.bucket.ownership).toBe(ResourceOwnership.STACK);
|
|
303
|
+
expect(decisions.bucket.physicalId).toBe('my-stack-bucket');
|
|
304
|
+
expect(decisions.queue.ownership).toBe(ResourceOwnership.STACK);
|
|
305
|
+
expect(decisions.queue.physicalId).toBe('https://sqs.us-east-1.amazonaws.com/123/my-queue');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('should handle shared migration resources scenario', () => {
|
|
309
|
+
// Using shared infrastructure migration resources
|
|
310
|
+
const appDefinition = {
|
|
311
|
+
managementMode: 'managed',
|
|
312
|
+
vpcIsolation: 'shared',
|
|
313
|
+
migration: {
|
|
314
|
+
ownership: { bucket: 'auto', queue: 'auto' }
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
const discovery = createEmptyDiscoveryResult();
|
|
318
|
+
discovery.external.push({
|
|
319
|
+
physicalId: 'shared-migration-bucket',
|
|
320
|
+
resourceType: 'AWS::S3::Bucket',
|
|
321
|
+
source: 'aws-discovery'
|
|
322
|
+
});
|
|
323
|
+
discovery.external.push({
|
|
324
|
+
physicalId: 'https://sqs.us-east-1.amazonaws.com/123/shared-queue',
|
|
325
|
+
resourceType: 'AWS::SQS::Queue',
|
|
326
|
+
source: 'aws-discovery'
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const decisions = resolver.resolveAll(appDefinition, discovery);
|
|
330
|
+
|
|
331
|
+
expect(decisions.bucket.ownership).toBe(ResourceOwnership.EXTERNAL);
|
|
332
|
+
expect(decisions.bucket.physicalId).toBe('shared-migration-bucket');
|
|
333
|
+
expect(decisions.queue.ownership).toBe(ResourceOwnership.EXTERNAL);
|
|
334
|
+
expect(decisions.queue.physicalId).toBe('https://sqs.us-east-1.amazonaws.com/123/shared-queue');
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
});
|