This Terraform module enables you to create AWS S3 buckets programmatically using Terraform. With this module, you can automate the process of creating multiple S3 buckets with configurable settings.
-
Creates a set of S3 buckets - The count attribute is used to create a set of buckets, where the number of buckets is equal to the length of the var.bucket_names variable.
-
Configures the bucket properties - The acl attribute sets the access control list for the buckets, and the force_destroy attribute ensures that the buckets are deleted even if there are still objects in them.
-
Configures versioning - The versioning block enables versioning for the buckets.
-
Configures server-side encryption - The server_side_encryption_configuration block enables server-side encryption for the buckets, and specifies the encryption algorithm to use.
-
Configures lifecycle rules - The lifecycle_rule block configures a lifecycle rule for the buckets. The rule specifies that objects should be transitioned to a different storage class after a certain number of days.
-
The count attribute is a special attribute that is used to create a set of resources. In this case, the count attribute is used to create a set of S3 buckets, where the number of buckets is equal to the length of the var.bucket_names variable.
-
The acl attribute sets the access control list for the buckets. The access control list determines who has access to the buckets and what permissions they have.
-
The force_destroy attribute ensures that the buckets are deleted even if there are still objects in them. This is important because it prevents orphaned objects from being left behind.
-
The versioning block enables versioning for the buckets. Versioning allows you to keep multiple versions of objects in the buckets. This can be useful for data protection and auditing purposes.
-
The server_side_encryption_configuration block enables server-side encryption for the buckets. Server-side encryption encrypts objects before they are stored in the buckets. This helps to protect the confidentiality of your data.
-
The lifecycle_rule block configures a lifecycle rule for the buckets. The lifecycle rule specifies how objects should be transitioned to different storage classes over time. This can help you to optimize your storage costs.
To use this module, include the following code in your Terraform configuration:
module "s3" {
source = "./s3-module"
}
Customize the module name like s3 or with the names of the module which is according to your preference. Adjust source with the name of the folder which contains all the code. For example here, i have created a folder with the name "s3-module".
- Terraform latest version
- AWS Account (a trial account would work)
- GitHub Personal Access Token with appropriate permissions (if you want to create CI/CD pipeline through Github Action)
Name | Description | Type | Default | Required |
---|---|---|---|---|
Environment | Put the Environment according to your preference | string |
"Production" |
no |
bucket_names | Put the name of the bucket according to your preference | list(string) |
["infrasity1", "infrasity2", "infrasity3"] | no |
days | Choose the no. of days of lifecycle_rule according to your preference | list |
[30, 60, 365] | no |
sse_algorithm | Choose the sse_algorithm according to your needs | string |
"AES256" |
no |
storage_class | Select the strorage class according to your needs | list(string) |
["STANDARD_IA","GLACIER"] | no |
Clone the project
git clone https://github.com/ScaleupInfra/terraform-aws-s3-bucket.git
Go to the project directory
cd terraform-aws-s3-bucket
teraform init
terraform plan
teraform apply -auto-approve
Destroy Infrastructrre dependencies
terraform destroy -auto-approve
Come join our Open Source Community on Slack. It's completely FREE! Our community is the perfect platform for infrastructure enthusiasts like you. Engage in discussions, seek advice, share your ideas, and collaborate with fellow community members to build scalable and robust infrastructure solutions. Don't miss out on this opportunity to be a part of our thriving community!
Contributions are always welcome!
See contributing.md
for ways to get started.
Please adhere to this project's code of conduct
.