Skip to content

Commit

Permalink
Adding module documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hmanzur committed Feb 17, 2021
1 parent 65abec3 commit 51fb464
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
65 changes: 58 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,74 @@

Using S3 Website and CloudFront if needed

# Example
## Example

### Simple S3 Website

```workflow
module "website" {
source = "[email protected]:hmanzur/terraform-module-s3-website.git"
bucket_name = "my-cool-bucket"
// Optional, default is "index.html"
index_document = "index.html"
// Optional, default is "index.html"
error_document = "index.html"
// custom policy
policy = jsonencode({
Version = "2012-10-17"
Id = "MYBUCKETPOLICY"
Statement = [
{
Sid = "IPAllow"
Effect = "Deny"
Principal = "*"
Action = "s3:*"
Resource = [
aws_s3_bucket.b.arn,
"${aws_s3_bucket.b.arn}/*",
]
Condition = {
IPAddress = {
"aws:SourceIp" = "8.8.8.8/32"
}
}
},
]
})
}
```

### With Cloudfront

```workflow
module "website" {
source = "[email protected]:hmanzur/terraform-module-s3-website.git"
bucket_name = "my-cool-bucket"
enable_cloudfront = true
// Enables cloudfront
cloudfront = true
whitelist = ["US", "CA", "GB", "DE"]
aliases = ["my.domain.com", "example.domain.com", "..."]
}
```

## Variables

| Variable | Default | Required | Description |
|-------------------|-------------|----------|----------------|
| name | 10.0.0.0/16 | No | VPC name |
| enable_cloudfront | | Yes | VPC CIDR Block |
| Variable | Default | Required | Description |
|-------------------|-------------------------------------|----------|-------------------------------|
| bucket_name | | Yes | S3 Bucket name |
| index_document | `index.html` | No | Root index page |
| error_document | `index.html` | No | VPC CIDR Block |
| cloudfront | false | No | Enables CloudFront |
| policy |[policy.json](files/policy.json.tpl) | No | Custom policy |
| aliases | [] | No | Cloudfront domain aliases |
| whitelist | `["US", "CA", "GB", "DE"]` | No | Cloudfront location whitelist |

## Outputs

Expand Down
4 changes: 2 additions & 2 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ output "website_endpoint" {
}

output "cloudfront_id" {
value = aws_cloudfront_distribution.default.id
value = aws_cloudfront_distribution.default[0].id
description = "Cloudfront id"
}

output "domain_name" {
value = aws_cloudfront_distribution.default.domain_name
value = aws_cloudfront_distribution.default[0].domain_name
description = "Cloudfront domain name"
}
10 changes: 7 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
variable "bucket_name" {}
variable "bucket_name" {
description = "S3 Bucket name"
}

variable "index_document" {
default = "index.html"
description = "Root index page"
}

variable "error_document" {
default = "index.html"
description = "Failover default page"
}

variable "cloudfront" {
Expand All @@ -16,12 +20,12 @@ variable "cloudfront" {

variable "policy" {
default = false
description = "Set custom policy"
description = "Custom policy"
}

variable "aliases" {
default = []
description = "Cloudfront Array Aliases"
description = "Cloudfront domain aliases"
}

variable "whitelist" {
Expand Down

0 comments on commit 51fb464

Please sign in to comment.