Skip to content

Commit f1adb12

Browse files
author
kfc-manager
committed
Initial commit
0 parents  commit f1adb12

File tree

12 files changed

+408
-0
lines changed

12 files changed

+408
-0
lines changed

.github/.secrets.baseline

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"version": "1.2.0",
3+
"plugins_used": [
4+
{
5+
"name": "ArtifactoryDetector"
6+
},
7+
{
8+
"name": "AWSKeyDetector"
9+
},
10+
{
11+
"name": "AzureStorageKeyDetector"
12+
},
13+
{
14+
"name": "Base64HighEntropyString",
15+
"limit": 4.5
16+
},
17+
{
18+
"name": "BasicAuthDetector"
19+
},
20+
{
21+
"name": "CloudantDetector"
22+
},
23+
{
24+
"name": "GitHubTokenDetector"
25+
},
26+
{
27+
"name": "HexHighEntropyString",
28+
"limit": 3.0
29+
},
30+
{
31+
"name": "IbmCloudIamDetector"
32+
},
33+
{
34+
"name": "IbmCosHmacDetector"
35+
},
36+
{
37+
"name": "JwtTokenDetector"
38+
},
39+
{
40+
"name": "KeywordDetector",
41+
"keyword_exclude": ""
42+
},
43+
{
44+
"name": "MailchimpDetector"
45+
},
46+
{
47+
"name": "NpmDetector"
48+
},
49+
{
50+
"name": "PrivateKeyDetector"
51+
},
52+
{
53+
"name": "SendGridDetector"
54+
},
55+
{
56+
"name": "SlackDetector"
57+
},
58+
{
59+
"name": "SoftlayerDetector"
60+
},
61+
{
62+
"name": "SquareOAuthDetector"
63+
},
64+
{
65+
"name": "StripeDetector"
66+
},
67+
{
68+
"name": "TwilioKeyDetector"
69+
}
70+
],
71+
"filters_used": [
72+
{
73+
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
74+
},
75+
{
76+
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
77+
"min_level": 2
78+
},
79+
{
80+
"path": "detect_secrets.filters.gibberish.should_exclude_secret",
81+
"limit": 3.7
82+
},
83+
{
84+
"path": "detect_secrets.filters.heuristic.is_indirect_reference"
85+
},
86+
{
87+
"path": "detect_secrets.filters.heuristic.is_likely_id_string"
88+
},
89+
{
90+
"path": "detect_secrets.filters.heuristic.is_lock_file"
91+
},
92+
{
93+
"path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string"
94+
},
95+
{
96+
"path": "detect_secrets.filters.heuristic.is_potential_uuid"
97+
},
98+
{
99+
"path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign"
100+
},
101+
{
102+
"path": "detect_secrets.filters.heuristic.is_sequential_string"
103+
},
104+
{
105+
"path": "detect_secrets.filters.heuristic.is_swagger_file"
106+
},
107+
{
108+
"path": "detect_secrets.filters.heuristic.is_templated_secret"
109+
}
110+
],
111+
"results": {},
112+
"generated_at": "2024-02-17T17:33:52Z"
113+
}

.github/hooks/pre-commit

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# Run terraform fmt on all .tf files in the repository
4+
terraform_files=$(git diff --cached --name-only --diff-filter=ACMRTUXB | grep -E '\.tf$|\.tftest.hcl$')
5+
if [ -n "$terraform_files" ]; then
6+
echo "Formatting Terraform files..."
7+
terraform fmt -write=true $terraform_files
8+
git add $terraform_files
9+
fi
10+
11+
exit 0

.github/workflows/lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout source code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup TFLint
16+
uses: terraform-linters/setup-tflint@v3
17+
with:
18+
tflint_version: v0.44.1
19+
20+
- name: Show TFLint version
21+
run: tflint --version
22+
23+
- name: Init TFLint
24+
run: tflint --init
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}
27+
28+
- name: Run TFLint
29+
run: tflint -f compact

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Test"]
6+
types: [completed]
7+
branches: ["main"]
8+
9+
permissions:
10+
contents: write
11+
pull-requests: read
12+
13+
jobs:
14+
release:
15+
runs-on: "ubuntu-latest"
16+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
17+
18+
steps:
19+
- uses: rymndhng/release-on-push-action@master
20+
with:
21+
bump_version_scheme: minor
22+
tag_prefix: v
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/secrets-scan.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Secrets Scan
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
7+
jobs:
8+
scan:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout source code
13+
uses: actions/checkout@v4
14+
15+
- name: Move .secrets.baseline file
16+
run: mv .github/.secrets.baseline .
17+
18+
- name: Scan for secrets
19+
uses: secret-scanner/action@0.0.2

