Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(modules): implement first tests of this repo #30

Merged
merged 93 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
df796bf
init tests
leiicamundi Mar 26, 2024
d98bc49
continue tests
leiicamundi Mar 26, 2024
af7cbb8
update tests
leiicamundi Mar 27, 2024
6c1ce08
update to aws sdk, refactoring tests
leiicamundi Mar 28, 2024
34cf10e
extract cluster
leiicamundi Mar 28, 2024
9c809d8
wip tests
leiicamundi Mar 29, 2024
c2fdef1
add k8s cluster config todo
leiicamundi Mar 29, 2024
d807dce
implement rds test
leiicamundi Mar 29, 2024
791280d
wip tests eks rds
leiicamundi Apr 3, 2024
7eae057
fix string
leiicamundi Apr 3, 2024
43c60a0
completed aurora db test
leiicamundi Apr 4, 2024
a59b206
wip upgrade tests
leiicamundi Apr 4, 2024
d791041
WIP tests
leiicamundi Apr 4, 2024
0255998
refacto tests in TestSuites to be reviewed
leiicamundi Apr 8, 2024
f612454
refactor tests to be run in parallel
leiicamundi Apr 9, 2024
254e385
enable parallel and reduce nb nodes
leiicamundi Apr 10, 2024
146dc18
improve CI and fix rds
leiicamundi Apr 10, 2024
5f10d55
fix pre-commit
leiicamundi Apr 10, 2024
b9a18c4
fix some tests
leiicamundi Apr 10, 2024
6d01a09
fix wrong paths for rds
leiicamundi Apr 10, 2024
f1d9b2c
setup go
leiicamundi Apr 10, 2024
18cb1e1
fix path
leiicamundi Apr 10, 2024
9209dbe
add DEVELOPER.md and MAINTENANCE.md
leiicamundi Apr 10, 2024
a7f2e92
add cloud cleanup
leiicamundi Apr 10, 2024
fae5e6e
fix tests, update workflows
leiicamundi Apr 10, 2024
14ab3c7
add labels logic
leiicamundi Apr 10, 2024
9b21b33
fix
leiicamundi Apr 10, 2024
4bfa840
fix
leiicamundi Apr 10, 2024
e14ceb7
fix check labels
leiicamundi Apr 10, 2024
ff8213c
update checks
leiicamundi Apr 10, 2024
107870a
fix conditions
leiicamundi Apr 10, 2024
20a0bf3
fix
leiicamundi Apr 10, 2024
59d3bb9
fix
leiicamundi Apr 10, 2024
50cc17a
reapply after upgrade
leiicamundi Apr 10, 2024
294d42a
dummy commit
leiicamundi Apr 10, 2024
5b8c0ab
improve go tests summary
leiicamundi Apr 10, 2024
28c2f3c
fix tests ci
leiicamundi Apr 10, 2024
25dcb6a
fix path
leiicamundi Apr 10, 2024
47e8bd9
update report (may fail)
leiicamundi Apr 10, 2024
9ce7ebc
fix typo
leiicamundi Apr 11, 2024
7c4cc68
ping gh actions
leiicamundi Apr 11, 2024
c76f27d
only run tests if necessary
leiicamundi Apr 11, 2024
3ddf0a9
improve tests condition
leiicamundi Apr 12, 2024
25d0cc0
rename file
leiicamundi Apr 12, 2024
6257243
dynamic increase version
leiicamundi Apr 12, 2024
81fd65e
auto port selection
leiicamundi Apr 12, 2024
e151eb4
remove toml
leiicamundi Apr 12, 2024
418aa6c
use latest runs-on
leiicamundi Apr 12, 2024
aa37e00
implement just, update tests doc
leiicamundi Apr 12, 2024
ad8c962
document dummy commit
leiicamundi Apr 12, 2024
43cabc5
pin action
leiicamundi Apr 12, 2024
750c31b
update labeler
leiicamundi Apr 15, 2024
e82b895
fix region
leiicamundi Apr 15, 2024
be37984
add tests in parallel
leiicamundi Apr 15, 2024
44f0573
fix report
leiicamundi Apr 15, 2024
b9d6350
trigger workflow
leiicamundi Apr 15, 2024
ca3660f
skip tests can be empty
leiicamundi Apr 15, 2024
f7d096b
debug
leiicamundi Apr 15, 2024
1b65994
fix
leiicamundi Apr 15, 2024
4e9aeca
json format
leiicamundi Apr 15, 2024
94702bc
fix secret
leiicamundi Apr 15, 2024
e21a399
update test report
leiicamundi Apr 15, 2024
ce7e830
debug tests
leiicamundi Apr 15, 2024
59ecc22
debug tests
leiicamundi Apr 15, 2024
7f06dc3
improve tests debug status
leiicamundi Apr 15, 2024
2df9a8f
make kms optional and fix rds zones
leiicamundi Apr 15, 2024
8afcf06
pin actions
leiicamundi Apr 15, 2024
d1846c7
add license, fix skip
leiicamundi Apr 15, 2024
9963b57
implement custom tf binary
leiicamundi Apr 15, 2024
281b81f
fix skip
leiicamundi Apr 15, 2024
fd9e2dc
fix skip
leiicamundi Apr 15, 2024
5d22e60
fix skip
leiicamundi Apr 15, 2024
ec0dfc9
fix skip
leiicamundi Apr 15, 2024
1341a99
fix skip
leiicamundi Apr 15, 2024
2bafa73
trigger workflow
leiicamundi Apr 15, 2024
87752ea
fix cleanup aws region
leiicamundi Apr 15, 2024
e50341f
implement skip-test strategy
leiicamundi Apr 16, 2024
40e2a5e
implement skip-test strategy
leiicamundi Apr 16, 2024
3eea7ca
fix retention days
leiicamundi Apr 16, 2024
df9f3f0
update doc
leiicamundi Apr 16, 2024
4313047
trigger workflow
leiicamundi Apr 16, 2024
188874a
group all renovate in a single group, disable automerge
leiicamundi Apr 16, 2024
70b978d
replace labeling ci with path trigger
leiicamundi Apr 16, 2024
3b7a09b
re-enable kms check
leiicamundi Apr 16, 2024
a0d429a
re-enable kms check
leiicamundi Apr 16, 2024
d2d018d
fix tests
leiicamundi Apr 16, 2024
873f6bc
fix tests
leiicamundi Apr 16, 2024
ceaf0b7
fix tests kms with pagination
leiicamundi Apr 16, 2024
8276f7a
re-enable automerge of renovate
leiicamundi Apr 17, 2024
3a5060f
extend renovation
leiicamundi Apr 17, 2024
907230a
switch back from tofu to terraform by default globally
leiicamundi Apr 17, 2024
dd2b105
sort tool-versions and associated pre-commit-hook
leiicamundi Apr 19, 2024
267a8dc
replace the autosort by a comment
leiicamundi Apr 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/labeler.yml
@@ -0,0 +1,17 @@
# Add 'feature' label to any PR where the head branch name starts with `feature` or has a `feature` section in the name
feature:
- head-branch: ['^feature', 'feature']

