Skip to content

Commit 0c001a8

Browse files
author
Nikita Dugar
committed
initial commit
0 parents  commit 0c001a8

File tree

22 files changed

+1189
-0
lines changed

22 files changed

+1189
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ignored files
2+
*.tfstate
3+
*.tfstate.backup
4+
.terraform
5+
.idea
6+
*.iml

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.12.0
4+
hooks:
5+
- id: terraform_fmt
6+
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v2.0.0
9+
hooks:
10+
- id: check-merge-conflict
11+
- id: trailing-whitespace
12+
- id: check-yaml
13+
- id: check-added-large-files

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Cloud Drove
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export GENIE_PATH ?= $(shell 'pwd')/../../../genie
2+
3+
include $(GENIE_PATH)/Makefile

README.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
<!-- This file was automatically generated by the `geine`. Make all changes to `README.yaml` and run `make readme` to rebuild this file. -->
2+
3+
<p align="center"> <img src="https://user-images.githubusercontent.com/50652676/62349836-882fef80-b51e-11e9-99e3-7b974309c7e3.png" width="100" height="100"></p>
4+
5+
6+
<h1 align="center">
7+
Terraform AWS S3
8+
</h1>
9+
10+
<p align="center" style="font-size: 1.2rem;">
11+
Terraform module to create default S3 bucket with logging and encryption type specific features.
12+
</p>
13+
14+
<p align="center">
15+
16+
<a href="https://www.terraform.io">
17+
<img src="https://img.shields.io/badge/Terraform-v0.12-green" alt="Terraform">
18+
</a>
19+
<a href="LICENSE.md">
20+
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="Licence">
21+
</a>
22+
23+
24+
</p>
25+
<p align="center">
26+
27+
<a href='https://facebook.com/sharer/sharer.php?u=https://github.com/clouddrove/terraform-aws-s3'>
28+
<img title="Share on Facebook" src="https://user-images.githubusercontent.com/50652676/62817743-4f64cb80-bb59-11e9-90c7-b057252ded50.png" />
29+
</a>
30+
<a href='https://www.linkedin.com/shareArticle?mini=true&title=Terraform+AWS+S3&url=https://github.com/clouddrove/terraform-aws-s3'>
31+
<img title="Share on LinkedIn" src="https://user-images.githubusercontent.com/50652676/62817742-4e339e80-bb59-11e9-87b9-a1f68cae1049.png" />
32+
</a>
33+
<a href='https://twitter.com/intent/tweet/?text=Terraform+AWS+S3&url=https://github.com/clouddrove/terraform-aws-s3'>
34+
<img title="Share on Twitter" src="https://user-images.githubusercontent.com/50652676/62817740-4c69db00-bb59-11e9-8a79-3580fbbf6d5c.png" />
35+
</a>
36+
37+
</p>
38+
<hr>
39+
40+
41+
We eat, drink, sleep and most importantly love **DevOps**. We are working towards stratergies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy <b>Bigger problems are always solved by breaking them into smaller manageable problems</b>. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller <b>connected yet manageable pieces</b> within the infrastructure.
42+
43+
This module is basically combination of [Terraform open source](https://www.terraform.io/) and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.
44+
45+
We have [*fifty plus terraform modules*][terraform_modules]. A few of them are comepleted and are available for open source usage while a few others are in progress.
46+
47+
48+
49+
50+
## Prerequisites
51+
52+
This module has a few dependencies:
53+
54+
- [Terraform 0.12](https://learn.hashicorp.com/terraform/getting-started/install.html)
55+
- [Go](https://golang.org/doc/install)
56+
- [github.com/stretchr/testify/assert](https://github.com/stretchr/testify)
57+
- [github.com/gruntwork-io/terratest/modules/terraform](https://github.com/gruntwork-io/terratest)
58+
59+
60+
61+
62+
63+
64+
## Examples
65+
66+
**IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-s3/releases).
67+
68+
69+
Here are some examples of how you can use this module in your inventory structure:
70+
### Basic Bucket
71+
```hcl
72+
module "s3_bucket" {
73+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
74+
name = "secure-bucket"
75+
region = "eu-west-1"
76+
application = "clouddrove"
77+
environment = "test"
78+
label_order = ["environment", "name", "application"]
79+
versioning = true
80+
acl = "private"
81+
bucket_enabled = true
82+
}
83+
```
84+
### Encryption Bucket
85+
```hcl
86+
module "s3_bucket" {
87+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
88+
name = "encryption-bucket"
89+
region = "eu-west-1"
90+
application = "clouddrove"
91+
environment = "test"
92+
label_order = ["environment", "name", "application"]
93+
versioning = true
94+
acl = "private"
95+
encryption_enabled = true
96+
sse_algorithm = "AES256"
97+
}
98+
```
99+
### Logging Bucket
100+
```hcl
101+
module "s3_bucket" {
102+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
103+
name = "logging-bucket"
104+
region = "eu-west-1"
105+
application = "clouddrove"
106+
environment = "test"
107+
label_order = ["environment", "name", "application"]
108+
versioning = true
109+
acl = "private"
110+
bucket_logging_enabled = true
111+
target_bucket = "bucket-logs12"
112+
target_prefix = "logs"
113+
}
114+
```
115+
### Website Host Bucket
116+
```hcl
117+
module "s3_bucket" {
118+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
119+
name = "website-bucket"
120+
region = "eu-west-1"
121+
application = "clouddrove"
122+
environment = "test"
123+
label_order = ["environment", "name", "application"]
124+
versioning = true
125+
acl = "private"
126+
website_hosting_bucket = true
127+
website_index = "index.html"
128+
website_error = "error.html"
129+
bucket_policy = true
130+
lifecycle_expiration_enabled = true
131+
lifecycle_expiration_object_prefix = "test"
132+
lifecycle_days_to_expiration = 10
133+
aws_iam_policy_document = data.aws_iam_policy_document.default.json
134+
}
135+
data "aws_iam_policy_document" "default" {
136+
version = "2012-10-17"
137+
statement {
138+
sid = "Stmt1447315805704"
139+
effect = "Allow"
140+
principals {
141+
type = "AWS"
142+
identifiers = ["*"]
143+
}
144+
actions = ["s3:GetObject"]
145+
resources = ["arn:aws:s3:::test-website-bucket-clouddrove/*"]
146+
}
147+
}
148+
```
149+
150+
151+
152+
## Inputs
153+
154+
| Name | Description | Type | Default | Required |
155+
|------|-------------|:----:|:-----:|:-----:|
156+
| acl | Canned ACL to apply to the S3 bucket. | string | `` | no |
157+
| application | Application (e.g. `cd` or `clouddrove`). | string | `` | no |
158+
| attributes | Additional attributes (e.g. `1`). | list | `<list>` | no |
159+
| aws_iam_policy_document | Specifies the number of days after object creation when the object expires. | string | `` | no |
160+
| bucket_enabled | Enable simple S3. | bool | `false` | no |
161+
| bucket_logging_enabled | Enable logging of S3. | bool | `false` | no |
162+
| bucket_policy | Conditionally create S3 bucket policy. | bool | `false` | no |
163+
| create_bucket | Conditionally create S3 bucket. | bool | `true` | no |
164+
| delimiter | Delimiter to be used between `organization`, `environment`, `name` and `attributes`. | string | `-` | no |
165+
| encryption_enabled | Enable encryption of S3. | bool | `false` | no |
166+
| environment | Environment (e.g. `prod`, `dev`, `staging`). | string | `` | no |
167+
| force_destroy | A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. | bool | `false` | no |
168+
| kms_master_key_id | The AWS KMS master key ID used for the SSE-KMS encryption. This can only be used when you set the value of sse_algorithm as aws:kms. The default aws/s3 AWS KMS master key is used if this element is absent while the sse_algorithm is aws:kms. | string | `` | no |
169+
| label_order | Label order, e.g. `name`,`application`. | list | `<list>` | no |
170+
| lifecycle_days_to_expiration | Specifies the number of days after object creation when the object expires. | number | `365` | no |
171+
| lifecycle_days_to_glacier_transition | Specifies the number of days after object creation when it will be moved to Glacier storage. | number | `180` | no |
172+
| lifecycle_days_to_infrequent_storage_transition | Specifies the number of days after object creation when it will be moved to standard infrequent access storage. | number | `60` | no |
173+
| lifecycle_expiration_enabled | Specifies expiration lifecycle rule status. | bool | `false` | no |
174+
| lifecycle_expiration_object_prefix | Object key prefix identifying one or more objects to which the lifecycle rule applies. | string | `` | no |
175+
| lifecycle_glacier_object_prefix | Object key prefix identifying one or more objects to which the lifecycle rule applies. | string | `` | no |
176+
| lifecycle_glacier_transition_enabled | Specifies Glacier transition lifecycle rule status. | bool | `false` | no |
177+
| lifecycle_infrequent_storage_object_prefix | Object key prefix identifying one or more objects to which the lifecycle rule applies. | string | `` | no |
178+
| lifecycle_infrequent_storage_transition_enabled | Specifies infrequent storage transition lifecycle rule status. | bool | `false` | no |
179+
| name | Name (e.g. `app` or `cluster`). | string | `` | no |
180+
| region | Region Where you want to host S3. | string | `` | no |
181+
| sse_algorithm | The server-side encryption algorithm to use. Valid values are AES256 and aws:kms. | string | `AES256` | no |
182+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`). | map | `<map>` | no |
183+
| target_bucket | The name of the bucket that will receive the log objects. | string | `` | no |
184+
| target_prefix | To specify a key prefix for log objects. | string | `` | no |
185+
| versioning | Enable Versioning of S3. | bool | `false` | no |
186+
| website_error | An absolute path to the document to return in case of a 4XX error. | string | `error.html` | no |
187+
| website_hosting_bucket | Enable website hosting of S3. | bool | `false` | no |
188+
| website_index | Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders. | string | `index.html` | no |
189+
190+
## Outputs
191+
192+
| Name | Description |
193+
|------|-------------|
194+
| arn | The ARN of the s3 bucket. |
195+
| bucket_domain_name | The Domain of the s3 bucket. |
196+
| id | The ID of the s3 bucket. |
197+
| tags | A mapping of tags to assign to the resource. |
198+
199+
200+
201+
## Testing
202+
203+
In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system.
204+
205+
You need to run the following command in the testing folder:
206+
```hcl
207+
go test -run Test
208+
```
209+
210+
211+
212+
## Feedback
213+
If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-aws-s3/issues), or feel free to drop us an email at [hello@clouddrove.com](mailto:hello@clouddrove.com).
214+
215+
If you have found it worth your time, go ahead and give us a * on [our GitHub](https://github.com/clouddrove/terraform-aws-s3)!
216+
217+
## About us
218+
219+
At [CloudDrove][website], we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering.
220+
221+
<p align="center">We are <b> The Cloud Experts!</b></p>
222+
<hr />
223+
<p align="center">We ❤️ <a href="https://github.com/clouddrove">Open Source</a> and you can check out <a href="https://github.com/clouddrove">our other modules</a> to get help with your new Cloud ideas.</p>
224+
225+
[website]: https://clouddrove.com
226+
[github]: https://github.com/clouddrove
227+
[linkedin]: https://cpco.io/linkedin
228+
[twitter]: https://twitter.com/clouddrove/
229+
[email]: https://clouddrove.com/contact-us.html
230+
[terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language=

README.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
#
3+
# This is the canonical configuration for the `README.md`
4+
# Run `make readme` to rebuild the `README.md`
5+
#
6+
7+
# Name of this project
8+
name : Terraform AWS S3
9+
10+
# License of this project
11+
license: "MIT"
12+
13+
# Canonical GitHub repo
14+
github_repo: clouddrove/terraform-aws-s3
15+
16+
# Badges to display
17+
badges:
18+
- name: "Terraform"
19+
image: "https://img.shields.io/badge/Terraform-v0.12-green"
20+
url: "https://www.terraform.io"
21+
- name: "Licence"
22+
image: "https://img.shields.io/badge/License-MIT-blue.svg"
23+
url: "LICENSE.md"
24+
25+
# description of this project
26+
description: |-
27+
Terraform module to create default S3 bucket with logging and encryption type specific features.
28+
29+
# extra content
30+
include:
31+
- "terraform.md"
32+
33+
# How to use this project
34+
usage : |-
35+
Here are some examples of how you can use this module in your inventory structure:
36+
### Basic Bucket
37+
```hcl
38+
module "s3_bucket" {
39+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
40+
name = "secure-bucket"
41+
region = "eu-west-1"
42+
application = "clouddrove"
43+
environment = "test"
44+
label_order = ["environment", "name", "application"]
45+
versioning = true
46+
acl = "private"
47+
bucket_enabled = true
48+
}
49+
```
50+
### Encryption Bucket
51+
```hcl
52+
module "s3_bucket" {
53+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
54+
name = "encryption-bucket"
55+
region = "eu-west-1"
56+
application = "clouddrove"
57+
environment = "test"
58+
label_order = ["environment", "name", "application"]
59+
versioning = true
60+
acl = "private"
61+
encryption_enabled = true
62+
sse_algorithm = "AES256"
63+
}
64+
```
65+
### Logging Bucket
66+
```hcl
67+
module "s3_bucket" {
68+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
69+
name = "logging-bucket"
70+
region = "eu-west-1"
71+
application = "clouddrove"
72+
environment = "test"
73+
label_order = ["environment", "name", "application"]
74+
versioning = true
75+
acl = "private"
76+
bucket_logging_enabled = true
77+
target_bucket = "bucket-logs12"
78+
target_prefix = "logs"
79+
}
80+
```
81+
### Website Host Bucket
82+
```hcl
83+
module "s3_bucket" {
84+
source = "https://github.com/clouddrove/terraform-aws-s3?ref=tags/0.12.1"
85+
name = "website-bucket"
86+
region = "eu-west-1"
87+
application = "clouddrove"
88+
environment = "test"
89+
label_order = ["environment", "name", "application"]
90+
versioning = true
91+
acl = "private"
92+
website_hosting_bucket = true
93+
website_index = "index.html"
94+
website_error = "error.html"
95+
bucket_policy = true
96+
lifecycle_expiration_enabled = true
97+
lifecycle_expiration_object_prefix = "test"
98+
lifecycle_days_to_expiration = 10
99+
aws_iam_policy_document = data.aws_iam_policy_document.default.json
100+
}
101+
data "aws_iam_policy_document" "default" {
102+
version = "2012-10-17"
103+
statement {
104+
sid = "Stmt1447315805704"
105+
effect = "Allow"
106+
principals {
107+
type = "AWS"
108+
identifiers = ["*"]
109+
}
110+
actions = ["s3:GetObject"]
111+
resources = ["arn:aws:s3:::test-website-bucket-clouddrove/*"]
112+
}
113+
}
114+
```

0 commit comments

Comments
 (0)