Skip to content

Commit 764c8a7

Browse files
committed
updated starter template
1 parent ffbf5c5 commit 764c8a7

5 files changed

Lines changed: 69 additions & 66 deletions

File tree

src/commands/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,25 @@ fn run_build(
536536

537537
// Post-deploy state check
538538
if is_created_or_updated {
539+
// After create/update, re-run the exists query to capture
540+
// this.* fields (e.g. identifier) that are needed by the
541+
// statecheck and exports queries.
542+
if let Some(ref eq) = exists_query {
543+
let eq_opts = resource_queries.get("exists").unwrap();
544+
let (_exists, fields) = runner.check_if_resource_exists(
545+
resource,
546+
&eq.0,
547+
eq_opts.options.retries.max(3),
548+
eq_opts.options.retry_delay.max(5),
549+
dry_run,
550+
show_queries,
551+
false,
552+
);
553+
apply_exists_fields(fields, &resource.name, &mut full_context);
554+
// Re-render exports with the newly captured fields
555+
exports_query_str = render_exports!(runner, resource_queries, resource, &full_context);
556+
}
557+
539558
if let Some(sq) = render_statecheck!(runner, resource_queries, resource, &full_context) {
540559
let sq_opts = resource_queries.get("statecheck").unwrap();
541560
is_correct_state = runner.check_if_resource_is_correct_state(

src/commands/init.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ pub fn command() -> Command {
9090
.action(ArgAction::Set)
9191
.conflicts_with("provider"),
9292
)
93+
.arg(
94+
Arg::new("env")
95+
.short('e')
96+
.long("env")
97+
.help("Default environment for examples in generated README (default: dev)")
98+
.default_value("dev")
99+
.action(ArgAction::Set),
100+
)
93101
}
94102

95103
/// Executes the `init` command to initialize a new project structure.
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
# `stackql-deploy` starter project for `aws`
22

3-
> for starter projects using other providers, try `stackql-deploy {{ stack_name }} --provider=azure` or `stackql-deploy {{ stack_name }} --provider=google`
3+
> for starter projects using other providers, try `stackql-deploy init {{ stack_name }} --provider=azure` or `stackql-deploy init {{ stack_name }} --provider=google`
44

5-
see the following links for more information on `stackql`, `stackql-deploy` and the `aws` provider:
5+
see the following links for more information on `stackql`, `stackql-deploy` and the `awscc` provider:
66

7-
- [`aws` provider docs](https://stackql.io/registry/aws)
7+
- [`awscc` provider docs](https://awscc.stackql.io/providers/awscc/)
88
- [`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)
9+
- [`stackql-deploy` GitHub repo](https://github.com/stackql/stackql-deploy-rs)
1110

1211
## Overview
1312

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.
13+
__`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.
1514

1615
## Prerequisites
1716

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).
17+
This example requires `stackql-deploy` to be installed. The host used to run `stackql-deploy` needs the necessary environment variables set to authenticate to your specific provider, in the case of `aws`, `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 [`awscc` provider documentation](https://awscc.stackql.io/providers/awscc/).
1918

2019
## Usage
2120

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.
21+
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.
2322

2423
The syntax for the `stackql-deploy` command is as follows:
2524

2625
```bash
2726
stackql-deploy { build | test | teardown } { stack-directory } { deployment environment} [ optional flags ]
28-
```
27+
```
2928

3029
### Deploying a stack
3130

3231
For example, to deploy the stack named {{ stack_name }} to an environment labeled `sit`, run the following:
3332

3433
```bash
3534
stackql-deploy build {{ stack_name }} sit \
36-
-e AWS_REGION=ap-southeast-2
35+
-e AWS_REGION=us-east-1
3736
```
3837

3938
Use the `--dry-run` flag to view the queries to be run without actually running them, for example:
4039

4140
```bash
4241
stackql-deploy build {{ stack_name }} sit \
43-
-e AWS_REGION=ap-southeast-2 \
42+
-e AWS_REGION=us-east-1 \
4443
--dry-run
4544
```
4645

@@ -50,7 +49,7 @@ To test a stack to ensure that all resources are present and in the desired stat
5049

5150
```bash
5251
stackql-deploy test {{ stack_name }} sit \
53-
-e AWS_REGION=ap-southeast-2
52+
-e AWS_REGION=us-east-1
5453
```
5554

5655
### Tearing down a stack
@@ -59,5 +58,5 @@ To destroy or deprovision all resources in a stack for our `sit` deployment exam
5958

6059
```bash
6160
stackql-deploy teardown {{ stack_name }} sit \
62-
-e AWS_REGION=ap-southeast-2
63-
```
61+
-e AWS_REGION=us-east-1
62+
```
Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,44 @@
1-
/* defines the provisioning and deprovisioning commands
2-
used to create, update or delete the resource
3-
replace queries with your queries */
4-
51
/*+ exists */
2+
SELECT split_part(ResourceARN, '/', 2) as identifier
3+
FROM awscc.tagging.tagged_resources
4+
WHERE region = '{% raw %}{{ region }}{% endraw %}'
5+
AND TagFilters = '[{"Key":"stackql:stack-name","Values":["{% raw %}{{ stack_name }}{% endraw %}"]},{"Key":"stackql:stack-env","Values":["{% raw %}{{ stack_env }}{% endraw %}"]},{"Key":"stackql:resource-name","Values":["example_vpc"]}]'
6+
AND ResourceTypeFilters = '["ec2:vpc"]';
7+
8+
/*+ statecheck, retries=5, retry_delay=5 */
69
SELECT COUNT(*) as count FROM
710
(
8-
SELECT vpc_id,
9-
json_group_object(tag_key, tag_value) as tags
10-
FROM aws.ec2.vpc_tags
11-
WHERE region = '{% raw %}{{ region }}{% endraw %}'
12-
AND cidr_block = '{% raw %}{{ vpc_cidr_block }}{% endraw %}'
13-
GROUP BY vpc_id
14-
HAVING json_extract(tags, '$.Provisioner') = 'stackql'
15-
AND json_extract(tags, '$.StackName') = '{% raw %}{{ stack_name }}{% endraw %}'
16-
AND json_extract(tags, '$.StackEnv') = '{% raw %}{{ stack_env }}{% endraw %}'
17-
) t;
11+
SELECT vpc_id, cidr_block
12+
FROM awscc.ec2.vpcs
13+
WHERE Identifier = '{% raw %}{{ this.identifier }}{% endraw %}'
14+
AND region = '{% raw %}{{ region }}{% endraw %}'
15+
) t
16+
WHERE cidr_block = '{% raw %}{{ vpc_cidr_block }}{% endraw %}';
1817

1918
/*+ create */
20-
INSERT INTO aws.ec2.vpcs (
19+
INSERT INTO awscc.ec2.vpcs (
2120
CidrBlock,
2221
Tags,
2322
EnableDnsSupport,
24-
EnableDnsHostnames,
23+
EnableDnsHostnames,
2524
region
2625
)
27-
SELECT
26+
SELECT
2827
'{% raw %}{{ vpc_cidr_block }}{% endraw %}',
2928
'{% raw %}{{ vpc_tags }}{% endraw %}',
3029
true,
3130
true,
3231
'{% raw %}{{ region }}{% endraw %}';
3332

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 = '{% raw %}{{ region }}{% endraw %}'
42-
AND cidr_block = '{% raw %}{{ vpc_cidr_block }}{% endraw %}'
43-
GROUP BY vpc_id
44-
HAVING json_extract(tags, '$.Provisioner') = 'stackql'
45-
AND json_extract(tags, '$.StackName') = '{% raw %}{{ stack_name }}{% endraw %}'
46-
AND json_extract(tags, '$.StackEnv') = '{% raw %}{{ stack_env }}{% endraw %}'
47-
) t
48-
WHERE cidr_block = '{% raw %}{{ vpc_cidr_block }}{% endraw %}';
49-
5033
/*+ 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
34+
SELECT split_part(ResourceARN, '/', 2) as vpc_id,
35+
'{% raw %}{{ vpc_cidr_block }}{% endraw %}' as vpc_cidr_block
36+
FROM awscc.tagging.tagged_resources
5637
WHERE region = '{% raw %}{{ region }}{% endraw %}'
57-
AND cidr_block = '{% raw %}{{ vpc_cidr_block }}{% endraw %}'
58-
GROUP BY vpc_id
59-
HAVING json_extract(tags, '$.Provisioner') = 'stackql'
60-
AND json_extract(tags, '$.StackName') = '{% raw %}{{ stack_name }}{% endraw %}'
61-
AND json_extract(tags, '$.StackEnv') = '{% raw %}{{ stack_env }}{% endraw %}'
62-
) t;
38+
AND TagFilters = '[{"Key":"stackql:stack-name","Values":["{% raw %}{{ stack_name }}{% endraw %}"]},{"Key":"stackql:stack-env","Values":["{% raw %}{{ stack_env }}{% endraw %}"]},{"Key":"stackql:resource-name","Values":["example_vpc"]}]'
39+
AND ResourceTypeFilters = '["ec2:vpc"]';
6340

6441
/*+ delete */
65-
DELETE FROM aws.ec2.vpcs
66-
WHERE Identifier = '{% raw %}{{ vpc_id }}{% endraw %}'
67-
AND region = '{% raw %}{{ region }}{% endraw %}';
42+
DELETE FROM awscc.ec2.vpcs
43+
WHERE data__Identifier = '{% raw %}{{ vpc_id }}{% endraw %}'
44+
AND region = '{% raw %}{{ region }}{% endraw %}';

template-hub/aws/starter/stackql_manifest.yml.template

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ version: 1
55
name: "{{ stack_name }}"
66
description: description for "{{ stack_name }}"
77
providers:
8-
- aws
8+
- awscc
99
globals:
1010
- name: region
1111
description: aws region
1212
value: "{% raw %}{{ AWS_REGION }}{% endraw %}"
1313
- name: global_tags
1414
value:
15-
- Key: Provisioner
16-
Value: stackql
17-
- Key: StackName
15+
- Key: 'stackql:stack-name'
1816
Value: "{% raw %}{{ stack_name }}{% endraw %}"
19-
- Key: StackEnv
17+
- Key: 'stackql:stack-env'
2018
Value: "{% raw %}{{ stack_env }}{% endraw %}"
19+
- Key: 'stackql:resource-name'
20+
Value: "{% raw %}{{ resource_name }}{% endraw %}"
2121
resources:
2222
- name: example_vpc
2323
description: example vpc resource

0 commit comments

Comments
 (0)