# Add 'test' label to any changes within 'test' folder or any subfolders
test:
- changed-files:
- any-glob-to-any-file:
- test/**.go
- test/**/go.mod
- modules/fixtures/**

terraform:
- changed-files:
- any-glob-to-any-file:
- modules/**.tf
- .tool-versions
20 changes: 20 additions & 0 deletions .github/markdown-links.json
@@ -0,0 +1,20 @@
{
"projectBaseUrl":"${workspaceFolder}",
"ignorePatterns": [
{
"pattern": "^http(s?)://localhost"
},
{
"pattern": "^#"
}
],
"replacementPatterns": [
],
"httpHeaders": [
],
"timeout": "20s",
"retryOn429": true,
"retryCount": 5,
"fallbackRetryDelay": "30s",
"aliveStatusCodes": [200, 206]
}
42 changes: 32 additions & 10 deletions .github/renovate.json5
Expand Up @@ -8,6 +8,7 @@
":enablePreCommit",
],
schedule: ["every weekend"],
groupName: "mono-update-renovate", // we keep all updates in a single renovate branch in order to save CI tests
platformAutomerge: false,
prHourlyLimit: 6,
prConcurrentLimit: 20,
Expand All @@ -31,8 +32,24 @@
},
vulnerabilityAlerts: {
addLabels: ["security"],
enabled: true
enabled: true,
},
customManagers: [
{
"customType": "regex",
"fileMatch": ["^.tool-versions$"],
"matchStrings": [
"datasource=(?<datasource>.*?) depName=(?<depName>.*?)( versioning=(?<versioning>.*?))?( extractVersion=(?<extractVersion>.*?))?\\s.*? (?<currentValue>.*)\\s"
],
},
{
"customType": "regex",
"fileMatch": ["^justfile$"],
"matchStrings": [
"datasource=(?<datasource>.*?) depName=(?<depName>.*?)( versioning=(?<versioning>.*?))?( extractVersion=(?<extractVersion>.*?))?\\s(?<originalPackageName>.*) := \"(?<currentValue>.*?)\"\\s"
],
},
],
packageRules: [
// limit the PR creation for the Renovate pre-commit hook (it's released very frequently)
{
Expand All @@ -52,8 +69,9 @@
{
matchDatasources: ["terraform-module"],
matchPackagePatterns: ["terraform-aws-modules.*"],
addLabels: ["group:terraform"],
groupName: "Terraform AWS modules",
addLabels: ["group:terraform", "automerge"],
automerge: true,
groupName: "mono-update-renovate-automerge",
schedule: [
"every 2 weeks on Saturday and Sunday",
],
Expand All @@ -63,15 +81,15 @@
matchDatasources: ["terraform-provider"],
addLabels: ["group:terraform"],
schedule: [
"every 2 weeks on Saturday and Sunday",
]
"every 2 weeks on Saturday and Sunday"
],
},
// Terraform patch provider updates
{
matchUpdateTypes: ["patch"],
matchDatasources: ["terraform-provider"],
addLabels: ["group:terraform", "automerge"],
groupName: "Terraform providers",
groupName: "mono-update-renovate-automerge",
automerge: true,
schedule: [
"every 2 weeks on Saturday and Sunday",
Expand All @@ -82,6 +100,7 @@
matchUpdateTypes: ["minor", "patch"],
matchManagers: ["github-actions"],
addLabels: ["automerge"],
groupName: "mono-update-renovate-automerge",
automerge: true,
},
// Patches
Expand All @@ -98,6 +117,7 @@
"terraform-linters/tflint",
],
addLabels: ["automerge"],
groupName: "mono-update-renovate-automerge",
automerge: true,
},
// Minor versions
Expand All @@ -111,6 +131,7 @@
"terraform-linters/tflint",
],
addLabels: ["automerge"],
groupName: "mono-update-renovate-automerge",
automerge: true,
},
// Create PRs and automerge mentioned components afterward
Expand All @@ -121,25 +142,26 @@
"pre-commit/.+",
],
addLabels: ["automerge"],
groupName: "mono-update-renovate-automerge",
automerge: true,
},
{
matchUpdateTypes: ["major", "minor", "patch"],
matchManagers: ["pre-commit"],
groupName: "pre-commit hooks",
groupName: "mono-update-renovate-automerge",
addLabels: ["automerge"],
automerge: true
},
// For known GitHub repositories that use GitHub tags/releases of format
// "v1.2.3" and where the asdf plugin ignores the "v" prefix, we also tell
// Renovate to ignore it via extractVersion when updating .tool-version file
{
matchFileNames: ["**/.tool-versions", "**/*.tf"],
matchFileNames: ["**/*.tf"],
matchPackageNames: [
"hashicorp/terraform",
"pre-commit/pre-commit",
],
extractVersion: "^v(?<version>.*)$",
},
],
}
]
}
13 changes: 13 additions & 0 deletions .github/workflows/labeler.yml
@@ -0,0 +1,13 @@
name: "Pull Request Labeler"
on:
pull_request_target:
schedule:
maxdanilov marked this conversation as resolved.
Show resolved Hide resolved
- cron: "0 1 * * 1"
jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,19 @@
---
# desc: lint sanity check
name: lint

