|
1 | | -# `stackql-deploy` starter project for `azure` |
2 | | - |
3 | | -> for starter projects using other providers, try `stackql-deploy my_stack --provider=aws` or `stackql-deploy my_stack --provider=google` |
| 1 | +# Azure Web Server Example |
| 2 | + |
| 3 | +This example provisions an Azure networking stack with a web server VM using the `azure` provider. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +```mermaid |
| 8 | +flowchart LR |
| 9 | + subgraph RG["Resource Group"] |
| 10 | + subgraph VNet["VNet 10.x.0.0/16"] |
| 11 | + Subnet["Subnet\n10.x.1.0/24"] |
| 12 | + NIC["Network\nInterface"] |
| 13 | + Subnet --> NIC |
| 14 | + end |
| 15 | + NSG["NSG\nHTTP:8080\nSSH:22"] --> NIC |
| 16 | + PIP["Public IP"] --> NIC |
| 17 | + NIC --> VM["Web Server\nStandard_DS1_v2\nUbuntu 18.04"] |
| 18 | + VM --> EXT["Custom Script\nExtension"] |
| 19 | + end |
| 20 | + Internet(("Internet")) --> PIP |
| 21 | +``` |
4 | 22 |
|
5 | | -see the following links for more information on `stackql`, `stackql-deploy` and the `azure` provider: |
| 23 | +## Resources |
6 | 24 |
|
7 | | -- [`azure` provider docs](https://stackql.io/registry/azure) |
8 | | -- [`stackql`](https://github.com/stackql/stackql) |
9 | | -- [`stackql-deploy` on crates.io](https://crates.io/crates/stackql-deploy) |
10 | | -- [`stackql-deploy` GitHub repo](https://github.com/stackql/stackql-deploy) |
| 25 | +| # | Resource | Provider Resource | Description | |
| 26 | +|---|----------|-------------------|-------------| |
| 27 | +| 1 | `example_resource_group` | `azure.resources.resource_groups` | Resource group for all stack resources | |
| 28 | +| 2 | `example_vnet` | `azure.network.virtual_networks` | Virtual network with environment-specific CIDR | |
| 29 | +| 3 | `example_subnet` | `azure.network.subnets` | Subnet within the VNet | |
| 30 | +| 4 | `example_public_ip` | `azure.network.public_ip_addresses` | Static public IP for the VM | |
| 31 | +| 5 | `example_nsg` | `azure.network.network_security_groups` | NSG allowing HTTP (8080) and SSH (22 from VNet) | |
| 32 | +| 6 | `example_nic` | `azure.network.network_interfaces` | NIC with subnet, public IP, and NSG | |
| 33 | +| 7 | `example_web_server` | `azure.compute.virtual_machines` | Ubuntu 18.04 VM (Standard_DS1_v2) | |
| 34 | +| 8 | `example_vm_ext` | `azure.compute.virtual_machine_extensions` | Custom script extension to start a web server | |
11 | 35 |
|
12 | | -## Overview |
| 36 | +## Environment-Specific CIDR Blocks |
13 | 37 |
|
14 | | -__`stackql-deploy`__ is a stateless, declarative, SQL driven Infrastructure-as-Code (IaC) framework. There is no state file required as the current state is assessed for each resource at runtime. __`stackql-deploy`__ is capable of provisioning, deprovisioning and testing a stack which can include resources across different providers, like a stack spanning `azure` and `azure` for example. |
| 38 | +| Environment | VNet CIDR | Subnet CIDR | |
| 39 | +|-------------|-----------|-------------| |
| 40 | +| `prd` | 10.0.0.0/16 | 10.0.1.0/24 | |
| 41 | +| `sit` | 10.1.0.0/16 | 10.1.1.0/24 | |
| 42 | +| `dev` | 10.2.0.0/16 | 10.2.1.0/24 | |
15 | 43 |
|
16 | 44 | ## Prerequisites |
17 | 45 |
|
18 | | -This example requires `stackql-deploy` to be installed using __`pip install stackql-deploy`__. The host used to run `stackql-deploy` needs the necessary environment variables set to authenticate to your specific provider, in the case of the `azure` provider, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and optionally `AWS_SESSION_TOKEN` must be set, for more information on authentication to `azure` see the [`azure` provider documentation](https://azure.stackql.io/providers/azure). |
19 | | - |
20 | | -> __Note for macOS users__ |
21 | | -> to install `stackql-deploy` in a virtual environment (which may be necessary on __macOS__), use the following: |
22 | | -> ```bash |
23 | | -> python3 -m venv myenv |
24 | | -> source myenv/bin/activate |
25 | | -> pip install stackql-deploy |
26 | | -> ``` |
27 | | -
|
28 | | -## Usage |
| 46 | +- `stackql-deploy` installed ([releases](https://github.com/stackql/stackql-deploy-rs/releases)) |
| 47 | +- Azure service principal credentials set as environment variables (used for provider authentication): |
29 | 48 |
|
30 | | -Adjust the values in the [__`stackql_manifest.yml`__](stackql_manifest.yml) file if desired. The [__`stackql_manifest.yml`__](stackql_manifest.yml) file contains resource configuration variables to support multiple deployment environments, these will be used for `stackql` queries in the `resources` and `resources` folders. |
| 49 | + ```bash |
| 50 | + export AZURE_TENANT_ID=your_tenant_id |
| 51 | + export AZURE_CLIENT_ID=your_client_id |
| 52 | + export AZURE_CLIENT_SECRET=your_client_secret |
| 53 | + ``` |
31 | 54 |
|
32 | | -The syntax for the `stackql-deploy` command is as follows: |
| 55 | +- Stack-specific variables passed via `-e` flags (mapped to manifest globals): |
| 56 | + - `AZURE_SUBSCRIPTION_ID` - your Azure subscription ID |
| 57 | + - `AZURE_VM_ADMIN_PASSWORD` - password for the VM admin user |
33 | 58 |
|
34 | | -```bash |
35 | | -stackql-deploy { build | test | teardown } { stack-directory } { deployment environment} [ optional flags ] |
36 | | -``` |
| 59 | + For more information on authentication, see the [`azure` provider documentation](https://azure.stackql.io/providers/azure). |
37 | 60 |
|
38 | | -### Deploying a stack |
| 61 | +## Usage |
39 | 62 |
|
40 | | -For example, to deploy the stack to an environment labeled `sit`, run the following: |
| 63 | +### Deploy |
41 | 64 |
|
42 | 65 | ```bash |
43 | | -export AZURE_VM_ADMIN_PASSWORD="Your_password_here1" |
44 | | -stackql-deploy build \ |
45 | | -examples/azure/azure-stack sit \ |
46 | | --e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468 \ |
47 | | --e AZURE_VM_ADMIN_PASSWORD=$AZURE_VM_ADMIN_PASSWORD |
| 66 | +stackql-deploy build examples/azure/azure-web-server dev \ |
| 67 | + -e AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID} \ |
| 68 | + -e AZURE_VM_ADMIN_PASSWORD=${AZURE_VM_ADMIN_PASSWORD} |
48 | 69 | ``` |
49 | 70 |
|
50 | | -Use the `--dry-run` flag to view the queries to be run without actually running them, for example: |
| 71 | +### Test |
51 | 72 |
|
52 | 73 | ```bash |
53 | | -stackql-deploy build \ |
54 | | -examples/azure/azure-stack sit \ |
55 | | --e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468 \ |
56 | | ---dry-run |
| 74 | +stackql-deploy test examples/azure/azure-web-server dev \ |
| 75 | + -e AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID} \ |
| 76 | + -e AZURE_VM_ADMIN_PASSWORD=${AZURE_VM_ADMIN_PASSWORD} |
57 | 77 | ``` |
58 | 78 |
|
59 | | -### Testing a stack |
60 | | -
|
61 | | -To test a stack to ensure that all resources are present and in the desired state, run the following (in our `sit` deployment example): |
| 79 | +### Teardown |
62 | 80 |
|
63 | 81 | ```bash |
64 | | -stackql-deploy test \ |
65 | | -examples/azure/azure-stack sit \ |
66 | | --e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468 \ |
67 | | --e AZURE_VM_ADMIN_PASSWORD=$AZURE_VM_ADMIN_PASSWORD |
| 82 | +stackql-deploy teardown examples/azure/azure-web-server dev \ |
| 83 | + -e AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID} \ |
| 84 | + -e AZURE_VM_ADMIN_PASSWORD=${AZURE_VM_ADMIN_PASSWORD} |
68 | 85 | ``` |
69 | 86 |
|
70 | | -### Tearing down a stack |
71 | | -
|
72 | | -To destroy or deprovision all resources in a stack for our `sit` deployment example, run the following: |
| 87 | +### Debug mode |
73 | 88 |
|
74 | 89 | ```bash |
75 | | -stackql-deploy teardown \ |
76 | | -examples/azure/azure-stack sit \ |
77 | | --e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468 \ |
78 | | --e AZURE_VM_ADMIN_PASSWORD=$AZURE_VM_ADMIN_PASSWORD |
79 | | -``` |
| 90 | +stackql-deploy build examples/azure/azure-web-server dev \ |
| 91 | + -e AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID} \ |
| 92 | + -e AZURE_VM_ADMIN_PASSWORD=${AZURE_VM_ADMIN_PASSWORD} \ |
| 93 | + --log-level debug |
| 94 | +``` |
0 commit comments