@friggframework/devtools 2.0.0-next.45 → 2.0.0-next.46

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.
Files changed (212) hide show
  1. package/infrastructure/ARCHITECTURE.md +487 -0
  2. package/infrastructure/HEALTH.md +468 -0
  3. package/infrastructure/README.md +51 -0
  4. package/infrastructure/__tests__/postgres-config.test.js +914 -0
  5. package/infrastructure/__tests__/template-generation.test.js +687 -0
  6. package/infrastructure/create-frigg-infrastructure.js +1 -1
  7. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +630 -0
  8. package/infrastructure/{DEPLOYMENT-INSTRUCTIONS.md → docs/deployment-instructions.md} +3 -3
  9. package/infrastructure/{IAM-POLICY-TEMPLATES.md → docs/iam-policy-templates.md} +9 -10
  10. package/infrastructure/domains/database/aurora-builder.js +809 -0
  11. package/infrastructure/domains/database/aurora-builder.test.js +950 -0
  12. package/infrastructure/domains/database/aurora-discovery.js +87 -0
  13. package/infrastructure/domains/database/aurora-discovery.test.js +188 -0
  14. package/infrastructure/domains/database/aurora-resolver.js +210 -0
  15. package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
  16. package/infrastructure/domains/database/migration-builder.js +633 -0
  17. package/infrastructure/domains/database/migration-builder.test.js +294 -0
  18. package/infrastructure/domains/database/migration-resolver.js +163 -0
  19. package/infrastructure/domains/database/migration-resolver.test.js +337 -0
  20. package/infrastructure/domains/health/application/ports/IPropertyReconciler.js +164 -0
  21. package/infrastructure/domains/health/application/ports/IResourceDetector.js +129 -0
  22. package/infrastructure/domains/health/application/ports/IResourceImporter.js +142 -0
  23. package/infrastructure/domains/health/application/ports/IStackRepository.js +131 -0
  24. package/infrastructure/domains/health/application/ports/index.js +26 -0
  25. package/infrastructure/domains/health/application/use-cases/__tests__/execute-resource-import-use-case.test.js +679 -0
  26. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +167 -0
  27. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +1130 -0
  28. package/infrastructure/domains/health/application/use-cases/execute-resource-import-use-case.js +221 -0
  29. package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.js +152 -0
  30. package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.test.js +343 -0
  31. package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.js +535 -0
  32. package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.test.js +376 -0
  33. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.js +213 -0
  34. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +441 -0
  35. package/infrastructure/domains/health/docs/ACME-DEV-DRIFT-ANALYSIS.md +267 -0
  36. package/infrastructure/domains/health/docs/BUILD-VS-DEPLOYED-TEMPLATE-ANALYSIS.md +324 -0
  37. package/infrastructure/domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md +386 -0
  38. package/infrastructure/domains/health/docs/SPEC-CLEANUP-COMMAND.md +1419 -0
  39. package/infrastructure/domains/health/docs/TDD-IMPLEMENTATION-SUMMARY.md +391 -0
  40. package/infrastructure/domains/health/docs/TEMPLATE-COMPARISON-IMPLEMENTATION.md +551 -0
  41. package/infrastructure/domains/health/domain/entities/issue.js +299 -0
  42. package/infrastructure/domains/health/domain/entities/issue.test.js +528 -0
  43. package/infrastructure/domains/health/domain/entities/property-mismatch.js +108 -0
  44. package/infrastructure/domains/health/domain/entities/property-mismatch.test.js +275 -0
  45. package/infrastructure/domains/health/domain/entities/resource.js +159 -0
  46. package/infrastructure/domains/health/domain/entities/resource.test.js +432 -0
  47. package/infrastructure/domains/health/domain/entities/stack-health-report.js +306 -0
  48. package/infrastructure/domains/health/domain/entities/stack-health-report.test.js +601 -0
  49. package/infrastructure/domains/health/domain/services/__tests__/health-score-percentage-based.test.js +380 -0
  50. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +971 -0
  51. package/infrastructure/domains/health/domain/services/__tests__/import-template-generator.test.js +1150 -0
  52. package/infrastructure/domains/health/domain/services/__tests__/logical-id-mapper.test.js +672 -0
  53. package/infrastructure/domains/health/domain/services/__tests__/template-parser.test.js +496 -0
  54. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +419 -0
  55. package/infrastructure/domains/health/domain/services/health-score-calculator.js +248 -0
  56. package/infrastructure/domains/health/domain/services/health-score-calculator.test.js +504 -0
  57. package/infrastructure/domains/health/domain/services/import-progress-monitor.js +195 -0
  58. package/infrastructure/domains/health/domain/services/import-template-generator.js +435 -0
  59. package/infrastructure/domains/health/domain/services/logical-id-mapper.js +345 -0
  60. package/infrastructure/domains/health/domain/services/mismatch-analyzer.js +234 -0
  61. package/infrastructure/domains/health/domain/services/mismatch-analyzer.test.js +431 -0
  62. package/infrastructure/domains/health/domain/services/property-mutability-config.js +382 -0
  63. package/infrastructure/domains/health/domain/services/template-parser.js +245 -0
  64. package/infrastructure/domains/health/domain/services/update-progress-monitor.js +192 -0
  65. package/infrastructure/domains/health/domain/value-objects/health-score.js +138 -0
  66. package/infrastructure/domains/health/domain/value-objects/health-score.test.js +267 -0
  67. package/infrastructure/domains/health/domain/value-objects/property-mutability.js +161 -0
  68. package/infrastructure/domains/health/domain/value-objects/property-mutability.test.js +198 -0
  69. package/infrastructure/domains/health/domain/value-objects/resource-state.js +167 -0
  70. package/infrastructure/domains/health/domain/value-objects/resource-state.test.js +196 -0
  71. package/infrastructure/domains/health/domain/value-objects/stack-identifier.js +192 -0
  72. package/infrastructure/domains/health/domain/value-objects/stack-identifier.test.js +262 -0
  73. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-cfn-tagged.test.js +312 -0
  74. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-multi-stack.test.js +367 -0
  75. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +432 -0
  76. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.js +784 -0
  77. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +1133 -0
  78. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.js +565 -0
  79. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +554 -0
  80. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.js +318 -0
  81. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.test.js +398 -0
  82. package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.js +777 -0
  83. package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.test.js +580 -0
  84. package/infrastructure/domains/integration/integration-builder.js +397 -0
  85. package/infrastructure/domains/integration/integration-builder.test.js +593 -0
  86. package/infrastructure/domains/integration/integration-resolver.js +170 -0
  87. package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
  88. package/infrastructure/domains/integration/websocket-builder.js +69 -0
  89. package/infrastructure/domains/integration/websocket-builder.test.js +195 -0
  90. package/infrastructure/domains/networking/vpc-builder.js +1829 -0
  91. package/infrastructure/domains/networking/vpc-builder.test.js +1262 -0
  92. package/infrastructure/domains/networking/vpc-discovery.js +177 -0
  93. package/infrastructure/domains/networking/vpc-discovery.test.js +350 -0
  94. package/infrastructure/domains/networking/vpc-resolver.js +324 -0
  95. package/infrastructure/domains/networking/vpc-resolver.test.js +501 -0
  96. package/infrastructure/domains/parameters/ssm-builder.js +79 -0
  97. package/infrastructure/domains/parameters/ssm-builder.test.js +189 -0
  98. package/infrastructure/domains/parameters/ssm-discovery.js +84 -0
  99. package/infrastructure/domains/parameters/ssm-discovery.test.js +210 -0
  100. package/infrastructure/{iam-generator.js → domains/security/iam-generator.js} +2 -2
  101. package/infrastructure/domains/security/kms-builder.js +366 -0
  102. package/infrastructure/domains/security/kms-builder.test.js +374 -0
  103. package/infrastructure/domains/security/kms-discovery.js +80 -0
  104. package/infrastructure/domains/security/kms-discovery.test.js +177 -0
  105. package/infrastructure/domains/security/kms-resolver.js +96 -0
  106. package/infrastructure/domains/security/kms-resolver.test.js +216 -0
  107. package/infrastructure/domains/shared/base-builder.js +112 -0
  108. package/infrastructure/domains/shared/base-resolver.js +186 -0
  109. package/infrastructure/domains/shared/base-resolver.test.js +305 -0
  110. package/infrastructure/domains/shared/builder-orchestrator.js +212 -0
  111. package/infrastructure/domains/shared/builder-orchestrator.test.js +213 -0
  112. package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
  113. package/infrastructure/domains/shared/cloudformation-discovery.js +375 -0
  114. package/infrastructure/domains/shared/cloudformation-discovery.test.js +590 -0
  115. package/infrastructure/domains/shared/environment-builder.js +119 -0
  116. package/infrastructure/domains/shared/environment-builder.test.js +247 -0
  117. package/infrastructure/domains/shared/providers/aws-provider-adapter.js +544 -0
  118. package/infrastructure/domains/shared/providers/aws-provider-adapter.test.js +377 -0
  119. package/infrastructure/domains/shared/providers/azure-provider-adapter.stub.js +93 -0
  120. package/infrastructure/domains/shared/providers/cloud-provider-adapter.js +136 -0
  121. package/infrastructure/domains/shared/providers/gcp-provider-adapter.stub.js +82 -0
  122. package/infrastructure/domains/shared/providers/provider-factory.js +108 -0
  123. package/infrastructure/domains/shared/providers/provider-factory.test.js +170 -0
  124. package/infrastructure/domains/shared/resource-discovery.js +192 -0
  125. package/infrastructure/domains/shared/resource-discovery.test.js +552 -0
  126. package/infrastructure/domains/shared/types/app-definition.js +205 -0
  127. package/infrastructure/domains/shared/types/discovery-result.js +106 -0
  128. package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
  129. package/infrastructure/domains/shared/types/index.js +46 -0
  130. package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
  131. package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
  132. package/infrastructure/domains/shared/utilities/base-definition-factory.js +380 -0
  133. package/infrastructure/domains/shared/utilities/base-definition-factory.js.bak +338 -0
  134. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +248 -0
  135. package/infrastructure/domains/shared/utilities/handler-path-resolver.js +134 -0
  136. package/infrastructure/domains/shared/utilities/handler-path-resolver.test.js +268 -0
  137. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +55 -0
  138. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +138 -0
  139. package/infrastructure/{env-validator.js → domains/shared/validation/env-validator.js} +2 -1
  140. package/infrastructure/domains/shared/validation/env-validator.test.js +173 -0
  141. package/infrastructure/esbuild.config.js +53 -0
  142. package/infrastructure/infrastructure-composer.js +87 -0
  143. package/infrastructure/{serverless-template.test.js → infrastructure-composer.test.js} +115 -24
  144. package/infrastructure/scripts/build-prisma-layer.js +553 -0
  145. package/infrastructure/scripts/build-prisma-layer.test.js +102 -0
  146. package/infrastructure/{build-time-discovery.js → scripts/build-time-discovery.js} +80 -48
  147. package/infrastructure/{build-time-discovery.test.js → scripts/build-time-discovery.test.js} +5 -4
  148. package/layers/prisma/nodejs/package.json +8 -0
  149. package/management-ui/server/utils/cliIntegration.js +1 -1
  150. package/management-ui/server/utils/environment/awsParameterStore.js +29 -18
  151. package/package.json +11 -11
  152. package/frigg-cli/.eslintrc.js +0 -141
  153. package/frigg-cli/__tests__/unit/commands/build.test.js +0 -251
  154. package/frigg-cli/__tests__/unit/commands/db-setup.test.js +0 -548
  155. package/frigg-cli/__tests__/unit/commands/install.test.js +0 -400
  156. package/frigg-cli/__tests__/unit/commands/ui.test.js +0 -346
  157. package/frigg-cli/__tests__/unit/utils/database-validator.test.js +0 -366
  158. package/frigg-cli/__tests__/unit/utils/error-messages.test.js +0 -304
  159. package/frigg-cli/__tests__/unit/utils/prisma-runner.test.js +0 -486
  160. package/frigg-cli/__tests__/utils/mock-factory.js +0 -270
  161. package/frigg-cli/__tests__/utils/prisma-mock.js +0 -194
  162. package/frigg-cli/__tests__/utils/test-fixtures.js +0 -463
  163. package/frigg-cli/__tests__/utils/test-setup.js +0 -287
  164. package/frigg-cli/build-command/index.js +0 -65
  165. package/frigg-cli/db-setup-command/index.js +0 -193
  166. package/frigg-cli/deploy-command/index.js +0 -175
  167. package/frigg-cli/generate-command/__tests__/generate-command.test.js +0 -301
  168. package/frigg-cli/generate-command/azure-generator.js +0 -43
  169. package/frigg-cli/generate-command/gcp-generator.js +0 -47
  170. package/frigg-cli/generate-command/index.js +0 -332
  171. package/frigg-cli/generate-command/terraform-generator.js +0 -555
  172. package/frigg-cli/generate-iam-command.js +0 -118
  173. package/frigg-cli/index.js +0 -75
  174. package/frigg-cli/index.test.js +0 -158
  175. package/frigg-cli/init-command/backend-first-handler.js +0 -756
  176. package/frigg-cli/init-command/index.js +0 -93
  177. package/frigg-cli/init-command/template-handler.js +0 -143
  178. package/frigg-cli/install-command/backend-js.js +0 -33
  179. package/frigg-cli/install-command/commit-changes.js +0 -16
  180. package/frigg-cli/install-command/environment-variables.js +0 -127
  181. package/frigg-cli/install-command/environment-variables.test.js +0 -136
  182. package/frigg-cli/install-command/index.js +0 -54
  183. package/frigg-cli/install-command/install-package.js +0 -13
  184. package/frigg-cli/install-command/integration-file.js +0 -30
  185. package/frigg-cli/install-command/logger.js +0 -12
  186. package/frigg-cli/install-command/template.js +0 -90
  187. package/frigg-cli/install-command/validate-package.js +0 -75
  188. package/frigg-cli/jest.config.js +0 -124
  189. package/frigg-cli/package.json +0 -54
  190. package/frigg-cli/start-command/index.js +0 -149
  191. package/frigg-cli/start-command/start-command.test.js +0 -297
  192. package/frigg-cli/test/init-command.test.js +0 -180
  193. package/frigg-cli/test/npm-registry.test.js +0 -319
  194. package/frigg-cli/ui-command/index.js +0 -154
  195. package/frigg-cli/utils/app-resolver.js +0 -319
  196. package/frigg-cli/utils/backend-path.js +0 -25
  197. package/frigg-cli/utils/database-validator.js +0 -161
  198. package/frigg-cli/utils/error-messages.js +0 -257
  199. package/frigg-cli/utils/npm-registry.js +0 -167
  200. package/frigg-cli/utils/prisma-runner.js +0 -280
  201. package/frigg-cli/utils/process-manager.js +0 -199
  202. package/frigg-cli/utils/repo-detection.js +0 -405
  203. package/infrastructure/aws-discovery.js +0 -1176
  204. package/infrastructure/aws-discovery.test.js +0 -1220
  205. package/infrastructure/serverless-template.js +0 -2094
  206. /package/infrastructure/{WEBSOCKET-CONFIGURATION.md → docs/WEBSOCKET-CONFIGURATION.md} +0 -0
  207. /package/infrastructure/{GENERATE-IAM-DOCS.md → docs/generate-iam-command.md} +0 -0
  208. /package/infrastructure/{iam-generator.test.js → domains/security/iam-generator.test.js} +0 -0
  209. /package/infrastructure/{frigg-deployment-iam-stack.yaml → domains/security/templates/frigg-deployment-iam-stack.yaml} +0 -0
  210. /package/infrastructure/{iam-policy-basic.json → domains/security/templates/iam-policy-basic.json} +0 -0
  211. /package/infrastructure/{iam-policy-full.json → domains/security/templates/iam-policy-full.json} +0 -0
  212. /package/infrastructure/{run-discovery.js → scripts/run-discovery.js} +0 -0
