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

CloudWatch log retention update for RDS … #250

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ output: ## terraform output (make output OUTPUT_ARGUMENT='--raw dns_dhcp_vpc_id'
apply: ## terraform apply
$(DOCKER_RUN) /bin/bash -c "terraform apply"
$(DOCKER_RUN) /bin/bash -c "./scripts/publish_terraform_outputs.sh"
$(DOCKER_RUN) /bin/bash -c "./scripts/cloudwatch_log_retention_policies.sh"

.PHONY: state-list
state-list: ## terraform state list
Expand Down
20 changes: 20 additions & 0 deletions scripts/cloudwatch_log_retention_policies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -e

# Check if the environment is "production"
if [[ $ENV != "production" ]]; then
echo "Script is intended for production environment only. Exiting."
exit 0
fi

# Filter for log groups containing "aws/rds/instance/" in the name
log_group_names=$(aws logs describe-log-groups | jq -r '.logGroups | .[] | select(.logGroupName | contains("aws/rds/instance/")) | .logGroupName')

retention_period=90

for log_group_name in $log_group_names
do
echo "setting log retention policy for $log_group_name to $retention_period"
aws logs put-retention-policy --log-group-name $log_group_name --retention-in-days $retention_period
done
4 changes: 4 additions & 0 deletions scripts/terraform_plan_or_apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ if [[ "${PLAN}" == "true" ]]; then
else
terraform apply --auto-approve -no-color
fi
# Run the cloud watch log retention script if in production and apply was successful
if [[ $ENV == "production" ]] && [[ $? -eq 0 ]]; then
bash ./scripts.cloudwatch_log_retention_policies.sh
fi
Loading