Skip to content

Commit e091e59

Browse files
authored
Merge pull request #34 from stackql/feature/updates
Feature/updates
2 parents 6f870a1 + 38d2d0f commit e091e59

File tree

6 files changed

+390
-5
lines changed

6 files changed

+390
-5
lines changed

examples/azure/azure-stack/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ stackql-deploy { build | test | teardown } { stack-directory } { deployment envi
4040
For example, to deploy the stack to an environment labeled `sit`, run the following:
4141
4242
```bash
43-
export AZURE_VM_ADMIN_PASSWORD="your_password_here"
43+
export AZURE_VM_ADMIN_PASSWORD="Your_password_here1"
4444
stackql-deploy build \
4545
examples/azure/azure-stack sit \
4646
-e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468 \
@@ -63,7 +63,8 @@ To test a stack to ensure that all resources are present and in the desired stat
6363
```bash
6464
stackql-deploy test \
6565
examples/azure/azure-stack sit \
66-
-e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468
66+
-e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468 \
67+
-e AZURE_VM_ADMIN_PASSWORD=$AZURE_VM_ADMIN_PASSWORD
6768
```
6869
6970
### Tearing down a stack
@@ -73,5 +74,6 @@ To destroy or deprovision all resources in a stack for our `sit` deployment exam
7374
```bash
7475
stackql-deploy teardown \
7576
examples/azure/azure-stack sit \
76-
-e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468
77+
-e AZURE_SUBSCRIPTION_ID=631d1c6d-2a65-43e7-93c2-688bfe4e1468 \
78+
-e AZURE_VM_ADMIN_PASSWORD=$AZURE_VM_ADMIN_PASSWORD
7779
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# example `stackql-deploy` stack
2+
3+
Based upon the [__terraform-google-load-balanced-vms__](https://github.com/GoogleCloudPlatform/terraform-google-load-balanced-vms) project.
4+
5+
![load balanced vms](https://raw.githubusercontent.com/GoogleCloudPlatform/terraform-google-load-balanced-vms/c3e9669856df44a7b7399a7119eda3ae9ce5a2fa/assets/load_balanced_vms_v1.svg)
6+
7+
## about `stackql-deploy`
8+
9+
[`stackql-deploy`](https://pypi.org/project/stackql-deploy/) is a multi cloud deployment automation and testing framework which is an alternative to Terraform or similar IaC tools. `stackql-deploy` uses a declarative model/ELT based approach to cloud resource deployment (inspired by [`dbt`](https://www.getdbt.com/)). Advantages of `stackql-deploy` include:
10+
11+
- declarative framework
12+
- no state file (state is determined from the target environment)
13+
- multi-cloud/omni-cloud ready
14+
- includes resource tests which can include secure config tests
15+
16+
## instaling `stackql-deploy`
17+
18+
`stackql-deploy` is installed as a python based CLI using...
19+
20+
```bash
21+
pip install stackql-deploy
22+
# or
23+
pip3 install stackql-deploy
24+
```
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
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
# Create a Network Security Group and rule
3+
resource "azurerm_network_security_group" "tfexample" {
4+
name = "my-terraform-nsg"
5+
location = azurerm_resource_group.tfexample.location
6+
resource_group_name = azurerm_resource_group.tfexample.name
7+
8+
security_rule {
9+
name = "HTTP"
10+
priority = 1001
11+
direction = "Inbound"
12+
access = "Allow"
13+
protocol = "Tcp"
14+
source_port_range = "*"
15+
destination_port_range = "8080"
16+
source_address_prefix = "*"
17+
destination_address_prefix = "*"
18+
}
19+
20+
tags = {
21+
environment = "my-terraform-env"
22+
}
23+
}
24+
25+
# Create a Network Interface
26+
resource "azurerm_network_interface" "tfexample" {
27+
name = "my-terraform-nic"
28+
location = azurerm_resource_group.tfexample.location
29+
resource_group_name = azurerm_resource_group.tfexample.name
30+
31+
ip_configuration {
32+
name = "my-terraform-nic-ip-config"
33+
subnet_id = azurerm_subnet.tfexample.id
34+
private_ip_address_allocation = "Dynamic"
35+
public_ip_address_id = azurerm_public_ip.tfexample.id
36+
}
37+
38+
tags = {
39+
environment = "my-terraform-env"
40+
}
41+
}
42+
43+
# Create a Network Interface Security Group association
44+
resource "azurerm_network_interface_security_group_association" "tfexample" {
45+
network_interface_id = azurerm_network_interface.tfexample.id
46+
network_security_group_id = azurerm_network_security_group.tfexample.id
47+
}
48+
49+
# Create a Virtual Machine
50+
resource "azurerm_linux_virtual_machine" "tfexample" {
51+
name = "my-terraform-vm"
52+
location = azurerm_resource_group.tfexample.location
53+
resource_group_name = azurerm_resource_group.tfexample.name
54+
network_interface_ids = [azurerm_network_interface.tfexample.id]
55+
size = "Standard_DS1_v2"
56+
computer_name = "myvm"
57+
admin_username = "azureuser"
58+
admin_password = "Password1234!"
59+
disable_password_authentication = false
60+
61+
source_image_reference {
62+
publisher = "Canonical"
63+
offer = "UbuntuServer"
64+
sku = "18.04-LTS"
65+
version = "latest"
66+
}
67+
68+
os_disk {
69+
name = "my-terraform-os-disk"
70+
storage_account_type = "Standard_LRS"
71+
caching = "ReadWrite"
72+
}
73+
74+
tags = {
75+
environment = "my-terraform-env"
76+
}
77+
}
78+
79+
# Configurate to run automated tasks in the VM start-up
80+
resource "azurerm_virtual_machine_extension" "tfexample" {
81+
name = "hostname"
82+
virtual_machine_id = azurerm_linux_virtual_machine.tfexample.id
83+
publisher = "Microsoft.Azure.Extensions"
84+
type = "CustomScript"
85+
type_handler_version = "2.1"
86+
87+
settings = <<SETTINGS
88+
{
89+
"commandToExecute": "echo 'Hello, World' > index.html ; nohup busybox httpd -f -p 8080 &"
90+
}
91+
SETTINGS
92+
93+
tags = {
94+
environment = "my-terraform-env"
95+
}
96+
}
97+
98+
# Data source to access the properties of an existing Azure Public IP Address
99+
data "azurerm_public_ip" "tfexample" {
100+
name = azurerm_public_ip.tfexample.name
101+
resource_group_name = azurerm_linux_virtual_machine.tfexample.resource_group_name
102+
}
103+
104+
# Output variable: Public IP address
105+
output "public_ip" {
106+
value = data.azurerm_public_ip.tfexample.ip_address
107+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*+ exists */
2+
SELECT name FROM google.serviceusage.services
3+
WHERE parent = '219788095364'
4+
AND parentType = 'projects'
5+
AND filter = 'state:ENABLED'
6+
AND name = 'compute.googleapis.com';
7+
8+
9+
projects//services/cloudtrace.googleapis.com
10+
11+
SELECT * FROM google.serviceusage.services
12+
WHERE name = 'projects/123/services/serviceusage.googleapis.com'
13+
14+
parent, parentType
15+
16+
17+
name string The resource name of the consumer and service. A valid name would be: - projects/123/services/serviceusage.googleapis.com
18+
config object The configuration of the service.
19+
parent string The resource name of the consumer. A valid name would be: - projects/123
20+
state string Whether or not the service has been enabled for use by the consumer.
21+
22+
23+
24+
/*+ createorupdate */
25+
{% for network_interface in network_interfaces | from_json %}
26+
DELETE FROM google.compute.instances
27+
WHERE project = '{{ project }}'
28+
AND zone = '{{ default_zone }}'
29+
AND instance = '{{ instance_name_prefix }}-{{ loop.index }}';
30+
{% endfor %}
31+
32+
33+
34+
35+
{{ range .root_projects }}
36+
{{ $project := . }}
37+
{{ range .apis }}
38+
EXEC google.serviceusage.services.enable
39+
@name = (
40+
SELECT
41+
'projects/' || name || '/services/{{ . }}'
42+
FROM google.cloudresourcemanager.projects
43+
WHERE parent='{{ $global.organization_id }}'
44+
and displayName= '{{ $project.displayName }}'
45+
);
46+
{{end}}
47+
{{end}}

0 commit comments

Comments
 (0)