create-nx-terraform-app 0.7.2 → 0.9.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/package.json +1 -1
- package/README.md +0 -263
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
# create-nx-terraform-app
|
|
2
|
-
|
|
3
|
-
A CLI tool for creating new Nx workspaces pre-configured with Terraform support. This package provides an interactive setup experience that creates a fully functional Nx workspace with the `nx-terraform` plugin and an initial Terraform backend project.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
`create-nx-terraform-app` is an executable npm package that scaffolds a new Nx workspace with Terraform infrastructure-as-code capabilities. It guides users through an interactive setup process to configure their workspace with appropriate Terraform backend type and project settings.
|
|
8
|
-
|
|
9
|
-
## Installation & Usage
|
|
10
|
-
|
|
11
|
-
### Creating a New Workspace
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
# Create a new Terraform workspace
|
|
15
|
-
npx create-nx-terraform-app my-terraform-workspace
|
|
16
|
-
|
|
17
|
-
# With options (non-interactive)
|
|
18
|
-
npx create-nx-terraform-app my-workspace --backendType=aws-s3 --packageManager=npm
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Interactive Prompts
|
|
22
|
-
|
|
23
|
-
When run without all options, the CLI will prompt for:
|
|
24
|
-
|
|
25
|
-
1. **Project name**: Name of your workspace/project
|
|
26
|
-
2. **Terraform backend type**: Choose between:
|
|
27
|
-
- `aws-s3`: AWS S3 remote backend (production-ready, supports state locking)
|
|
28
|
-
- `local`: Local backend (development, state files stored locally)
|
|
29
|
-
3. **Package manager**: npm, yarn, or pnpm
|
|
30
|
-
4. **Nx Cloud**: Option to connect to Nx Cloud for distributed caching
|
|
31
|
-
5. **Git options**: Initialize git repository, set default branch
|
|
32
|
-
|
|
33
|
-
## Options
|
|
34
|
-
|
|
35
|
-
| Option | Type | Description | Default |
|
|
36
|
-
|--------|------|-------------|---------|
|
|
37
|
-
| `[name]` or `projectName` | string | Workspace/project name | - |
|
|
38
|
-
| `--backendType` | 'aws-s3' \| 'local' | Terraform backend type | Prompted |
|
|
39
|
-
| `--packageManager` | 'npm' \| 'yarn' \| 'pnpm' | Package manager to use | Prompted |
|
|
40
|
-
| `--nxCloud` | boolean | Connect to Nx Cloud | Prompted |
|
|
41
|
-
| `--git` | boolean | Initialize git repository | true |
|
|
42
|
-
| `--defaultBase` | string | Default git branch | 'main' |
|
|
43
|
-
|
|
44
|
-
## What It Creates
|
|
45
|
-
|
|
46
|
-
After running `create-nx-terraform-app`, you get a complete Nx workspace:
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
my-terraform-workspace/
|
|
50
|
-
├── nx.json # Nx configuration with nx-terraform plugin
|
|
51
|
-
├── package.json # Workspace dependencies
|
|
52
|
-
├── .gitignore # Git ignore patterns
|
|
53
|
-
└── packages/
|
|
54
|
-
├── terraform-setup/ # Initial Terraform backend project
|
|
55
|
-
│ ├── project.json
|
|
56
|
-
│ ├── main.tf
|
|
57
|
-
│ ├── backend.tf
|
|
58
|
-
│ ├── provider.tf
|
|
59
|
-
│ ├── variables.tf
|
|
60
|
-
│ └── backend.config # Generated after first apply
|
|
61
|
-
└── terraform-infra/ # Initial Terraform stateful module
|
|
62
|
-
├── project.json # Contains metadata['nx-terraform'].backendProject: 'terraform-setup'
|
|
63
|
-
├── main.tf
|
|
64
|
-
├── backend.tf # References terraform-setup backend
|
|
65
|
-
├── provider.tf
|
|
66
|
-
├── variables.tf
|
|
67
|
-
└── outputs.tf
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Workspace Configuration
|
|
71
|
-
|
|
72
|
-
- **Nx Plugin**: `nx-terraform` automatically registered in `nx.json`
|
|
73
|
-
- **Backend Project**: Initial Terraform backend project at `packages/terraform-setup/`
|
|
74
|
-
- **Stateful Module**: Initial Terraform infrastructure module at `packages/terraform-infra/` (connected to backend)
|
|
75
|
-
- **Backend Type**: Configured based on your selection (AWS S3 or local), used for both projects
|
|
76
|
-
- **Package Manager**: Dependencies installed with your chosen manager
|
|
77
|
-
|
|
78
|
-
## Implementation Details
|
|
79
|
-
|
|
80
|
-
### Architecture
|
|
81
|
-
|
|
82
|
-
The CLI tool is built using:
|
|
83
|
-
- **`create-nx-workspace`**: Core workspace creation functionality from Nx
|
|
84
|
-
- **`yargs`**: Command-line argument parsing
|
|
85
|
-
- **`enquirer`**: Interactive prompts
|
|
86
|
-
- **`picocolors`**: Terminal output formatting
|
|
87
|
-
|
|
88
|
-
### Workflow
|
|
89
|
-
|
|
90
|
-
1. **Argument Parsing**: Uses yargs to parse CLI arguments
|
|
91
|
-
2. **Interactive Prompts**: Prompts for missing required options
|
|
92
|
-
3. **Workspace Creation**: Calls `createWorkspace` with preset `nx-terraform@<version>`
|
|
93
|
-
4. **Preset Execution**: The preset generator runs:
|
|
94
|
-
- Registers `nx-terraform` plugin (via `init` generator)
|
|
95
|
-
- Creates backend project `terraform-setup` (via `terraform-backend` generator)
|
|
96
|
-
- Creates stateful module `terraform-infra` (via `terraform-module` generator)
|
|
97
|
-
|
|
98
|
-
### Code Structure
|
|
99
|
-
|
|
100
|
-
**Main Entry Point:**
|
|
101
|
-
- `bin/index.ts`: Executable script (`#!/usr/bin/env node`)
|
|
102
|
-
- `package.json`: Defines binary as `create-nx-terraform-app`
|
|
103
|
-
|
|
104
|
-
**Key Functions:**
|
|
105
|
-
- `determineProjectName()`: Prompts for or validates project name
|
|
106
|
-
- `determineBackendType()`: Prompts for backend type selection
|
|
107
|
-
- `normalizeArgsMiddleware()`: Prepares arguments for workspace creation
|
|
108
|
-
- `main()`: Orchestrates workspace creation process
|
|
109
|
-
|
|
110
|
-
**Preset Integration:**
|
|
111
|
-
- Calls `createWorkspace` with preset: `nx-terraform@<version>`
|
|
112
|
-
- Preset is resolved to `packages/nx-terraform/src/generators/preset/generator`
|
|
113
|
-
- Preset generator handles plugin registration and backend project creation
|
|
114
|
-
|
|
115
|
-
### Normalization
|
|
116
|
-
|
|
117
|
-
The CLI normalizes arguments:
|
|
118
|
-
- Handles project names with slashes (extracts folder name)
|
|
119
|
-
- Merges prompted values with provided arguments
|
|
120
|
-
- Ensures all required options are present before workspace creation
|
|
121
|
-
|
|
122
|
-
## Examples
|
|
123
|
-
|
|
124
|
-
### Quick Start (Interactive)
|
|
125
|
-
|
|
126
|
-
```bash
|
|
127
|
-
npx create-nx-terraform-app my-infrastructure
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
You'll be guided through:
|
|
131
|
-
- Project name confirmation
|
|
132
|
-
- Backend type selection (AWS S3 or local)
|
|
133
|
-
- Package manager choice
|
|
134
|
-
- Nx Cloud setup (optional)
|
|
135
|
-
- Git initialization
|
|
136
|
-
|
|
137
|
-
### Non-Interactive (CI/CD)
|
|
138
|
-
|
|
139
|
-
```bash
|
|
140
|
-
npx create-nx-terraform-app my-workspace \
|
|
141
|
-
--backendType=aws-s3 \
|
|
142
|
-
--packageManager=npm \
|
|
143
|
-
--nxCloud=false \
|
|
144
|
-
--git=true
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### AWS S3 Backend Setup
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
npx create-nx-terraform-app production-infra --backendType=aws-s3
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Creates workspace with production-ready S3 backend for remote state management.
|
|
154
|
-
|
|
155
|
-
### Local Backend for Development
|
|
156
|
-
|
|
157
|
-
```bash
|
|
158
|
-
npx create-nx-terraform-app dev-workspace --backendType=local
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Creates workspace with local state storage (good for development/testing).
|
|
162
|
-
|
|
163
|
-
## Next Steps After Creation
|
|
164
|
-
|
|
165
|
-
Once your workspace is created:
|
|
166
|
-
|
|
167
|
-
1. **Apply Backend** (if using remote backend):
|
|
168
|
-
```bash
|
|
169
|
-
cd my-terraform-workspace
|
|
170
|
-
nx run terraform-setup:terraform-apply
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
2. **Initialize and Deploy Infrastructure Module** (already created):
|
|
174
|
-
```bash
|
|
175
|
-
nx run terraform-infra:terraform-init
|
|
176
|
-
nx run terraform-infra:terraform-plan --configuration=dev
|
|
177
|
-
nx run terraform-infra:terraform-apply --configuration=dev
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
3. **Create Additional Modules** (optional):
|
|
181
|
-
```bash
|
|
182
|
-
# Simple module (library)
|
|
183
|
-
nx g nx-terraform:terraform-module my-module
|
|
184
|
-
|
|
185
|
-
# Stateful module (application)
|
|
186
|
-
nx g nx-terraform:terraform-module my-infra \
|
|
187
|
-
--backendProject=terraform-setup
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
4. **Start Developing**:
|
|
191
|
-
- Edit Terraform files in `packages/terraform-setup/` or `packages/terraform-infra/`
|
|
192
|
-
- Run `nx graph` to see project relationships
|
|
193
|
-
- Use `nx run <project>:terraform-plan` to preview changes
|
|
194
|
-
|
|
195
|
-
## Integration with Preset Generator
|
|
196
|
-
|
|
197
|
-
This CLI tool is a wrapper around the `preset` generator. The relationship:
|
|
198
|
-
|
|
199
|
-
- **create-nx-terraform-app**: CLI user interface and workspace scaffolding
|
|
200
|
-
- **preset generator**: Actual workspace configuration logic
|
|
201
|
-
- **init + terraform-backend + terraform-module generators**: Executed by preset
|
|
202
|
-
|
|
203
|
-
The CLI provides:
|
|
204
|
-
- Interactive prompts for better UX
|
|
205
|
-
- Package manager detection and setup
|
|
206
|
-
- Git repository initialization
|
|
207
|
-
- Nx Cloud integration options
|
|
208
|
-
|
|
209
|
-
## Related Packages
|
|
210
|
-
|
|
211
|
-
- **nx-terraform**: The main plugin package containing generators and targets
|
|
212
|
-
- **create-nx-workspace**: Core Nx workspace creation functionality
|
|
213
|
-
|
|
214
|
-
## Development
|
|
215
|
-
|
|
216
|
-
### Building the Package
|
|
217
|
-
|
|
218
|
-
```bash
|
|
219
|
-
nx build create-nx-terraform-app
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### Testing
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
nx test create-nx-terraform-app
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
### Publishing
|
|
229
|
-
|
|
230
|
-
The package is published to npm and can be used globally or via `npx`:
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
# Published as: create-nx-terraform-app
|
|
234
|
-
npm publish
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
## Troubleshooting
|
|
238
|
-
|
|
239
|
-
### Common Issues
|
|
240
|
-
|
|
241
|
-
**Issue**: Workspace creation fails
|
|
242
|
-
- Ensure you have Node.js and npm/yarn/pnpm installed
|
|
243
|
-
- Check network connectivity (needs to download dependencies)
|
|
244
|
-
- Verify disk space for new workspace
|
|
245
|
-
|
|
246
|
-
**Issue**: Backend project not created
|
|
247
|
-
- Check that preset generator executed successfully
|
|
248
|
-
- Verify `nx.json` contains `nx-terraform` plugin entry
|
|
249
|
-
- Check `packages/terraform-setup/` directory exists
|
|
250
|
-
|
|
251
|
-
**Issue**: Permission errors
|
|
252
|
-
- On Unix systems, may need to use `npx` instead of global install
|
|
253
|
-
- Check write permissions in target directory
|
|
254
|
-
|
|
255
|
-
## Notes
|
|
256
|
-
|
|
257
|
-
- The backend project is always named `terraform-setup` (hardcoded in preset)
|
|
258
|
-
- The infrastructure module is always named `terraform-infra` (hardcoded in preset)
|
|
259
|
-
- Both projects are created automatically by the preset generator
|
|
260
|
-
- Requires Nx v22.0.2 or compatible version
|
|
261
|
-
- Uses CommonJS module system
|
|
262
|
-
- Package version matches the main plugin version for consistency
|
|
263
|
-
- The CLI automatically handles workspace name normalization (handles slashes)
|