Skip to content

Commit 23bfdc1

Browse files
committed
google example
1 parent c3c9d51 commit 23bfdc1

12 files changed

Lines changed: 100 additions & 174 deletions

File tree

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,94 @@
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+
```
422

5-
see the following links for more information on `stackql`, `stackql-deploy` and the `azure` provider:
23+
## Resources
624

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 |
1135

12-
## Overview
36+
## Environment-Specific CIDR Blocks
1337

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 |
1543

1644
## Prerequisites
1745

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):
2948

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+
```
3154

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
3358

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).
3760

38-
### Deploying a stack
61+
## Usage
3962

40-
For example, to deploy the stack to an environment labeled `sit`, run the following:
63+
### Deploy
4164

4265
```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}
4869
```
4970

50-
Use the `--dry-run` flag to view the queries to be run without actually running them, for example:
71+
### Test
5172

5273
```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}
5777
```
5878

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
6280

6381
```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}
6885
```
6986

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
7388

7489
```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+
```

examples/databricks/classic/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ For extra credit, you can (asynchronously) delete the unnecessary workspace with
6969
Time to get down to business. From the root of this repository:
7070

7171
```bash
72-
python3 -m venv myenv
7372
source examples/databricks/all-purpose-cluster/convenience.sh
7473
source venv/bin/activate
75-
pip install stackql-deploy
74+
install stackql-deploy from https://github.com/stackql/stackql-deploy-rs/releases
7675
```
7776

7877
> alternatively set the `AWS_REGION`, `AWS_ACCOUNT_ID`, `DATABRICKS_ACCOUNT_ID`, `DATABRICKS_AWS_ACCOUNT_ID` along with provider credentials `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `DATABRICKS_CLIENT_ID`, `DATABRICKS_CLIENT_SECRET`

examples/databricks/serverless/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ For extra credit, you can (asynchronously) delete the unnecessary workspace with
6969
Time to get down to business. From the root of this repository:
7070

7171
```bash
72-
python3 -m venv myenv
7372
source examples/databricks/serverless/convenience.sh
7473
source venv/bin/activate
75-
pip install stackql-deploy
74+
install stackql-deploy from https://github.com/stackql/stackql-deploy-rs/releases
7675
```
7776

7877
> alternatively set the `AWS_REGION`, `AWS_ACCOUNT_ID`, `DATABRICKS_ACCOUNT_ID`, `DATABRICKS_AWS_ACCOUNT_ID` along with provider credentials `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `DATABRICKS_CLIENT_ID`, `DATABRICKS_CLIENT_SECRET`

examples/databricks/snowflake-interoperability/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ For extra credit, you can (asynchronously) delete the unnecessary workspace with
6969
Time to get down to business. From the root of this repository:
7070

7171
```bash
72-
python3 -m venv myenv
7372
source examples/databricks/serverless/convenience.sh
7473
source venv/bin/activate
75-
pip install stackql-deploy
74+
install stackql-deploy from https://github.com/stackql/stackql-deploy-rs/releases
7675
```
7776

7877
> alternatively set the `AWS_REGION`, `AWS_ACCOUNT_ID`, `DATABRICKS_ACCOUNT_ID`, `DATABRICKS_AWS_ACCOUNT_ID` along with provider credentials `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `DATABRICKS_CLIENT_ID`, `DATABRICKS_CLIENT_SECRET`

examples/google/google-web-server/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,24 @@ flowchart LR
4343
- `stackql-deploy` installed ([releases](https://github.com/stackql/stackql-deploy-rs/releases))
4444
- Google Cloud credentials:
4545

46-
```bash
47-
export GOOGLE_CREDENTIALS=$(cat path/to/sa-key.json)
48-
export GOOGLE_PROJECT=your-project-id
49-
export GOOGLE_REGION=us-central1
50-
export GOOGLE_ZONE=us-central1-a
51-
```
46+
```bash
47+
export GOOGLE_CREDENTIALS=$(cat path/to/sa-key.json)
48+
export GOOGLE_PROJECT=stackql-demo
49+
export GOOGLE_REGION=us-central1
50+
export GOOGLE_ZONE=us-central1-a
51+
```
5252

5353
## Usage
5454

5555
### Deploy
5656

5757
```bash
58-
stackql-deploy build examples/google/google-web-server dev
58+
target/release/stackql-deploy build \
59+
examples/google/google-web-server dev \
60+
-e GOOGLE_PROJECT=${GOOGLE_PROJECT} \
61+
-e GOOGLE_REGION=${GOOGLE_REGION} \
62+
-e GOOGLE_ZONE=${GOOGLE_ZONE}
5963
```
60-
6164
### Test
6265

6366
```bash
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*+ exports */
2+
SELECT '{{ web_server_code | base64 }}' as web_server_code_base64

