Skip to content

Commit 401384c

Browse files
committed
Flushes the kinesis stream to s3 before deleting resources
1 parent b2fc3ee commit 401384c

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

.github/actions/test/action.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,45 @@ runs:
6767
fi
6868
echo "ARTIFACT_LOCATION=${ARTIFACT_LOCATION}"
6969
70+
# Flush Firehose streams so all data is written to S3
71+
FIREHOSE_STREAMS=$(terraform output -json firehose_delivery_stream_names 2>/dev/null | jq -r '.[] // empty' || true)
72+
73+
if [ -n "$FIREHOSE_STREAMS" ]; then
74+
echo "Flushing Firehose streams..."
75+
76+
for stream_name in $FIREHOSE_STREAMS; do
77+
echo "Reducing buffering interval for stream: $stream_name"
78+
79+
# Get current delivery stream config and version
80+
STREAM_DESC=$(aws firehose describe-delivery-stream --delivery-stream-name "$stream_name" 2>/dev/null || true)
81+
82+
if [ -n "$STREAM_DESC" ]; then
83+
VERSION_ID=$(echo "$STREAM_DESC" | jq -r '.DeliveryStreamDescription.VersionId')
84+
DEST_ID=$(echo "$STREAM_DESC" | jq -r '.DeliveryStreamDescription.Destinations[0].DestinationId')
85+
86+
# Update with reduced time interval (60s) to flush quickly while keeping max size (128 MiB)
87+
# Since destination type is not changing, only BufferingHints need to be specified; other config is merged
88+
aws firehose update-destination \
89+
--delivery-stream-name "$stream_name" \
90+
--current-delivery-stream-version-id "$VERSION_ID" \
91+
--destination-id "$DEST_ID" \
92+
--extended-s3-destination-update '{
93+
"BufferingHints": {
94+
"SizeInMBs": 128,
95+
"IntervalInSeconds": 60
96+
}
97+
}' 2>/dev/null || echo "Warning: Could not update stream $stream_name"
98+
fi
99+
done
100+
101+
echo "Waiting 60 seconds for Firehose to flush buffered data..."
102+
for i in 60 50 40 30 20 10; do
103+
echo " $i seconds remaining..."
104+
sleep 10
105+
done
106+
echo " Flush complete."
107+
fi
108+
70109
if [ "${TF_DESTROY_AFTER_TEST}" = "true" ]; then
71110
# destroy resources
72111
terraform destroy -no-color -input=false -auto-approve

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,19 @@ aws_instance.source_build["centos8stream"]: Still creating... [1m10s elapsed]
6262

6363
| Name | Version |
6464
|------|---------|
65-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
66-
| <a name="provider_http"></a> [http](#provider\_http) | >= 3.0 |
67-
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
68-
| <a name="provider_tls"></a> [tls](#provider\_tls) | >= 4.0 |
65+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.44.0 |
66+
| <a name="provider_http"></a> [http](#provider\_http) | 3.5.0 |
67+
| <a name="provider_random"></a> [random](#provider\_random) | 3.8.1 |
68+
| <a name="provider_tls"></a> [tls](#provider\_tls) | 4.2.1 |
6969

7070
## Resources
7171

7272
| Name | Type |
7373
|------|------|
7474
| [aws_ami.amis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
75+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
76+
| [aws_iam_instance_profile.builds](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_instance_profile) | data source |
77+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
7578
| [aws_subnet.tfi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | data source |
7679
| [aws_vpc.tfi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
7780
| [http_http.ip](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source |
@@ -120,6 +123,7 @@ aws_instance.source_build["centos8stream"]: Still creating... [1m10s elapsed]
120123
| <a name="output_build_id"></a> [build\_id](#output\_build\_id) | n/a |
121124
| <a name="output_build_slug"></a> [build\_slug](#output\_build\_slug) | n/a |
122125
| <a name="output_builders"></a> [builders](#output\_builders) | n/a |
126+
| <a name="output_firehose_delivery_stream_names"></a> [firehose\_delivery\_stream\_names](#output\_firehose\_delivery\_stream\_names) | Kinesis Firehose delivery stream names for flushing before destroy |
123127
| <a name="output_private_key"></a> [private\_key](#output\_private\_key) | n/a |
124128
| <a name="output_public_key"></a> [public\_key](#output\_public\_key) | n/a |
125129
| <a name="output_source_builds"></a> [source\_builds](#output\_source\_builds) | n/a |

outputs.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ output "public_key" {
4343
output "build_slug" {
4444
value = local.build_slug
4545
}
46+
47+
output "firehose_delivery_stream_names" {
48+
description = "Kinesis Firehose delivery stream names for flushing before destroy"
49+
value = {
50+
for key, stream in aws_kinesis_firehose_delivery_stream.userdata_logs : key => stream.name
51+
}
52+
}

0 commit comments

Comments
 (0)