@@ -1,555 +0,0 @@
1
- async function generateTerraformTemplate(options) {
2
- const { appName, features, userPrefix } = options;
3
- const userName = `${userPrefix}-${appName}`.replace(/[^a-zA-Z0-9-]/g, '-');
4
-
5
- let template = `# Frigg Deployment IAM Configuration for ${appName}
6
- # Generated by Frigg CLI
7
-
8
- terraform {
9
- required_providers {
10
- aws = {
11
- source = "hashicorp/aws"
12
- version = "~> 5.0"
13
- }
14
- }
15
- }
16
-
17
- # Variables
18
- variable "enable_vpc" {
19
- description = "Enable VPC permissions"
20
- type = bool
21
- default = ${features.vpc}
22
- }
23
-
24
- variable "enable_kms" {
25
- description = "Enable KMS permissions"
26
- type = bool
27
- default = ${features.kms}
28
- }
29
-
30
- variable "enable_ssm" {
31
- description = "Enable SSM Parameter Store permissions"
32
- type = bool
33
- default = ${features.ssm}
34
- }
35
-
36
- variable "enable_websockets" {
37
- description = "Enable WebSocket permissions"
38
- type = bool
39
- default = ${features.websockets}
40
- }
41
-
42
- # IAM User
43
- resource "aws_iam_user" "frigg_deployment" {
44
- name = "${userName}"
45
- path = "/deployment/"
46
-
47
- tags = {
48
- Application = "${appName}"
49
- ManagedBy = "Frigg"
50
- Purpose = "Deployment"
51
- }
52
- }
53
-
54
- # Access Key
55
- resource "aws_iam_access_key" "frigg_deployment" {
56
- user = aws_iam_user.frigg_deployment.name
57
- }
58
-
59
- # Core Discovery Policy
60
- resource "aws_iam_policy" "frigg_discovery" {
61
- name = "${userName}-discovery-policy"
62
- description = "Allows discovery of AWS resources for Frigg deployment"
63
-
64
- policy = jsonencode({
65
- Version = "2012-10-17"
66
- Statement = [
67
- {
68
- Effect = "Allow"
69
- Action = [
70
- "cloudformation:ListStacks",
71
- "cloudformation:DescribeStacks",
72
- "lambda:ListFunctions",
73
- "lambda:GetFunction",
74
- "apigateway:GET",
75
- "s3:ListAllMyBuckets",
76
- "s3:GetBucketLocation",
77
- "s3:GetBucketVersioning",
78
- "dynamodb:ListTables",
79
- "dynamodb:DescribeTable",
80
- "sqs:ListQueues",
81
- "sqs:GetQueueAttributes",
82
- "events:ListRules",
83
- "events:DescribeRule",
84
- "iam:GetRole",
85
- "iam:GetPolicy",
86
- "iam:GetPolicyVersion",
87
- "iam:ListAttachedRolePolicies",
88
- "tag:GetResources"
89
- ]
90
- Resource = "*"
91
- }
92
- ]
93
- })
94
- }
95
-
96
- # Core Deployment Policy
97
- resource "aws_iam_policy" "frigg_core_deployment" {
98
- name = "${userName}-core-deployment-policy"
99
- description = "Core permissions for Frigg deployment"
100
-
101
- policy = jsonencode({
102
- Version = "2012-10-17"
103
- Statement = [
104
- {
105
- Sid = "CloudFormationManagement"
106
- Effect = "Allow"
107
- Action = [
108
- "cloudformation:CreateStack",
109
- "cloudformation:UpdateStack",
110
- "cloudformation:DeleteStack",
111
- "cloudformation:DescribeStacks",
112
- "cloudformation:DescribeStackEvents",
113
- "cloudformation:DescribeStackResources",
114
- "cloudformation:DescribeStackResource",
115
- "cloudformation:ListStackResources",
116
- "cloudformation:GetTemplate",
117
- "cloudformation:ValidateTemplate",
118
- "cloudformation:CreateChangeSet",
119
- "cloudformation:DeleteChangeSet",
120
- "cloudformation:DescribeChangeSet",
121
- "cloudformation:ExecuteChangeSet",
122
- "cloudformation:TagResource",
123
- "cloudformation:UntagResource"
124
- ]
125
- Resource = [
126
- "arn:aws:cloudformation:*:*:stack/*frigg*/*",
127
- "arn:aws:cloudformation:*:*:stack/${appName}*/*"
128
- ]
129
- },
130
- {
131
- Sid = "S3Management"
132
- Effect = "Allow"
133
- Action = [
134
- "s3:CreateBucket",
135
- "s3:DeleteBucket",
136
- "s3:PutObject",
137
- "s3:GetObject",
138
- "s3:DeleteObject",
139
- "s3:PutBucketPolicy",
140
- "s3:GetBucketPolicy",
141
- "s3:DeleteBucketPolicy",
142
- "s3:PutBucketVersioning",
143
- "s3:GetBucketVersioning",
144
- "s3:PutBucketPublicAccessBlock",
145
- "s3:GetBucketPublicAccessBlock",
146
- "s3:PutBucketTagging",
147
- "s3:GetBucketTagging",
148
- "s3:DeleteBucketTagging",
149
- "s3:PutBucketEncryption",
150
- "s3:GetBucketEncryption",
151
- "s3:PutEncryptionConfiguration",
152
- "s3:PutBucketNotification",
153
- "s3:GetBucketNotification",
154
- "s3:GetBucketLocation",
155
- "s3:ListBucket",
156
- "s3:GetBucketAcl",
157
- "s3:PutBucketAcl"
158
- ]
159
- Resource = [
160
- "arn:aws:s3:::*frigg*",
161
- "arn:aws:s3:::*frigg*/*",
162
- "arn:aws:s3:::${appName}*",
163
- "arn:aws:s3:::${appName}*/*"
164
- ]
165
- },
166
- {
167
- Sid = "LambdaManagement"
168
- Effect = "Allow"
169
- Action = [
170
- "lambda:CreateFunction",
171
- "lambda:UpdateFunctionCode",
172
- "lambda:UpdateFunctionConfiguration",
173
- "lambda:DeleteFunction",
174
- "lambda:GetFunction",
175
- "lambda:GetFunctionConfiguration",
176
- "lambda:AddPermission",
177
- "lambda:RemovePermission",
178
- "lambda:InvokeFunction",
179
- "lambda:TagResource",
180
- "lambda:UntagResource",
181
- "lambda:ListTags",
182
- "lambda:PutFunctionConcurrency",
183
- "lambda:DeleteFunctionConcurrency"
184
- ]
185
- Resource = [
186
- "arn:aws:lambda:*:*:function:*frigg*",
187
- "arn:aws:lambda:*:*:function:${appName}*"
188
- ]
189
- },
190
- {
191
- Sid = "IAMRoleManagement"
192
- Effect = "Allow"
193
- Action = [
194
- "iam:CreateRole",
195
- "iam:DeleteRole",
196
- "iam:AttachRolePolicy",
197
- "iam:DetachRolePolicy",
198
- "iam:PutRolePolicy",
199
- "iam:DeleteRolePolicy",
200
- "iam:GetRole",
201
- "iam:GetRolePolicy",
202
- "iam:UpdateRole",
203
- "iam:PassRole",
204
- "iam:TagRole",
205
- "iam:UntagRole"
206
- ]
207
- Resource = [
208
- "arn:aws:iam::*:role/*frigg*",
209
- "arn:aws:iam::*:role/${appName}*"
210
- ]
211
- },
212
- {
213
- Sid = "APIGatewayManagement"
214
- Effect = "Allow"
215
- Action = [
216
- "apigateway:*"
217
- ]
218
- Resource = [
219
- "arn:aws:apigateway:*::/restapis",
220
- "arn:aws:apigateway:*::/restapis/*",
221
- "arn:aws:apigateway:*::/apis",
222
- "arn:aws:apigateway:*::/apis/*",
223
- "arn:aws:apigateway:*::/tags/*"
224
- ]
225
- },
226
- {
227
- Sid = "DynamoDBManagement"
228
- Effect = "Allow"
229
- Action = [
230
- "dynamodb:CreateTable",
231
- "dynamodb:UpdateTable",
232
- "dynamodb:DeleteTable",
233
- "dynamodb:DescribeTable",
234
- "dynamodb:TagResource",
235
- "dynamodb:UntagResource",
236
- "dynamodb:ListTagsOfResource",
237
- "dynamodb:UpdateTimeToLive",
238
- "dynamodb:DescribeTimeToLive",
239
- "dynamodb:CreateBackup",
240
- "dynamodb:DeleteBackup",
241
- "dynamodb:DescribeBackup",
242
- "dynamodb:ListBackups"
243
- ]
244
- Resource = [
245
- "arn:aws:dynamodb:*:*:table/*frigg*",
246
- "arn:aws:dynamodb:*:*:table/${appName}*"
247
- ]
248
- },
249
- {
250
- Sid = "EventBridgeManagement"
251
- Effect = "Allow"
252
- Action = [
253
- "events:PutRule",
254
- "events:DeleteRule",
255
- "events:DescribeRule",
256
- "events:EnableRule",
257
- "events:DisableRule",
258
- "events:PutTargets",
259
- "events:RemoveTargets",
260
- "events:ListTargetsByRule",
261
- "events:TagResource",
262
- "events:UntagResource"
263
- ]
264
- Resource = [
265
- "arn:aws:events:*:*:rule/*frigg*",
266
- "arn:aws:events:*:*:rule/${appName}*"
267
- ]
268
- },
269
- {
270
- Sid = "SQSManagement"
271
- Effect = "Allow"
272
- Action = [
273
- "sqs:CreateQueue",
274
- "sqs:DeleteQueue",
275
- "sqs:SetQueueAttributes",
276
- "sqs:GetQueueAttributes",
277
- "sqs:TagQueue",
278
- "sqs:UntagQueue",
279
- "sqs:ListQueueTags",
280
- "sqs:AddPermission",
281
- "sqs:RemovePermission"
282
- ]
283
- Resource = [
284
- "arn:aws:sqs:*:*:*frigg*",
285
- "arn:aws:sqs:*:*:${appName}*"
286
- ]
287
- },
288
- {
289
- Sid = "LogsManagement"
290
- Effect = "Allow"
291
- Action = [
292
- "logs:CreateLogGroup",
293
- "logs:DeleteLogGroup",
294
- "logs:PutRetentionPolicy",
295
- "logs:DeleteRetentionPolicy",
296
- "logs:TagLogGroup",
297
- "logs:UntagLogGroup"
298
- ]
299
- Resource = [
300
- "arn:aws:logs:*:*:log-group:/aws/lambda/*frigg*",
301
- "arn:aws:logs:*:*:log-group:/aws/lambda/${appName}*",
302
- "arn:aws:logs:*:*:log-group:/aws/apigateway/*frigg*",
303
- "arn:aws:logs:*:*:log-group:/aws/apigateway/${appName}*"
304
- ]
305
- }
306
- ]
307
- })
308
- }
309
- `;
310
-
311
- // Add VPC policy if enabled
312
- if (features.vpc) {
313
- template += `
314
- # VPC Management Policy
315
- resource "aws_iam_policy" "frigg_vpc" {
316
- name = "${userName}-vpc-policy"
317
- description = "VPC management permissions for Frigg"
318
-
319
- policy = jsonencode({
320
- Version = "2012-10-17"
321
- Statement = [
322
- {
323
- Sid = "VPCDiscovery"
324
- Effect = "Allow"
325
- Action = [
326
- "ec2:DescribeVpcs",
327
- "ec2:DescribeSubnets",
328
- "ec2:DescribeSecurityGroups",
329
- "ec2:DescribeRouteTables",
330
- "ec2:DescribeNatGateways",
331
- "ec2:DescribeInternetGateways",
332
- "ec2:DescribeVpcEndpoints",
333
- "ec2:DescribeNetworkInterfaces",
334
- "ec2:DescribeAddresses"
335
- ]
336
- Resource = "*"
337
- },
338
- {
339
- Sid = "VPCManagement"
340
- Effect = "Allow"
341
- Action = [
342
- "ec2:CreateVpc",
343
- "ec2:DeleteVpc",
344
- "ec2:ModifyVpcAttribute",
345
- "ec2:CreateSubnet",
346
- "ec2:DeleteSubnet",
347
- "ec2:CreateSecurityGroup",
348
- "ec2:DeleteSecurityGroup",
349
- "ec2:AuthorizeSecurityGroupIngress",
350
- "ec2:AuthorizeSecurityGroupEgress",
351
- "ec2:RevokeSecurityGroupIngress",
352
- "ec2:RevokeSecurityGroupEgress",
353
- "ec2:CreateRouteTable",
354
- "ec2:DeleteRouteTable",
355
- "ec2:CreateRoute",
356
- "ec2:DeleteRoute",
357
- "ec2:AssociateRouteTable",
358
- "ec2:DisassociateRouteTable",
359
- "ec2:CreateInternetGateway",
360
- "ec2:DeleteInternetGateway",
361
- "ec2:AttachInternetGateway",
362
- "ec2:DetachInternetGateway",
363
- "ec2:CreateNatGateway",
364
- "ec2:DeleteNatGateway",
365
- "ec2:AllocateAddress",
366
- "ec2:ReleaseAddress",
367
- "ec2:CreateVpcEndpoint",
368
- "ec2:DeleteVpcEndpoints",
369
- "ec2:CreateTags",
370
- "ec2:DeleteTags"
371
- ]
372
- Resource = "*"
373
- Condition = {
374
- StringLike = {
375
- "aws:RequestTag/Name" = ["*frigg*", "*${appName}*"]
376
- }
377
- }
378
- }
379
- ]
380
- })
381
- }
382
- `;
383
- }
384
-
385
- // Add KMS policy if enabled
386
- if (features.kms) {
387
- template += `
388
- # KMS Management Policy
389
- resource "aws_iam_policy" "frigg_kms" {
390
- name = "${userName}-kms-policy"
391
- description = "KMS management permissions for Frigg"
392
-
393
- policy = jsonencode({
394
- Version = "2012-10-17"
395
- Statement = [
396
- {
397
- Sid = "KMSKeyManagement"
398
- Effect = "Allow"
399
- Action = [
400
- "kms:CreateKey",
401
- "kms:DescribeKey",
402
- "kms:ListKeys",
403
- "kms:ListAliases",
404
- "kms:CreateAlias",
405
- "kms:UpdateAlias",
406
- "kms:DeleteAlias",
407
- "kms:EnableKey",
408
- "kms:DisableKey",
409
- "kms:ScheduleKeyDeletion",
410
- "kms:CancelKeyDeletion",
411
- "kms:GetKeyPolicy",
412
- "kms:PutKeyPolicy",
413
- "kms:TagResource",
414
- "kms:UntagResource",
415
- "kms:ListResourceTags",
416
- "kms:Encrypt",
417
- "kms:Decrypt",
418
- "kms:GenerateDataKey"
419
- ]
420
- Resource = "*"
421
- }
422
- ]
423
- })
424
- }
425
- `;
426
- }
427
-
428
- // Add SSM policy if enabled
429
- if (features.ssm) {
430
- template += `
431
- # SSM Parameter Store Policy
432
- resource "aws_iam_policy" "frigg_ssm" {
433
- name = "${userName}-ssm-policy"
434
- description = "SSM Parameter Store permissions for Frigg"
435
-
436
- policy = jsonencode({
437
- Version = "2012-10-17"
438
- Statement = [
439
- {
440
- Sid = "SSMParameterManagement"
441
- Effect = "Allow"
442
- Action = [
443
- "ssm:PutParameter",
444
- "ssm:GetParameter",
445
- "ssm:GetParameters",
446
- "ssm:GetParametersByPath",
447
- "ssm:DeleteParameter",
448
- "ssm:DeleteParameters",
449
- "ssm:DescribeParameters",
450
- "ssm:AddTagsToResource",
451
- "ssm:RemoveTagsFromResource",
452
- "ssm:ListTagsForResource"
453
- ]
454
- Resource = [
455
- "arn:aws:ssm:*:*:parameter/*frigg*",
456
- "arn:aws:ssm:*:*:parameter/${appName}*"
457
- ]
458
- },
459
- {
460
- Sid = "SSMParameterDiscovery"
461
- Effect = "Allow"
462
- Action = [
463
- "ssm:DescribeParameters"
464
- ]
465
- Resource = "*"
466
- }
467
- ]
468
- })
469
- }
470
- `;
471
- }
472
-
473
- // Attach policies to user
474
- template += `
475
- # Attach policies to user
476
- resource "aws_iam_user_policy_attachment" "frigg_discovery" {
477
- user = aws_iam_user.frigg_deployment.name
478
- policy_arn = aws_iam_policy.frigg_discovery.arn
479
- }
480
-
481
- resource "aws_iam_user_policy_attachment" "frigg_core_deployment" {
482
- user = aws_iam_user.frigg_deployment.name
483
- policy_arn = aws_iam_policy.frigg_core_deployment.arn
484
- }
485
- `;
486
-
487
- if (features.vpc) {
488
- template += `
489
- resource "aws_iam_user_policy_attachment" "frigg_vpc" {
490
- count = var.enable_vpc ? 1 : 0
491
- user = aws_iam_user.frigg_deployment.name
492
- policy_arn = aws_iam_policy.frigg_vpc.arn
493
- }
494
- `;
495
- }
496
-
497
- if (features.kms) {
498
- template += `
499
- resource "aws_iam_user_policy_attachment" "frigg_kms" {
500
- count = var.enable_kms ? 1 : 0
501
- user = aws_iam_user.frigg_deployment.name
502
- policy_arn = aws_iam_policy.frigg_kms.arn
503
- }
504
- `;
505
- }
506
-
507
- if (features.ssm) {
508
- template += `
509
- resource "aws_iam_user_policy_attachment" "frigg_ssm" {
510
- count = var.enable_ssm ? 1 : 0
511
- user = aws_iam_user.frigg_deployment.name
512
- policy_arn = aws_iam_policy.frigg_ssm.arn
513
- }
514
- `;
515
- }
516
-
517
- // Add outputs
518
- template += `
519
- # Outputs
520
- output "user_arn" {
521
- description = "ARN of the created IAM user"
522
- value = aws_iam_user.frigg_deployment.arn
523
- }
524
-
525
- output "user_name" {
526
- description = "Name of the created IAM user"
527
- value = aws_iam_user.frigg_deployment.name
528
- }
529
-
530
- output "access_key_id" {
531
- description = "Access key ID for the IAM user"
532
- value = aws_iam_access_key.frigg_deployment.id
533
- }
534
-
535
- output "secret_access_key" {
536
- description = "Secret access key for the IAM user"
537
- value = aws_iam_access_key.frigg_deployment.secret
538
- sensitive = true
539
- }
540
-
541
- output "enabled_features" {
542
- description = "Features enabled for this deployment user"
543
- value = {
544
- vpc = var.enable_vpc
545
- kms = var.enable_kms
546
- ssm = var.enable_ssm
547
- websockets = var.enable_websockets
548
- }
549
- }
550
- `;
551
-
552
- return template;
553
- }
554
-
555
- module.exports = { generateTerraformTemplate };
@@ -1,118 +0,0 @@
1
- const fs = require('fs-extra');
2
- const path = require('path');
3
- const { findNearestBackendPackageJson } = require('@friggframework/core');
4
- const { generateIAMCloudFormation, getFeatureSummary } = require('../infrastructure/iam-generator');
5
-
6
- /**
7
- * Generate IAM CloudFormation stack based on current app definition
8
- * @param {Object} options - Command options
9
- */
10
- async function generateIamCommand(options = {}) {
11
- try {
12
- console.log('🔍 Finding Frigg application...');
13
-
14
- // Find the backend package.json
15
- const backendPath = findNearestBackendPackageJson();
16
- if (!backendPath) {
17
- console.error('❌ Could not find backend package.json');
18
- console.error(' Make sure you are in a Frigg application directory');
19
- process.exit(1);
20
- }
21
-
22
- const backendDir = path.dirname(backendPath);
23
- const backendFilePath = path.join(backendDir, 'index.js');
24
-
25
- if (!fs.existsSync(backendFilePath)) {
26
- console.error('❌ Could not find backend/index.js');
27
- console.error(' Make sure your Frigg application has a backend/index.js file');
28
- process.exit(1);
29
- }
30
-
31
- console.log(`📱 Found Frigg application at: ${backendDir}`);
32
-
33
- // Load the app definition
34
- const backend = require(backendFilePath);
35
- const appDefinition = backend.Definition;
36
-
37
- if (!appDefinition) {
38
- console.error('❌ No Definition found in backend/index.js');
39
- console.error(' Make sure your backend exports a Definition object');
40
- process.exit(1);
41
- }
42
-
43
- // Get feature summary
44
- const summary = getFeatureSummary(appDefinition);
45
-
46
- console.log('\\n📋 Application Analysis:');
47
- console.log(` App Name: ${summary.appName}`);
48
- console.log(` Integrations: ${summary.integrationCount}`);
49
- console.log('\\n🔧 Features Detected:');
50
- console.log(` ✅ Core deployment (always included)`);
51
- console.log(` ${summary.features.vpc ? '✅' : '❌'} VPC support`);
52
- console.log(` ${summary.features.kms ? '✅' : '❌'} KMS encryption`);
53
- console.log(` ${summary.features.ssm ? '✅' : '❌'} SSM Parameter Store`);
54
- console.log(` ${summary.features.websockets ? '✅' : '❌'} WebSocket support`);
55
-
56
- // Generate the CloudFormation template
57
- console.log('\\n🏗️ Generating IAM CloudFormation template...');
58
-
59
- const deploymentUserName = options.user || 'frigg-deployment-user';
60
- const stackName = options.stackName || 'frigg-deployment-iam';
61
-
62
- // Use the summary already extracted above (line 44)
63
- const cloudFormationYaml = generateIAMCloudFormation({
64
- appName: summary.appName,
65
- features: summary.features,
66
- userPrefix: deploymentUserName,
67
- stackName
68
- });
69
-
70
- // Determine output file path
71
- const outputDir = options.output || path.join(backendDir, 'infrastructure');
72
- await fs.ensureDir(outputDir);
73
-
74
- const outputFile = path.join(outputDir, `${stackName}.yaml`);
75
-
76
- // Write the file
77
- await fs.writeFile(outputFile, cloudFormationYaml);
78
-
79
- console.log(`\\n✅ IAM CloudFormation template generated successfully!`);
80
- console.log(`📄 File: ${outputFile}`);
81
-
82
- // Show deployment instructions
83
- console.log('\\n📚 Next Steps:');
84
- console.log('\\n1. Deploy the CloudFormation stack:');
85
- console.log(` aws cloudformation deploy \\\\`);
86
- console.log(` --template-file ${path.relative(process.cwd(), outputFile)} \\\\`);
87
- console.log(` --stack-name ${stackName} \\\\`);
88
- console.log(` --capabilities CAPABILITY_NAMED_IAM \\\\`);
89
- console.log(` --parameter-overrides DeploymentUserName=${deploymentUserName}`);
90
-
91
- console.log('\\n2. Retrieve credentials:');
92
- console.log(` aws cloudformation describe-stacks \\\\`);
93
- console.log(` --stack-name ${stackName} \\\\`);
94
- console.log(` --query 'Stacks[0].Outputs[?OutputKey==\`AccessKeyId\`].OutputValue' \\\\`);
95
- console.log(` --output text`);
96
-
97
- console.log('\\n3. Get secret access key:');
98
- console.log(` aws secretsmanager get-secret-value \\\\`);
99
- console.log(` --secret-id frigg-deployment-credentials \\\\`);
100
- console.log(` --query SecretString \\\\`);
101
- console.log(` --output text | jq -r .SecretAccessKey`);
102
-
103
- if (options.verbose) {
104
- console.log('\\n🔍 Generated Template Summary:');
105
- console.log(` File size: ${Math.round(cloudFormationYaml.length / 1024)}KB`);
106
- console.log(` Features enabled: ${Object.values(summary.features).filter(Boolean).length}`);
107
- }
108
-
109
- } catch (error) {
110
- console.error('❌ Error generating IAM template:', error.message);
111
- if (options.verbose) {
112
- console.error('Stack trace:', error.stack);
113
- }
114
- process.exit(1);
115
- }
116
- }
117
-
118
- module.exports = { generateIamCommand };