.github/workflows/test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout source code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Terraform
16+
uses: hashicorp/setup-terraform@v3
17+
with:
18+
terraform_version: latest
19+
20+
- name: Init Terraform
21+
run: terraform init
22+
23+
- name: Run Terraform Test
24+
run: terraform test
25+
env:
26+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Editor directories and files
2+
.vscode/*
3+
!.vscode/extensions.json
4+
.idea
5+
.DS_Store
6+
*.suo
7+
*.ntvs*
8+
*.njsproj
9+
*.sln
10+
*.sw?
11+
12+
# Terraform files
13+
**/.terraform/*
14+
*.tfstate
15+
*.tfstate.*
16+
crash.log
17+
crash.*.log
18+
.terraform.lock.hcl
19+
*.tfvars
20+
*.tfvars.json
21+
override.tf
22+
override.tf.json
23+
*_override.tf
24+
*_override.tf.json
25+
*tfplan*
26+
.terraformrc
27+
terraform.rc

main.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
################################
2+
# SQS Queue #
3+
################################
4+
5+
resource "aws_sqs_queue" "deadletter" {
6+
count = var.max_receive_count > 0 ? 1 : 0
7+
name = "${var.identifier}-deadletter"
8+
9+
tags = var.tags
10+
}
11+
12+
resource "aws_sqs_queue" "main" {
13+
name = var.identifier
14+
message_retention_seconds = var.message_retention_seconds
15+
visibility_timeout_seconds = var.visibility_timeout_seconds
16+
17+
redrive_policy = var.max_receive_count > 0 ? jsonencode({
18+
deadLetterTargetArn = aws_sqs_queue.deadletter[0].arn
19+
maxReceiveCount = var.max_receive_count
20+
}) : null
21+
22+
tags = var.tags
23+
}
24+
25+
resource "aws_sqs_queue_redrive_allow_policy" "main" {
26+
count = var.max_receive_count > 0 ? 1 : 0
27+
queue_url = aws_sqs_queue.deadletter[0].id
28+
29+
redrive_allow_policy = jsonencode({
30+
redrivePermission = "byQueue",
31+
sourceQueueArns = [aws_sqs_queue.main.arn]
32+
})
33+
}

outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "arn" {
2+
description = "The ARN of the SQS queue."
3+
value = try(aws_sqs_queue.main.arn, null)
4+
}
5+
6+
output "url" {
7+
description = "The URL of the SQS queue."
8+
value = try(aws_sqs_queue.main.url, null)
9+
}
10+
11+
output "deadletter_arn" {
12+
description = "The ARN of the deadletter SQS queue of the main queue."
13+
value = try(aws_sqs_queue.deadletter[0].url, null)
14+
}
15+
16+
output "deadletter_url" {
17+
description = "The URL of the deadletter SQS queue of the main queue."
18+
value = try(aws_sqs_queue.deadletter[0].url, null)
19+
}

tests/queue.tftest.hcl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
provider "aws" {
2+
region = "eu-central-1"
3+
default_tags {
4+
tags = {
5+
Environment = "Test"
6+
}
7+
}
8+
}
9+
10+
run "invalid_identifier" {
11+
command = plan
12+
13+
variables {
14+
identifier = "ab"
15+
}
16+
17+
expect_failures = [var.identifier]
18+
}
19+
20+
run "valid_identifier" {
21+
command = plan
22+
23+
variables {
24+
identifier = "abc"
25+
}
26+
}
27+
28+
run "with_deadletter" {
29+
command = plan
30+
31+
variables {
32+
identifier = "abc"
33+
max_receive_count = 4
34+
}
35+
36+
assert {
37+
condition = length(aws_sqs_queue.deadletter) == 1
38+
error_message = "Deadletter queue was not created"
39+
}
40+
41+
assert {
42+
condition = length(aws_sqs_queue_redrive_allow_policy.main) == 1
43+
error_message = "Redrive allow policy was not created"
44+
}
45+
}
46+
47+
run "without_deadletter" {
48+
command = plan
49+
50+
variables {
51+
identifier = "abc"
52+
max_receive_count = 0
53+
}
54+
55+
assert {
56+
condition = length(aws_sqs_queue.deadletter) == 0
57+
error_message = "Deadletter queue was created unexpectedly"
58+
}
59+
60+
assert {
61+
condition = length(aws_sqs_queue_redrive_allow_policy.main) == 0
62+
error_message = "Redrive allow policy was created unexpectedly"
63+
}
64+
}

0 commit comments

Comments
 (0)