|
1 | 1 | # Examples |
2 | 2 |
|
3 | | -Working YAML examples for `ApplyDocument` resources used by `matlas infra`. |
4 | | - |
5 | | -## Files |
6 | | - |
7 | | -- `users-basic.yaml`: Single `DatabaseUser` with a basic read role on `admin`. |
8 | | -- `users-standalone-multiple.yaml`: Two standalone users with different roles and labels. |
9 | | -- `overlay-network-and-user.yaml`: Adds a user and a `NetworkAccess` IP entry (overlay style). |
10 | | -- `custom-roles-and-users.yaml`: Defines a `DatabaseRole` and a user that uses it. |
11 | | -- `cluster-basic.yaml`: Minimal `Cluster` definition. |
12 | | -- `cluster-advanced.yaml`: Cluster with autoscaling and replication spec. |
13 | | -- `project-with-cluster-and-users.yaml`: Cluster plus an app user in one document. |
14 | | -- `custom-roles-example.yaml`: Comprehensive custom roles example including users. |
15 | | - - `users-scoped.yaml`: Users scoped to specific clusters via `scopes`. |
16 | | - - `network-variants.yaml`: `NetworkAccess` examples for `cidr`, `ipAddress` with `deleteAfterDate`, and `awsSecurityGroup`. |
17 | | - - `dependencies-and-deletion.yaml`: Demonstrates `dependsOn` and `deletionPolicy` between resources. |
18 | | - - `cluster-multiregion.yaml`: Multi-region cluster using `replicationSpecs` and `regionConfigs`. |
19 | | - - `cluster-security-and-tags.yaml`: Cluster with `encryption`, `biConnector`, and `tags`. |
20 | | - - `project-format.yaml`: Project-format configuration consumable by infra commands. |
| 3 | +Working YAML examples for `ApplyDocument` resources used by `matlas infra` and comprehensive demonstrations of CLI functionality. |
| 4 | + |
| 5 | +## Discovery Examples |
| 6 | + |
| 7 | +- **`discovery-basic.yaml`**: Basic discovered project converted to ApplyDocument format with cluster, user, and network access |
| 8 | +- **`discovery-with-databases.yaml`**: Comprehensive discovery including database-level resources (databases, collections, indexes, custom roles) |
| 9 | + |
| 10 | +## Cluster Examples |
| 11 | + |
| 12 | +- **`cluster-basic.yaml`**: Minimal cluster definition for development environments |
| 13 | +- **`cluster-advanced.yaml`**: Cluster with autoscaling and replication specifications |
| 14 | +- **`cluster-comprehensive.yaml`**: Production-ready cluster with autoscaling, multi-region, security features, and proper tagging |
| 15 | +- **`cluster-multiregion.yaml`**: Multi-region cluster using `replicationSpecs` and `regionConfigs` |
| 16 | +- **`cluster-security-and-tags.yaml`**: Cluster with encryption, BI Connector, and comprehensive tags |
| 17 | + |
| 18 | +## User Management Examples |
| 19 | + |
| 20 | +- **`users-basic.yaml`**: Single DatabaseUser with basic read role |
| 21 | +- **`users-standalone-multiple.yaml`**: Multiple users with different roles and labels |
| 22 | +- **`users-scoped.yaml`**: Users scoped to specific clusters via `scopes` |
| 23 | +- **`user-password-management.yaml`**: Comprehensive user management demonstrating password display features and different user types |
| 24 | +- **`users-with-password-display.yaml`**: Users configured for password display during creation |
| 25 | + |
| 26 | +## Authentication and Database Operations |
| 27 | + |
| 28 | +- **`database-operations-authentication.yaml`**: Examples demonstrating the three authentication methods for database operations |
| 29 | +- **`atlas-vs-database-users-roles.yaml`**: Comparison between Atlas-managed and database-level users |
| 30 | + |
| 31 | +## Custom Roles Examples |
| 32 | + |
| 33 | +- **`custom-roles-and-users.yaml`**: Basic custom role definition with associated user |
| 34 | +- **`custom-roles-example.yaml`**: Comprehensive custom roles example |
| 35 | +- **`custom-roles-comprehensive.yaml`**: Advanced custom roles with granular collection-level permissions |
| 36 | + |
| 37 | +## Network Access Examples |
| 38 | + |
| 39 | +- **`network-access.yaml`**: Basic network access configuration |
| 40 | +- **`network-variants.yaml`**: Multiple NetworkAccess types (CIDR, IP with expiration, AWS security groups) |
| 41 | +- **`overlay-network-and-user.yaml`**: Overlay-style addition of user and network access |
| 42 | + |
| 43 | +## Infrastructure Management |
| 44 | + |
| 45 | +- **`project-format.yaml`**: Project-format configuration for infrastructure commands |
| 46 | +- **`project-with-cluster-and-users.yaml`**: Complete project with cluster and users in one document |
| 47 | +- **`safe-operations-preserve-existing.yaml`**: Demonstrates safe operations using `--preserve-existing` flag |
| 48 | +- **`dependencies-and-deletion.yaml`**: Resource dependencies and deletion policies |
21 | 49 |
|
22 | 50 | ## Usage |
23 | 51 |
|
| 52 | +### Environment Variables |
| 53 | + |
24 | 54 | Replace placeholders like "My Project" and provide environment variables for passwords before running: |
25 | 55 |
|
26 | 56 | ```bash |
| 57 | +# Basic user passwords |
27 | 58 | export APP_USER_PASSWORD='StrongPass123!' |
28 | 59 | export APP_WRITER_PASSWORD='StrongPass123!' |
29 | 60 | export ANALYTICS_PASSWORD='StrongPass123!' |
30 | 61 | export OVERLAY_USER_PASSWORD='StrongPass123!' |
31 | 62 | export ROLE_USER_PASSWORD='StrongPass123!' |
| 63 | + |
| 64 | +# Advanced user passwords for comprehensive examples |
| 65 | +export SERVICE_ACCOUNT_PASSWORD='ServicePass123!' |
| 66 | +export DATABASE_ADMIN_PASSWORD='AdminPass123!' |
| 67 | +export CLUSTER_USER_PASSWORD='ClusterPass123!' |
| 68 | +export ECOMMERCE_APP_PASSWORD='EcommercePass123!' |
| 69 | +export DATABASE_MANAGER_PASSWORD='ManagerPass123!' |
| 70 | + |
| 71 | +# Database operations passwords |
| 72 | +export DB_OPERATIONS_PASSWORD='DbOpsPass123!' |
| 73 | +export SAFE_TEST_PASSWORD='SafeTestPass123!' |
| 74 | +``` |
| 75 | + |
| 76 | +### Discovery Workflows |
| 77 | + |
| 78 | +```bash |
| 79 | +# Discover existing project |
| 80 | +matlas discover --project-id <project-id> --output-file discovered.yaml |
| 81 | + |
| 82 | +# Discover with database resources |
| 83 | +matlas discover \ |
| 84 | + --project-id <project-id> \ |
| 85 | + --include-databases \ |
| 86 | + --use-temp-user \ |
| 87 | + --convert-to-apply \ |
| 88 | + --output-file complete-discovery.yaml |
| 89 | + |
| 90 | +# Filter discovery by resource type |
| 91 | +matlas discover --project-id <project-id> --include clusters,users --output-file filtered.yaml |
32 | 92 | ``` |
33 | 93 |
|
34 | | -Validate/diff/apply: |
| 94 | +### Infrastructure Operations |
35 | 95 |
|
36 | 96 | ```bash |
| 97 | +# Validate configurations |
37 | 98 | matlas infra validate -f examples/users-basic.yaml |
38 | | -matlas infra diff -f examples/custom-roles-and-users.yaml |
39 | | -matlas infra apply -f examples/overlay-network-and-user.yaml --auto-approve |
| 99 | +matlas infra validate -f examples/cluster-comprehensive.yaml |
| 100 | + |
| 101 | +# Preview changes |
| 102 | +matlas infra diff -f examples/custom-roles-comprehensive.yaml --detailed |
| 103 | +matlas infra plan -f examples/discovery-basic.yaml --output table |
| 104 | + |
| 105 | +# Apply changes safely |
| 106 | +matlas infra apply -f examples/safe-operations-preserve-existing.yaml --preserve-existing --auto-approve |
| 107 | +matlas infra apply -f examples/overlay-network-and-user.yaml --dry-run --dry-run-mode thorough |
40 | 108 | ``` |
41 | 109 |
|
| 110 | +### Database Operations with New Authentication |
| 111 | + |
| 112 | +```bash |
| 113 | +# Create database with temporary user (recommended) |
| 114 | +matlas database create inventory \ |
| 115 | + --cluster my-cluster \ |
| 116 | + --project-id <project-id> \ |
| 117 | + --collection products \ |
| 118 | + --use-temp-user |
| 119 | + |
| 120 | +# Create database with manual credentials |
| 121 | +matlas database create inventory \ |
| 122 | + --cluster my-cluster \ |
| 123 | + --project-id <project-id> \ |
| 124 | + --collection products \ |
| 125 | + --username dbuser \ |
| 126 | + --password dbpass |
| 127 | + |
| 128 | +# Create database with direct connection |
| 129 | +matlas database create inventory \ |
| 130 | + --connection-string "mongodb+srv://user:pass@cluster/" \ |
| 131 | + --collection products |
| 132 | +``` |
| 133 | + |
| 134 | +### User Management with Password Display |
| 135 | + |
| 136 | +```bash |
| 137 | +# Create user and display password |
| 138 | +matlas atlas users create \ |
| 139 | + --project-id <project-id> \ |
| 140 | + --username myuser \ |
| 141 | + --roles "readWrite@myapp" \ |
| 142 | + --show-password |
| 143 | + |
| 144 | +# Create database user with custom role |
| 145 | +matlas database users create appuser \ |
| 146 | + --cluster my-cluster \ |
| 147 | + --project-id <project-id> \ |
| 148 | + --database myapp \ |
| 149 | + --use-temp-user \ |
| 150 | + --password "SecurePass123!" \ |
| 151 | + --roles "customRole@myapp" \ |
| 152 | + --show-password |
| 153 | +``` |
| 154 | + |
| 155 | +## Implementation Notes |
| 156 | + |
| 157 | +- **Database Creation**: All database creation now requires `--collection` parameter for immediate visibility |
| 158 | +- **Authentication Methods**: Choose one of three methods: `--use-temp-user`, `--username/--password`, or `--connection-string` |
| 159 | +- **Safety Features**: Use `--preserve-existing` flag to protect existing resources during apply operations |
| 160 | +- **Discovery**: Include `--include-databases` for comprehensive resource enumeration |
| 161 | +- **Custom Roles**: Use `matlas database roles create` commands for role implementation |
| 162 | + |
42 | 163 | These examples mirror structures used in the test scripts under `scripts/test/` and adhere to the types in `internal/types/`. |
0 commit comments