Skip to content

Commit 5fb4c54

Browse files
add pre-commit + workflow (#82)
* add workflow * add pre-commit config * fix typo
1 parent c2cdd1b commit 5fb4c54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+354
-302
lines changed

.github/git-chglog/CHANGELOG.tpl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Reverts
1313
{{- if .NoteGroups -}} {{ range .NoteGroups -}}
1414

1515
{{ .Title }}
16-
{{ range .Notes }} {{ .Body }} {{ end }} {{ end -}} {{ end -}} {{ end -}}
16+
{{ range .Notes }} {{ .Body }} {{ end }} {{ end -}} {{ end -}} {{ end -}}

.github/git-chglog/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ options:
2323
- Subject
2424
notes:
2525
keywords:
26-
- BREAKING CHANGE
26+
- BREAKING CHANGE

.github/workflows/ci-pull-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
run: |
5252
go install github.com/onsi/ginkgo/ginkgo@latest
5353
- name: Test
54-
run: make test
54+
run: make test
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Pre-commit Check
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Get changed files
14+
uses: tj-actions/changed-files@v41
15+
id: changed-files
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.x'
21+
22+
- name: Set up Terraform
23+
uses: hashicorp/setup-terraform@v3
24+
with:
25+
terraform_version: latest
26+
27+
- name: Install pre-commit
28+
run: pip install pre-commit
29+
30+
- name: Run pre-commit on changed files
31+
run: |
32+
pre-commit run --files ${{ steps.changed-files.outputs.all_changed_files }} --hook-stage push

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ crash.log
3131
.envrc
3232
.direnv
3333
.DS_Store
34-
.idea/
34+
.idea/

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: terraform_clean
5+
name: "Terraform Cleanup"
6+
pass_filenames: false
7+
language: system
8+
entry: bash -c "find . \( -iname ".terraform*" ! -iname ".terraform-docs*" ! -path "*/test/*" \) -print0 | xargs -0 rm -r; true"
9+
- repo: https://github.com/antonbabenko/pre-commit-terraform
10+
rev: v1.88.4
11+
hooks:
12+
- id: terraform_fmt
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v4.5.0
15+
hooks:
16+
- id: trailing-whitespace
17+
- id: end-of-file-fixer
18+
- id: check-yaml
19+
- id: check-added-large-files
20+
- id: check-merge-conflict
21+
- id: no-commit-to-branch
22+
args: [--branch, main, --pattern, ".*/.*"]

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ It's recommended to use an .envrc file to keep environment variables under contr
3131

3232
## Release
3333

34-
- push a new tag and the Github Action will draft a release (with notes)
34+
- push a new tag and the Github Action will draft a release (with notes)

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,4 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ clean:
2727

2828
.PHONY: test
2929
test:
30-
$(MAKE) -C test test
30+
$(MAKE) -C test test

modules/agentless-scanning/locals.tf

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ data "aws_organizations_organization" "org" {
99
locals {
1010
# check if both old and new org parameters are provided, we fail early
1111
both_org_configuration_params = var.is_organizational && length(var.org_units) > 0 && (
12-
length(var.include_ouids) > 0 ||
13-
length(var.exclude_ouids) > 0 ||
14-
length(var.include_accounts) > 0 ||
15-
length(var.exclude_accounts) > 0
12+
length(var.include_ouids) > 0 ||
13+
length(var.exclude_ouids) > 0 ||
14+
length(var.include_accounts) > 0 ||
15+
length(var.exclude_accounts) > 0
1616
)
1717

1818
# check if old org_units parameter is provided, for backwards compatibility we will always give preference to it
@@ -25,14 +25,14 @@ locals {
2525

2626
check "validate_org_configuration_params" {
2727
assert {
28-
condition = length(var.org_units) == 0 # if this condition is false we throw warning
28+
condition = length(var.org_units) == 0 # if this condition is false we throw warning
2929
error_message = <<-EOT
3030
WARNING: TO BE DEPRECATED 'org_units' on 30th November, 2025. Please work with Sysdig to migrate your Terraform installs to use 'include_ouids' instead.
3131
EOT
3232
}
3333

3434
assert {
35-
condition = !local.both_org_configuration_params # if this condition is false we throw error
35+
condition = !local.both_org_configuration_params # if this condition is false we throw error
3636
error_message = <<-EOT
3737
ERROR: If both org_units and include_ouids/exclude_ouids/include_accounts/exclude_accounts variables are populated,
3838
ONLY org_units will be considered. Please use only one of the two methods.
@@ -70,19 +70,19 @@ locals {
7070
# case1 - if old method is used where ONLY org_units is provided, use those
7171
local.check_old_ouid_param ? (
7272
"old_ouid_param"
73-
) : (
73+
) : (
7474
# case2 - if no include/exclude ous provided, include entire org
7575
var.is_organizational && length(var.include_ouids) == 0 && length(var.exclude_ouids) == 0 ? (
7676
"entire_org"
77-
) : (
77+
) : (
7878
# case3 - if only included ouids provided, include those ous only
7979
var.is_organizational && length(var.include_ouids) > 0 && length(var.exclude_ouids) == 0 ? (
8080
"included_ous_only"
81-
) : (
81+
) : (
8282
# case4 - if only excluded ouids provided, exclude their accounts from rest of org
8383
var.is_organizational && length(var.include_ouids) == 0 && length(var.exclude_ouids) > 0 ? (
8484
"excluded_ous_only"
85-
) : (
85+
) : (
8686
# case5 - if both include and exclude ouids are provided, includes override excludes
8787
var.is_organizational && length(var.include_ouids) > 0 && length(var.exclude_ouids) > 0 ? (
8888
"mixed_ous"
@@ -99,7 +99,7 @@ locals {
9999
org_units_to_deploy = var.org_units
100100
}
101101
entire_org = {
102-
org_units_to_deploy = local.root_org_unit
102+
org_units_to_deploy = local.root_org_unit
103103
}
104104
included_ous_only = {
105105
org_units_to_deploy = var.include_ouids
@@ -140,15 +140,15 @@ locals {
140140
# case1 - if old method is used where ONLY org_units is provided, this configuration is a noop
141141
local.check_old_ouid_param ? (
142142
"NONE"
143-
) : (
143+
) : (
144144
# case2 - if only included accounts provided, include those accts as well
145145
var.is_organizational && length(var.include_accounts) > 0 && length(var.exclude_accounts) == 0 ? (
146146
"UNION"
147-
) : (
147+
) : (
148148
# case3 - if only excluded accounts or only excluded ouids provided, exclude those accounts
149-
var.is_organizational && length(var.include_accounts) == 0 && ( length(var.exclude_accounts) > 0 || local.org_configuration == "excluded_ous_only" ) ? (
149+
var.is_organizational && length(var.include_accounts) == 0 && (length(var.exclude_accounts) > 0 || local.org_configuration == "excluded_ous_only") ? (
150150
"DIFFERENCE"
151-
) : (
151+
) : (
152152
# case4 - if both include and exclude accounts are provided, includes override excludes
153153
var.is_organizational && length(var.include_accounts) > 0 && length(var.exclude_accounts) > 0 ? (
154154
"MIXED"
@@ -158,30 +158,30 @@ locals {
158158
)
159159
)
160160

161-
ou_accounts_to_exclude = flatten([ for ou_accounts in data.aws_organizations_organizational_unit_descendant_accounts.ou_accounts_to_exclude: [ ou_accounts.accounts[*].id ] ])
162-
accounts_to_exclude = setunion(local.ou_accounts_to_exclude, var.exclude_accounts)
161+
ou_accounts_to_exclude = flatten([for ou_accounts in data.aws_organizations_organizational_unit_descendant_accounts.ou_accounts_to_exclude : [ou_accounts.accounts[*].id]])
162+
accounts_to_exclude = setunion(local.ou_accounts_to_exclude, var.exclude_accounts)
163163

164164
# switch cases for various user provided accounts configuration to be onboarded
165165
deployment_account_options = {
166166
NONE = {
167-
accounts_to_deploy = []
167+
accounts_to_deploy = []
168168
account_filter_type = "NONE"
169169
}
170170
UNION = {
171-
accounts_to_deploy = var.include_accounts
171+
accounts_to_deploy = var.include_accounts
172172
account_filter_type = "UNION"
173173
}
174174
DIFFERENCE = {
175-
accounts_to_deploy = local.accounts_to_exclude
175+
accounts_to_deploy = local.accounts_to_exclude
176176
account_filter_type = "DIFFERENCE"
177177
}
178178
MIXED = {
179-
accounts_to_deploy = var.include_accounts
179+
accounts_to_deploy = var.include_accounts
180180
account_filter_type = "UNION"
181181
}
182182
default = {
183183
# default when neither of include/exclude accounts are provided
184-
accounts_to_deploy = []
184+
accounts_to_deploy = []
185185
account_filter_type = "NONE"
186186
}
187187
}
@@ -198,6 +198,6 @@ locals {
198198
# XXX: due to AWS bug of not having UNION filter fully working, there is no way to add those extra accounts requested.
199199
# to not miss out on those extra accounts, deploy the cloud resources across entire org and noop the UNION filter.
200200
# i.e till we can't deploy UNION, we deploy it all
201-
deployment_targets_org_units = local.deployment_targets_accounts.account_filter_type == "UNION" ? local.root_org_unit : local.deployment_targets_ous.org_units_to_deploy
201+
deployment_targets_org_units = local.deployment_targets_accounts.account_filter_type == "UNION" ? local.root_org_unit : local.deployment_targets_ous.org_units_to_deploy
202202
deployment_targets_accounts_filter = local.deployment_targets_accounts.account_filter_type == "UNION" ? "NONE" : local.deployment_targets_accounts.account_filter_type
203-
}
203+
}

0 commit comments

Comments
 (0)