on:
push:
workflow_dispatch:


jobs:
lint:
name: pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Install tooling using asdf
uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 # v3

- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
79 changes: 79 additions & 0 deletions .github/workflows/nightly_cleanup.yml
@@ -0,0 +1,79 @@
---
name: Nightly Cleanup

on:
schedule:
- cron: '0 5 * * *'
workflow_dispatch:


env:
AWS_PROFILE: "infex"
# remember to also update tests.yml!
AWS_REGION: "eu-west-2"
CLEANUP_NEWER_THAN: "6 hours"
CLOUD_NUKE_VERSION: "v0.35.0"

jobs:
aws-nightly-cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Import Secrets
id: secrets
uses: hashicorp/vault-action@d1720f055e0635fd932a1d2a48f87a666a57906c # v3
with:
url: ${{ secrets.VAULT_ADDR }}
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
exportEnv: false
secrets: |
secret/data/products/infrastructure-experience/ci/common AWS_ACCESS_KEY;
secret/data/products/infrastructure-experience/ci/common AWS_SECRET_KEY;

# Official action does not support profiles
leiicamundi marked this conversation as resolved.
Show resolved Hide resolved
- name: Add profile credentials to ~/.aws/credentials
run: |
aws configure set aws_access_key_id ${{ steps.secrets.outputs.AWS_ACCESS_KEY }} --profile ${{ env.AWS_PROFILE }}
aws configure set aws_secret_access_key ${{ steps.secrets.outputs.AWS_SECRET_KEY }} --profile ${{ env.AWS_PROFILE }}
aws configure set region ${{ env.AWS_REGION }} --profile ${{ env.AWS_PROFILE }}