examples/google/google-web-server/stackql_manifest.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ resources:
6868
value: "{{ stack_name }}-{{ stack_env }}-ip"
6969
exports:
7070
- address
71+
- name: get_web_server_code
72+
type: query
73+
props:
74+
- name: web_server_code
75+
value: '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Hello StackQL</title><style>body{font-family:Tahoma,sans-serif;display:flex;justify-content:center;align-items:center;height:100vh;margin:0;background-color:#f0f0f0;text-align:center;}p{font-size:2em;font-weight:bold;}</style></head><body><p>Hello, StackQL!</p></body></html>'
76+
sql: |
77+
SELECT '{{ web_server_code | base64_encode }}' as web_server_code_base64
78+
exports:
79+
- web_server_code_base64
7180
- name: example_web_server
7281
props:
7382
- name: instance_name
@@ -98,16 +107,8 @@ resources:
98107
- name: metadata
99108
value:
100109
items:
101-
- key: startup-script
102-
value: |
103-
#!/bin/bash
104-
apt-get update
105-
apt-get install -y apache2
106-
systemctl start apache2
107-
systemctl enable apache2
108-
cat > /var/www/html/index.html << 'HTMLEOF'
109-
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>StackQL on GCP</title><style>body {font-family: Tahoma, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; text-align: center;} img {height: auto;} code {background-color: #e8e8e8; padding: 2px 6px; border-radius: 3px; font-weight: bold;} p {font-size: 1.5em; font-weight: bold;}</style></head><body><div><a href="https://github.com/stackql/stackql"><img src="https://stackql.io/img/stackql-logo-bold.png" alt="StackQL Logo"></a><p>Hello, <a href="https://crates.io/crates/stackql-deploy"><code>stackql-deploy</code></a> on GCP!</p></div></body></html>
110-
HTMLEOF
110+
- key: startup-script
111+
value: "#!/bin/bash\\napt-get update\\napt-get install -y apache2\\nsystemctl start apache2\\nsystemctl enable apache2\\necho {{ web_server_code_base64 }} | base64 -d > /var/www/html/index.html\\n"
111112
exports:
112113
- instance_name
113114
- name: get_web_server_url

examples/google/k8s-the-hard-way/README.md

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,7 @@ Based upon the [Kubernetes the Hard Way](https://github.com/kelseyhightower/kube
1616
`stackql-deploy` is installed as a python based CLI using...
1717

1818
```bash
19-
pip install stackql-deploy
19+
install stackql-deploy from https://github.com/stackql/stackql-deploy-rs/releases
2020
# or
2121
pip3 install stackql-deploy
2222
```
23-
> __Note for macOS users__
24-
> to install `stackql-deploy` in a virtual environment (which may be necessary on __macOS__), use the following:
25-
> ```bash
26-
> python3 -m venv myenv
27-
> source myenv/bin/activate
28-
> pip install stackql-deploy
29-
> ```
30-
31-
## getting started with `stackql-deploy`
32-
33-
Once installed, use the `init` command to scaffold a sample project directory to get started:
34-
35-
```bash
36-
stackql-deploy init k8s-the-hard-way
37-
```
38-
39-
this will create a directory named `k8s-the-hard-way` which can be updated for your stack, as you can see in this project.
40-
41-
## deploying using `stackql-deploy`
42-
43-
```bash
44-
export GOOGLE_CREDENTIALS=$(cat ./testcreds/k8s-the-hard-way-project-demo-service-account.json)
45-
# deploy a stack
46-
stackql-deploy build \
47-
examples/google/k8s-the-hard-way \
48-
dev \
49-
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
50-
--dry-run \
51-
--log-level DEBUG
52-
53-
# test a stack
54-
stackql-deploy test \
55-
examples/google/k8s-the-hard-way \
56-
dev \
57-
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
58-
--dry-run
59-
60-
# teardown a stack
61-
stackql-deploy teardown \
62-
examples/google/k8s-the-hard-way \
63-
dev \
64-
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
65-
--dry-run
66-
```

examples/google/load-balanced-vms/README.md

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,7 @@ Based upon the [__terraform-google-load-balanced-vms__](https://github.com/Googl
1818
`stackql-deploy` is installed as a python based CLI using...
1919

2020
```bash
21-
pip install stackql-deploy
21+
install stackql-deploy from https://github.com/stackql/stackql-deploy-rs/releases
2222
# or
2323
pip3 install stackql-deploy
2424
```
25-
> __Note for macOS users__
26-
> to install `stackql-deploy` in a virtual environment (which may be necessary on __macOS__), use the following:
27-
> ```bash
28-
> python3 -m venv myenv
29-
> source myenv/bin/activate
30-
> pip install stackql-deploy
31-
> ```
32-
33-
## getting started with `stackql-deploy`
34-
35-
Once installed, use the `init` command to scaffold a sample project directory to get started:
36-
37-
```bash
38-
stackql-deploy init load-balanced-vms
39-
```
40-
41-
this will create a directory named `load-balanced-vms` which can be updated for your stack, as you can see in this project.
42-
43-
## deploying using `stackql-deploy`
44-
45-
```bash
46-
export GOOGLE_CREDENTIALS=$(cat ./testcreds/stackql-deploy-project-demo-service-account.json)
47-
# deploy a stack
48-
stackql-deploy build \
49-
examples\google\load-balanced-vms \
50-
dev \
51-
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
52-
--dry-run \
53-
--log-level DEBUG
54-
55-
# test a stack
56-
stackql-deploy test \
57-
examples/google/k8s-the-hard-way \
58-
dev \
59-
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
60-
--dry-run
61-
62-
# teardown a stack
63-
stackql-deploy teardown \
64-
examples/google/k8s-the-hard-way \
65-
dev \
66-
-e GOOGLE_PROJECT=stackql-k8s-the-hard-way-demo \
67-
--dry-run
68-
```
69-
70-
71-
72-
stackql-deploy-project

examples/snowflake/entitlements/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ __`stackql-deploy`__ is a stateless, declarative, SQL driven Infrastructure-as-C
1515

1616
## Prerequisites
1717

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 `snowflake` provider, `SNOWFLAKE_PAT` must be set, for more information on authentication to `snowflake` see the [`snowflake` provider documentation](https://snowflake.stackql.io/providers/snowflake).
18+
This example requires `stackql-deploy` to be installed. Pre-built binaries are available from the [releases page](https://github.com/stackql/stackql-deploy-rs/releases). See`stackql-deploy` ([releases](https://github.com/stackql/stackql-deploy-rs/releases))__. The host used to run `stackql-deploy` needs the necessary environment variables set to authenticate to your specific provider, in the case of the `snowflake` provider, `SNOWFLAKE_PAT` must be set, for more information on authentication to `snowflake` see the [`snowflake` provider documentation](https://snowflake.stackql.io/providers/snowflake).
1919

2020
## Usage
2121

0 commit comments

Comments
 (0)