-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FaithKovi
committed
Jul 30, 2024
1 parent
08d6ade
commit 5e0c4f7
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import boto3 | ||
import os | ||
|
||
def get_bucket_name(tfvars_file): | ||
with open(tfvars_file, 'r') as file: | ||
for line in file: | ||
if line.startswith("bucket_name"): | ||
return line.split('=')[1].strip().replace('"', '') | ||
|
||
def empty_bucket(bucket_name): | ||
s3 = boto3.resource('s3') | ||
bucket = s3.Bucket(bucket_name) | ||
bucket.objects.all().delete() | ||
|
||
if __name__ == "__main__": | ||
tfvars_file = 'variables.tfvars' | ||
bucket_name = get_bucket_name(tfvars_file) | ||
print(f"Emptying bucket: {bucket_name}") | ||
empty_bucket(bucket_name) | ||
print("Bucket emptied successfully.") |