Skip to content

Commit af2a2de

Browse files
authored
feat: manage destructor creation and activation separately (#66)
1 parent fc4ccf8 commit af2a2de

File tree

13 files changed

+120
-62
lines changed

13 files changed

+120
-62
lines changed

.github/renovate.json5

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,62 @@
33
"config:best-practices",
44
"github>aquaproj/aqua-renovate-config#2.7.5"
55
],
6-
"schedule": [
7-
"after 9am on the first day of the month"
8-
],
9-
"assigneesFromCodeOwners": true,
10-
"dependencyDashboardAutoclose": true,
11-
"addLabels": [
12-
"auto-upgrade"
13-
],
146
"enabledManagers": [
15-
"terraform"
7+
"terraform",
8+
"github-actions"
169
],
1710
"terraform": {
1811
"ignorePaths": [
1912
"**/context.tf" // Mixin file https://github.com/cloudposse/terraform-null-label/blob/main/exports/context.tf
13+
],
14+
"fileMatch": [
15+
"\\.tf$",
16+
"\\.tofu$"
2017
]
2118
},
19+
"schedule": [
20+
"after 9am on the first day of the month"
21+
],
22+
"assigneesFromCodeOwners": true,
23+
"dependencyDashboardAutoclose": true,
24+
"addLabels": ["{{manager}}"],
2225
"packageRules": [
2326
{
24-
"matchDepTypes": [
25-
"optionalDependencies"
26-
],
27-
// Allow auto merge if it's not a major version update
28-
"matchUpdateTypes": [
29-
"minor",
30-
"patch",
31-
"pin",
32-
"digest"
33-
],
34-
"automerge": true
27+
"matchManagers": ["github-actions"],
28+
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
29+
"automerge": true,
30+
"automergeType": "branch",
31+
"groupName": "github-actions-auto-upgrade",
32+
"addLabels": ["auto-upgrade"]
33+
},
34+
{
35+
"matchManagers": ["github-actions"],
36+
"matchUpdateTypes": ["major"],
37+
"groupName": "github-actions-needs-review",
38+
"addLabels": ["needs-review"]
39+
},
40+
{
41+
"matchManagers": ["terraform"],
42+
"groupName": "tf",
43+
"addLabels": ["needs-review"]
44+
},
45+
{
46+
"matchFileNames": ["**/*.tofu", "**/*.tf"],
47+
"matchDatasources": ["terraform-provider", "terraform-module"],
48+
"registryUrls": ["https://registry.opentofu.org"],
49+
"groupName": "tf"
50+
},
51+
{
52+
"matchFileNames": ["**/*.tofu"],
53+
"matchDepTypes": ["required_version"],
54+
"registryUrls": ["https://registry.opentofu.org"],
55+
"groupName": "tf"
56+
},
57+
{
58+
"matchFileNames": ["**/*.tf"],
59+
"matchDepTypes": ["required_version"],
60+
"registryUrls": ["https://registry.terraform.io"],
61+
"groupName": "tf"
3562
}
3663
]
37-
}
64+
}

.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Check out Git repository
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1717
- name: Trunk Check
18-
uses: trunk-io/trunk-action@v1
18+
uses: trunk-io/trunk-action@4d5ecc89b2691705fd08c747c78652d2fc806a94 # v1.1.19

.github/workflows/test.yaml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,8 @@ jobs:
2626
matrix:
2727
tf: [tofu, terraform]
2828
steps:
29-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30-
31-
- name: Aqua Cache
32-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
33-
if: ${{ !github.event.act }} # Don't enable the cache step if we're using act for testing
34-
with:
35-
path: ~/.local/share/aquaproj-aqua
36-
key: v1-aqua-installer-${{runner.os}}-${{runner.arch}}-${{hashFiles('aqua.yaml')}}
37-
restore-keys: |
38-
v1-aqua-installer-${{runner.os}}-${{runner.arch}}-
39-
40-
- name: Install Aqua
41-
uses: aquaproj/aqua-installer@5e54e5cee8a95ee2ce7c04cb993da6dfad13e59c # v3.2.1
29+
- uses: masterpointio/github-action-tf-test@c3b619f3bca9e4f482b9e0fb3166ab3f02d9d54c # v1.0.0
4230
with:
43-
aqua_version: v2.48.1
44-
45-
- name: Aqua Install
46-
shell: bash
47-
run: aqua install --tags ${{ matrix.tf }}
48-
49-
- run: ${{ matrix.tf }} init
50-
- run: ${{ matrix.tf }} test
31+
tf_type: ${{ matrix.tf }}
32+
aws_role_arn: ${{ vars.TF_TEST_AWS_ROLE_ARN }}
33+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/trunk-upgrade.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,17 @@ jobs:
2727
private_key: ${{ secrets.MP_BOT_APP_PRIVATE_KEY }}
2828

2929
- name: Upgrade
30+
id: trunk-upgrade
3031
uses: trunk-io/trunk-action/upgrade@4d5ecc89b2691705fd08c747c78652d2fc806a94 # v1.1.19
3132
with:
3233
github-token: ${{ steps.generate-token.outputs.token }}
3334
reviewers: "@masterpointio/masterpoint-internal"
3435
prefix: "chore: "
36+
37+
- name: Merge PR automatically
38+
if: steps.trunk-upgrade.outputs.pull-request-number != ''
39+
env:
40+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
41+
PR_NUMBER: ${{ steps.trunk-upgrade.outputs.pull-request-number }}
42+
run: |
43+
gh pr merge "$PR_NUMBER" --squash --auto --delete-branch