- name: Install Cloud Nuke
run: |
wget https://github.com/gruntwork-io/cloud-nuke/releases/download/${{ env.CLOUD_NUKE_VERSION }}/cloud-nuke_linux_amd64
chmod +x cloud-nuke_linux_amd64

# This is likely to fail, therefore we ignore the error
# We're ignoring ec2_dhcp_option as they couldn't be deleted
# cloudtrail is managed by IT and can't be deleted either
- name: Run Cloud Nuke
timeout-minutes: 45
env:
DISABLE_TELEMETRY: "true"
run: |
./cloud-nuke_linux_amd64 aws \
--region ${{ env.AWS_REGION }} \
--force \
--newer-than ${{ env.CLEANUP_NEWER_THAN }} \
--exclude-resource-type ec2_dhcp_option \
--exclude-resource-type cloudtrail || true

# Following will delete global resources and things that cloud-nuke does not support
- name: Delete additional AWS resources
timeout-minutes: 15
run: .github/workflows/scripts/aws_cleanup.sh "${{ env.AWS_REGION }}"

# The second run should remove the remaining resources (VPCs) and fail if there's anything left
- name: Run Cloud Nuke
timeout-minutes: 45
env:
DISABLE_TELEMETRY: "true"
run: |
./cloud-nuke_linux_amd64 aws \
--region ${{ env.AWS_REGION }} \
--force \
--newer-than ${{ env.CLEANUP_NEWER_THAN }} \
--exclude-resource-type ec2_dhcp_option \
--exclude-resource-type cloudtrail
94 changes: 94 additions & 0 deletions .github/workflows/scripts/aws_cleanup.sh
@@ -0,0 +1,94 @@
#!/bin/bash

