Skip to content

Commit 2c88afa

Browse files
authored
Merge pull request #50 from stackql/feature/add-command-specific-auth
Feature/add command specific auth
2 parents 2e94317 + 364f6ab commit 2c88afa

File tree

16 files changed

+380
-20
lines changed

16 files changed

+380
-20
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.8.0 (2024-11-09)
4+
5+
- Added option for command specific authentication
6+
37
## 1.7.7 (2024-10-09)
48

59
- Supported version pinning for providers(aws, gcp, azure and etc) in `manifest` file

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 StackQL Studios
3+
Copyright (c) 2022-2025 StackQL Studios
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# `stackql-deploy` starter project for `aws`
2+
3+
> for starter projects using other providers, try `stackql-deploy cmd-specific-auth --provider=azure` or `stackql-deploy cmd-specific-auth --provider=google`
4+
5+
see the following links for more information on `stackql`, `stackql-deploy` and the `aws` provider:
6+
7+
- [`aws` provider docs](https://stackql.io/registry/aws)
8+
- [`stackql`](https://github.com/stackql/stackql)
9+
- [`stackql-deploy` PyPI home page](https://pypi.org/project/stackql-deploy/)
10+
- [`stackql-deploy` GitHub repo](https://github.com/stackql/stackql-deploy)
11+
12+
## Overview
13+
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 `aws` and `azure` for example.
15+
16+
## Prerequisites
17+
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 `aws` provider, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and optionally `AWS_SESSION_TOKEN` must be set, for more information on authentication to `aws` see the [`aws` provider documentation](https://aws.stackql.io/providers/aws).
19+
20+
## Usage
21+
22+
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` folder.
23+
24+
The syntax for the `stackql-deploy` command is as follows:
25+
26+
```bash
27+
stackql-deploy { build | test | teardown } { stack-directory } { deployment environment} [ optional flags ]
28+
```
29+
30+
### Deploying a stack
31+
32+
For example, to deploy the stack named cmd-specific-auth to an environment labeled `sit`, run the following:
33+
34+
```bash
35+
stackql-deploy build cmd-specific-auth sit \
36+
-e AWS_REGION=ap-southeast-2
37+
```
38+
39+
Use the `--dry-run` flag to view the queries to be run without actually running them, for example:
40+
41+
```bash
42+
stackql-deploy build cmd-specific-auth sit \
43+
-e AWS_REGION=ap-southeast-2 \
44+
--dry-run
45+
```
46+
47+
### Testing a stack
48+
49+
To test a stack to ensure that all resources are present and in the desired state, run the following (in our `sit` deployment example):
50+
51+
```bash
52+
stackql-deploy test cmd-specific-auth sit \
53+
-e AWS_REGION=ap-southeast-2
54+
```
55+
56+
### Tearing down a stack
57+
58+
To destroy or deprovision all resources in a stack for our `sit` deployment example, run the following:
59+
60+
```bash
61+
stackql-deploy teardown cmd-specific-auth sit \
62+
-e AWS_REGION=ap-southeast-2
63+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* defines the provisioning and deprovisioning commands
2+
used to create, update or delete the resource
3+
replace queries with your queries */
4+
5+
/*+ exists */
6+
SELECT COUNT(*) as count FROM
7+
(
8+
SELECT vpc_id,
9+
json_group_object(tag_key, tag_value) as tags
10+
FROM aws.ec2.vpc_tags
11+
WHERE region = '{{ region }}'
12+
AND cidr_block = '{{ vpc_cidr_block }}'
13+
GROUP BY vpc_id
14+
HAVING json_extract(tags, '$.Provisioner') = 'stackql'
15+
AND json_extract(tags, '$.StackName') = '{{ stack_name }}'
16+
AND json_extract(tags, '$.StackEnv') = '{{ stack_env }}'
17+
) t;
18+
19+
/*+ create */
20+
INSERT INTO aws.ec2.vpcs (
21+
CidrBlock,
22+
Tags,
23+
EnableDnsSupport,
24+
EnableDnsHostnames,
25+
region
26+
)
27+
SELECT
28+
'{{ vpc_cidr_block }}',
29+
'{{ vpc_tags }}',
30+
true,
31+
true,
32+
'{{ region }}';
33+
34+
/*+ statecheck, retries=5, retry_delay=5 */
35+
SELECT COUNT(*) as count FROM
36+
(
37+
SELECT vpc_id,
38+
cidr_block,
39+
json_group_object(tag_key, tag_value) as tags
40+
FROM aws.ec2.vpc_tags
41+
WHERE region = '{{ region }}'
42+
AND cidr_block = '{{ vpc_cidr_block }}'
43+
GROUP BY vpc_id
44+
HAVING json_extract(tags, '$.Provisioner') = 'stackql'
45+
AND json_extract(tags, '$.StackName') = '{{ stack_name }}'
46+
AND json_extract(tags, '$.StackEnv') = '{{ stack_env }}'
47+
) t
48+
WHERE cidr_block = '{{ vpc_cidr_block }}';
49+
50+
/*+ exports, retries=5, retry_delay=5 */
51+
SELECT vpc_id, vpc_cidr_block FROM
52+
(
53+
SELECT vpc_id, cidr_block as "vpc_cidr_block",
54+
json_group_object(tag_key, tag_value) as tags
55+
FROM aws.ec2.vpc_tags
56+
WHERE region = '{{ region }}'
57+
AND cidr_block = '{{ vpc_cidr_block }}'
58+
GROUP BY vpc_id
59+
HAVING json_extract(tags, '$.Provisioner') = 'stackql'
60+
AND json_extract(tags, '$.StackName') = '{{ stack_name }}'
61+
AND json_extract(tags, '$.StackEnv') = '{{ stack_env }}'
62+
) t;
63+
64+
/*+ delete */
65+
DELETE FROM aws.ec2.vpcs
66+
WHERE data__Identifier = '{{ vpc_id }}'
67+
AND region = '{{ region }}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# aws starter project manifest file, add and update values as needed
3+
#
4+
version: 1
5+
name: "cmd-specific-auth"
6+
description: description for "cmd-specific-auth"
7+
providers:
8+
- aws
9+
globals:
10+
- name: region
11+
description: aws region
12+
value: "{{ AWS_REGION }}"
13+
- name: global_tags
14+
value:
15+
- Key: Provisioner
16+
Value: stackql
17+
- Key: StackName
18+
Value: "{{ stack_name }}"
19+
- Key: StackEnv
20+
Value: "{{ stack_env }}"
21+
resources:
22+
- name: example_vpc
23+
description: example vpc resource
24+
props:
25+
- name: vpc_cidr_block
26+
values:
27+
prd:
28+
value: "10.0.0.0/16"
29+
sit:
30+
value: "10.1.0.0/16"
31+
dev:
32+
value: "10.2.0.0/16"
33+
- name: vpc_tags
34+
value:
35+
- Key: Name
36+
Value: "{{ stack_name }}-{{ stack_env }}-vpc"
37+
merge: ['global_tags']
38+
exports:
39+
- vpc_id
40+
- vpc_cidr_block

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='stackql-deploy',
13-
version='1.7.7',
13+
version='1.8.0',
1414
description='Model driven resource provisioning and deployment framework using StackQL.',
1515
long_description=readme,
1616
long_description_content_type='text/x-rst',

stackql_deploy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.7.7'
1+
__version__ = '1.8.0'

stackql_deploy/cli.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ def parse_env_var(ctx, param, value):
8080
return env_vars
8181

8282
def setup_logger(command, args_dict):
83-
log_level = args_dict.get('log_level', 'INFO')
83+
log_level = args_dict.get('log_level', 'INFO').upper() # Normalize to uppercase
84+
valid_levels = {'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}
85+
86+
if log_level not in valid_levels:
87+
raise click.ClickException(
88+
f"Invalid log level: {log_level}. Valid levels are: {', '.join(valid_levels)}"
89+
)
90+
8491
logger.setLevel(log_level)
8592
logger.debug(f"'{command}' command called with args: {str(args_dict)}")
8693

0 commit comments

Comments
 (0)