.trunk/trunk.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
33
version: 0.1
44
cli:
5-
version: 1.22.12
5+
version: 1.22.15
66
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
77
plugins:
88
sources:
@@ -20,15 +20,16 @@ lint:
2020
# Incompatible with some Terraform features: https://github.com/tenable/terrascan/issues/1331
2121
- terrascan
2222
enabled:
23+
- renovate@40.0.0
2324
- tofu@1.9.1
2425
- actionlint@1.7.7
25-
- checkov@3.2.408
26+
- checkov@3.2.413
2627
- git-diff-check
2728
- markdownlint@0.44.0
2829
- prettier@3.5.3
2930
- tflint@0.56.0
3031
- trivy@0.61.1
31-
- trufflehog@3.88.25
32+
- trufflehog@3.88.26
3233
- yamllint@1.37.0
3334
ignore:
3435
- linters: [tofu]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ This is to support easy local and outside-spacelift operations. Keeping variable
293293
| <a name="input_common_config_file"></a> [common\_config\_file](#input\_common\_config\_file) | Name of the common configuration file for the stack across a root module. | `string` | `"common.yaml"` | no |
294294
| <a name="input_default_tf_workspace_enabled"></a> [default\_tf\_workspace\_enabled](#input\_default\_tf\_workspace\_enabled) | Enables the use of `default` Terraform workspace instead of managing multiple workspaces within a root module.<br/><br/>NOTE: We encourage the use of Terraform workspaces to manage multiple environments.<br/>However, you will want to disable this behavior if you're utilizing different backends for each instance<br/>of your root modules (we call this "Dynamic Backends"). | `bool` | `false` | no |
295295
| <a name="input_description"></a> [description](#input\_description) | A description for the created Stacks. This is a template string that will be rendered with the final config object for the stack.<br/> See the main.tf for full internals of that object and the documentation on templatestring for usage.<br/> https://opentofu.org/docs/language/functions/templatestring/ | `string` | `"Root Module: ${root_module}\nProject Root: ${project_root}\nWorkspace: ${terraform_workspace}\nManaged by spacelift-automation Terraform root module."` | no |
296-
| <a name="input_destructor_enabled"></a> [destructor\_enabled](#input\_destructor\_enabled) | Flag to enable/disable the destructor for the Stack. | `bool` | `false` | no |
296+
| <a name="input_destructor_deactivated"></a> [destructor\_deactivated](#input\_destructor\_deactivated) | Whether to deactivate the stack destructor by default | `bool` | `true` | no |
297+
| <a name="input_destructor_enabled"></a> [destructor\_enabled](#input\_destructor\_enabled) | Whether to enable the stack destructor by default | `bool` | `true` | no |
297298
| <a name="input_drift_detection_enabled"></a> [drift\_detection\_enabled](#input\_drift\_detection\_enabled) | Flag to enable/disable Drift Detection configuration for a Stack. | `bool` | `false` | no |
298299
| <a name="input_drift_detection_ignore_state"></a> [drift\_detection\_ignore\_state](#input\_drift\_detection\_ignore\_state) | Controls whether drift detection should be performed on a stack<br/>in any final state instead of just 'Finished'. | `bool` | `false` | no |
299300
| <a name="input_drift_detection_reconcile"></a> [drift\_detection\_reconcile](#input\_drift\_detection\_reconcile) | Flag to enable/disable automatic reconciliation of drifts. | `bool` | `false` | no |

aqua.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
# - all
99
registries:
1010
- type: standard
11-
ref: v4.353.0 # renovate: depName=aquaproj/aqua-registry
11+
ref: v4.355.0 # renovate: depName=aquaproj/aqua-registry
1212
packages:
1313
- name: terraform-docs/terraform-docs@v0.20.0
1414
- name: hashicorp/terraform@v1.11.4
1515
tags: [terraform]
1616
- name: opentofu/opentofu@v1.9.1
1717
tags: [tofu]
18-
- name: spacelift-io/spacectl@v1.11.0

examples/complete/root-modules/network/stacks/dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ stack_settings:
33
description: Create the VPC + Subnets for the Dev environment
44
labels:
55
- dev_stack_specific_label
6+
destructor_enabled: true

main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ locals {
297297
for stack, config in local.stack_configs :
298298
stack => config if try(config.drift_detection_enabled, var.drift_detection_enabled)
299299
}
300+
301+
destructor_stacks = {
302+
for stack, config in local.stack_configs :
303+
stack => config if try(config.destructor_enabled, var.destructor_enabled)
304+
}
300305
}
301306

302307
check "spaces_enforce_mutual_exclusivity" {
@@ -383,10 +388,10 @@ resource "spacelift_stack" "default" {
383388
# Use the 'deactivated' attribute to disable the stack destructor functionality instead.
384389
# https://github.com/spacelift-io/terraform-provider-spacelift/blob/master/spacelift/resource_stack_destructor.go
385390
resource "spacelift_stack_destructor" "default" {
386-
for_each = local.stacks
391+
for_each = local.destructor_stacks
387392

388393
stack_id = spacelift_stack.default[each.key].id
389-
deactivated = !try(local.stack_configs[each.key].destructor_enabled, var.destructor_enabled)
394+
deactivated = try(local.stack_configs[each.key].destructor_deactivated, var.destructor_deactivated)
390395

391396
# `depends_on` should be used to make sure that all necessary resources (environment variables, roles, integrations, etc.)
392397
# are still in place when the destruction run is executed.

stack-config.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
"destructor_enabled": {
233233
"type": "boolean",
234234
"description": "Whether to enable the stack destructor"
235+
},
236+
"destructor_deactivated": {
237+
"type": "boolean",
238+
"description": "Whether to deactivate the stack destructor when enabled"
235239
}
236240
}
237241
}

0 commit comments

Comments
 (0)