# This script deletes additional AWS resources based on specified criteria.

# Check if the region argument is provided
if [ -z "$1" ]; then
echo "Please provide the AWS region as the first argument."
exit 1
fi

region="$1"

echo "Deleting additional resources in the $region region..."


echo "Deleting additional resources..."
# KMS keys can't be deleted due to resource policies, requires manual intervention

echo "Deleting IAM Roles"
# Detach permissions and profile instances and delete IAM roles
role_arns=$(aws iam list-roles --query "Roles[?contains(RoleName, 'nightly')].RoleName" --output text)

read -r -a role_arns_array <<< "$role_arns"

for role_arn in "${role_arns_array[@]}"
do
echo "Removing instance profiles and policies of role: $role_arn"
attached_policy_arns=$(aws iam list-attached-role-policies --role-name "$role_arn" --query 'AttachedPolicies[].PolicyArn' --output text)
read -r -a attached_policy_arns_array <<< "$attached_policy_arns"

for policy_arn in "${attached_policy_arns_array[@]}"
do
echo "Removing attached policy: $policy_arn"
aws iam detach-role-policy --role-name "$role_arn" --policy-arn "$policy_arn"
done

policy_arns=$(aws iam list-role-policies --role-name "$role_arn" --query 'PolicyNames' --output text)
read -r -a policy_arns_array <<< "$policy_arns"

for policy_arn in "${policy_arns_array[@]}"
do
echo "Deleting policy: $policy_arn"
aws iam delete-role-policy --role-name "$role_arn" --policy-name "$policy_arn"
done

instance_profile_arns=$(aws iam list-instance-profiles-for-role --role-name "$role_arn" --query 'InstanceProfiles[].InstanceProfileName' --output text)
read -r -a instance_profile_arns_array <<< "$instance_profile_arns"

for instance_profile_arn in "${instance_profile_arns_array[@]}"
do
echo "Removing instance profile: $instance_profile_arn"
aws iam remove-role-from-instance-profile --instance-profile-name "$instance_profile_arn" --role-name "$role_arn"
done

echo "Deleting role: $role_arn"
aws iam delete-role --role-name "$role_arn"

done

echo "Deleting IAM Policies"
# Delete Policies
iam_policies=$(aws iam list-policies --query "Policies[?contains(PolicyName, 'nightly')].Arn" --output text)

read -r -a iam_policies_array <<< "$iam_policies"

for iam_policy in "${iam_policies_array[@]}"
do
echo "Deleting policy: $iam_policy"
aws iam delete-policy --policy-arn "$iam_policy"
done

echo "Deleting OIDC Providers"
# Delete OIDC Provider
oidc_providers=$(aws iam list-open-id-connect-providers --query "OpenIDConnectProviderList[?contains(Arn, 'eu-west-2') || contains(Arn, 'eu-west-3')].Arn" --output text)

read -r -a oidc_providers_array <<< "$oidc_providers"

for oidc_provider in "${oidc_providers_array[@]}"
do
echo "Deleting OIDC Provider: $oidc_provider"
aws iam delete-open-id-connect-provider --open-id-connect-provider-arn "$oidc_provider"
done

echo "Deleting VPC Peering Connections"
# Delete VPC Peering Connection
peering_connection_ids=$(aws ec2 describe-vpc-peering-connections --region "$region" --query "VpcPeeringConnections[?Status.Code == 'active' && Tags[?contains(Value, 'nightly')]]".VpcPeeringConnectionId --output text)

read -r -a peering_connection_ids_array <<< "$peering_connection_ids"

for peering_connection_id in "${peering_connection_ids_array[@]}"
do
echo "Deleting VPC Peering Connection: $peering_connection_id"
aws ec2 delete-vpc-peering-connection --region "$region" --vpc-peering-connection-id "$peering_connection_id"
done