@terraforge/core 0.0.1

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 (2) hide show
  1. package/README.md +116 -0
  2. package/package.json +38 -0
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+
2
+ # Infrastructure as code made fast & easy
3
+
4
+ The core of Terraforge lives in `@terraforge/core`, with the Terraform bridge in `@terraforge/terraform`. Together they provide a fast, diff-friendly IaC workflow for AWS (and custom) stacks.
5
+
6
+ ## The problem
7
+
8
+ The most used IaC solutions are slow & don't effectively leverage diffing to speed up their deployments.
9
+
10
+ ## Todo's
11
+ - When a resource is being deleted inside a deployment we need to make sure that resources that depends on our deleted resource will be updated first.
12
+
13
+ ## Setup
14
+
15
+ Install with (NPM):
16
+
17
+ ```
18
+ npm i @terraforge/core @terraforge/terraform
19
+ ```
20
+
21
+ ## Example
22
+
23
+ First, you need to create a workspace instance and pass in the cloud providers that you will use.
24
+ We also need to give it a lock provider & state provider.
25
+
26
+ - A cloud provider is used to create resources on a specific cloud provider. We have built-in cloud providers for AWS resources, but you could simply add your own as well.
27
+
28
+ - The state provider is used for storing the latest deployment state.
29
+
30
+ - The lock provider is used for acquiring a lock when you deploy your app. This will guarantee that multiple people can never deploy the same application at the same time.
31
+
32
+ In this example, we will use a local file lock & state provider.
33
+
34
+ ```ts
35
+ import { App, FileStateBackend, FileLockBackend, Stack, WorkSpace } from '@terraforge/core'
36
+ import { Terraform, $ } from '@terraforge/terraform'
37
+
38
+ const terraform = new Terraform({
39
+ providerLocation: './providers'
40
+ })
41
+
42
+ const aws = await terraform.install('hashicorp', 'aws', '5.93.0')
43
+
44
+ const workspace = new WorkSpace({
45
+ providers: [
46
+ aws({
47
+ profile: "PROFILE",
48
+ region: "REGION"
49
+ })
50
+ ],
51
+ backend: {
52
+ state: new FileStateBackend({ dir: './states' }),
53
+ lock: new FileLockBackend({ dir: './locks' }),
54
+ }
55
+ })
56
+ ```
57
+
58
+ With your workspace configuration ready we can now move on to defining your infrastructure.
59
+ This example illustrates how simple it is to define multi-stack resources without worrying about cross-stack references.
60
+
61
+ ```ts
62
+ const app = new App('todo-app')
63
+ const storage = new Stack(app, 'storage')
64
+ const list = new $.aws.s3.Bucket(storage, 'list', {})
65
+
66
+ const items = new Stack(app, 'items')
67
+ const todo = new $.aws.s3.BucketObject(items, 'item', {
68
+ bucket: list.bucket,
69
+ key: 'item-1',
70
+ content: JSON.stringify({
71
+ title: 'Write docs...',
72
+ done: true,
73
+ }),
74
+ })
75
+ ```
76
+
77
+ After defining your infrastructure, we can deploy our app.
78
+ ```ts
79
+ await workspace.deploy(app)
80
+ ```
81
+
82
+ Or destroy our app.
83
+ ```ts
84
+ await workspace.delete(app)
85
+ ```
86
+
87
+ Maybe you want to only deploy a subset of stacks.
88
+ ```ts
89
+ await workspace.deploy(app, {
90
+ filters: ["storage"]
91
+ })
92
+ ```
93
+
94
+ ## Production
95
+
96
+ For production, we recommend you use a state & lock backend that stores your data in the cloud.
97
+ An AWS DynamoDB table is perfect for storing locks.
98
+ While AWS S3 is perfect for storing your state files.
99
+
100
+ ```ts
101
+ const workspace = new WorkSpace({
102
+ providers: [...],
103
+ backend: {
104
+ lock: new DynamoLockBackend({
105
+ region,
106
+ credentials,
107
+ tableName: 'awsless-locks',
108
+ }),
109
+ state: new S3StateBackend({
110
+ region,
111
+ credentials,
112
+ bucket: 'awsless-state-UNIQUE_ID',
113
+ }),
114
+ }
115
+ })
116
+ ```
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@terraforge/core",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "module": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build": "bunup src/index.ts --format esm --dts --clean --target node --packages external --out-dir ./dist",
15
+ "prepublish": "bun run build",
16
+ "test": "bun test"
17
+ },
18
+ "dependencies": {
19
+ "@aws-sdk/client-dynamodb": "3.363.0",
20
+ "@aws-sdk/client-s3": "^3.779.0",
21
+ "@aws-sdk/types": "3.329.0",
22
+ "@aws-sdk/util-dynamodb": "^3.777.0",
23
+ "async-on-exit": "^0.1.0",
24
+ "get-wild": "^3.0.2",
25
+ "graphology": "^0.26.0",
26
+ "graphology-dag": "^0.4.1",
27
+ "p-limit": "^6.2.0",
28
+ "proper-lockfile": "^4.1.2",
29
+ "uuid": "^11.1.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/proper-lockfile": "^4.1.4"
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "license": "MIT"
38
+ }