|
1 | 1 | # terraform-aws-s3-static-website |
2 | | -Terraform module for deploying an AWS S3 static website with public access, website configuration, and index file support |
| 2 | + |
| 3 | +Terraform module that deploys basic AWS S3 static website |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +| Name | Version | |
| 8 | +|------|---------| |
| 9 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | |
| 10 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 | |
| 11 | + |
| 12 | +## Providers |
| 13 | + |
| 14 | +| Name | Version | |
| 15 | +|------|---------| |
| 16 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 | |
| 17 | +| <a name="provider_aws.us_east_1"></a> [aws.us\_east\_1](#provider\_aws.us\_east\_1) | >= 4.0 | |
| 18 | + |
| 19 | +## Modules |
| 20 | + |
| 21 | +No modules. |
| 22 | + |
| 23 | +## Resources |
| 24 | + |
| 25 | +| Name | Type | |
| 26 | +|------|------| |
| 27 | +| [aws_acm_certificate.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate) | resource | |
| 28 | +| [aws_acm_certificate_validation.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate_validation) | resource | |
| 29 | +| [aws_cloudfront_distribution.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution) | resource | |
| 30 | +| [aws_cloudfront_origin_access_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_origin_access_identity) | resource | |
| 31 | +| [aws_route53_record.cloudfront](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | |
| 32 | +| [aws_route53_record.ssl_validation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | |
| 33 | +| [aws_s3_bucket.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | |
| 34 | +| [aws_s3_bucket.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | |
| 35 | +| [aws_s3_bucket_acl.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource | |
| 36 | +| [aws_s3_bucket_lifecycle_configuration.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource | |
| 37 | +| [aws_s3_bucket_logging.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_logging) | resource | |
| 38 | +| [aws_s3_bucket_ownership_controls.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource | |
| 39 | +| [aws_s3_bucket_ownership_controls.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource | |
| 40 | +| [aws_s3_bucket_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource | |
| 41 | +| [aws_s3_bucket_public_access_block.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource | |
| 42 | +| [aws_s3_bucket_server_side_encryption_configuration.logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource | |
| 43 | +| [aws_s3_bucket_versioning.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource | |
| 44 | +| [aws_s3_bucket_website_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_website_configuration) | resource | |
| 45 | +| [aws_s3_object.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource | |
| 46 | +| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | |
| 47 | +| [aws_route53_zone.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source | |
| 48 | + |
| 49 | +## Inputs |
| 50 | + |
| 51 | +### S3 Configuration |
| 52 | + |
| 53 | +- **`s3_config`**: Configuration for the S3 bucket, including naming, access controls, and website settings. |
| 54 | + - **Attributes**: |
| 55 | + - **`bucket_name`**: Base name of the S3 bucket (`string`, required). Must be DNS-compliant (lowercase, numbers, hyphens only, and combined with `bucket_suffix` must not exceed 63 characters). |
| 56 | + - **`bucket_acl`**: Access control list for the S3 bucket (`string`, default: `"private"`). Allowed values: `"private"`, `"public-read"`. |
| 57 | + - **`bucket_suffix`**: Optional suffix for the bucket name (`string`, default: `""`). Must not exceed 16 characters. |
| 58 | + - **`enable_force_destroy`**: Force deletion of the bucket (`bool`, default: `false`). |
| 59 | + - **`object_ownership`**: Defines bucket ownership (`string`, default: `"BucketOwnerPreferred"`). Allowed values: `"BucketOwnerPreferred"`, `"ObjectWriter"`, `"BucketOwnerEnforced"`. |
| 60 | + - **`enable_versioning`**: Enable versioning for the bucket (`bool`, default: `false`). |
| 61 | + - **`index_document`**: Name of the index document (`string`, default: `"index.html"`). Cannot be empty. |
| 62 | + - **`error_document`**: Name of the error document (`string`, default: `""`). |
| 63 | + - **`public_access`**: Public access configuration for the bucket (`object`): |
| 64 | + - **`block_public_acls`**: Block public ACLs (`bool`, default: `true`). |
| 65 | + - **`block_public_policy`**: Block public bucket policies (`bool`, default: `true`). |
| 66 | + - **`ignore_public_acls`**: Ignore public ACLs (`bool`, default: `true`). |
| 67 | + - **`restrict_public_buckets`**: Restrict public buckets (`bool`, default: `true`). |
| 68 | + - **`source_file_path`**: Path to the local website files (`string`, default: `"/var/www"`). Cannot be empty. |
| 69 | + - **`allowed_principals`**: List of principals allowed access to the bucket (`list(string)`, default: `["*"]`). Must contain at least one principal. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### CDN Configuration |
| 74 | + |
| 75 | +- **`cdn_config`**: Settings for enabling HTTPS, CloudFront, ACM, and optional custom domain configurations. |
| 76 | + - **Attributes**: |
| 77 | + - **`enable`**: Enable or disable CDN. When `false`, CloudFront-related outputs will be `null` (`bool`, default: `false`). |
| 78 | + - **`domain`**: Domain settings for the CDN (`object`). |
| 79 | + - **`name`**: Root domain name (`string`, default: `""`). Must be DNS-compliant. |
| 80 | + - **`sub_name`**: Subdomain name (`string`, default: `""`). Must be DNS-compliant. |
| 81 | + - **`ttl`**: Time-to-live for DNS records (`number`, default: `300`). |
| 82 | + - **`validation_method`**: ACM validation method (`string`, default: `"DNS"`). |
| 83 | + - **`origin_access_comment`**: Comment for the CloudFront origin access identity (`string`, default: `"Access Identity for S3 Origin"`). |
| 84 | + - **`allowed_methods`**: Allowed HTTP methods (`list(string)`, default: `["GET", "HEAD", "OPTIONS"]`). Must contain at least one method. |
| 85 | + - **`cached_methods`**: Cached HTTP methods (`list(string)`, default: `["GET", "HEAD"]`). Must contain at least one method. |
| 86 | + - **`enable_compression`**: Enable HTTP compression (`bool`, default: `true`). |
| 87 | + - **`protocol_policy`**: CloudFront protocol policy (`string`, default: `"redirect-to-https"`). Allowed values: `"allow-all"`, `"redirect-to-https"`, `"https-only"`. |
| 88 | + - **`forward_query_string`**: Forward query strings to the origin (`bool`, default: `false`). |
| 89 | + - **`forward_cookies`**: Cookie forwarding policy (`string`, default: `"none"`). |
| 90 | + - **`minimum_ttl`**: Minimum TTL for objects (`number`, default: `0`). Must be greater than or equal to `0`. |
| 91 | + - **`default_ttl`**: Default TTL for objects (`number`, default: `300`). Must be greater than or equal to `minimum_ttl`. |
| 92 | + - **`maximum_ttl`**: Maximum TTL for objects (`number`, default: `1200`). Must be greater than or equal to `default_ttl`. |
| 93 | + - **`price_class`**: CloudFront price class (`string`, default: `"PriceClass_All"`). Allowed values: `"PriceClass_All"`, `"PriceClass_200"`, `"PriceClass_100"`. |
| 94 | + - **`error_page_path`**: Path for custom error pages (`string`, default: `"/error.html"`). |
| 95 | + - **`error_page_cache_ttl`**: TTL for caching error pages (`number`, default: `300`). |
| 96 | + - **`ssl_support_method`**: SSL support method for CloudFront (`string`, default: `"sni-only"`). Allowed values: `"sni-only"`, `"vip"`. |
| 97 | + - **`minimum_tls_version`**: Minimum TLS version for HTTPS (`string`, default: `"TLSv1.2_2021"`). Allowed values: `"SSLv3"`, `"TLSv1"`, `"TLSv1.1"`, `"TLSv1.2"`, `"TLSv1.2_2018"`, `"TLSv1.2_2021"`. |
| 98 | + - **`geo_restriction_policy`**: Geo-restriction policy (`string`, default: `"none"`). Allowed values: `"none"`, `"whitelist"`, `"blacklist"`. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +### Logging Configuration |
| 103 | + |
| 104 | +- **`logging_config`**: Configuration for S3 bucket logging. |
| 105 | + - **Attributes**: |
| 106 | + - **`enable`**: Enable or disable logging. When `false`, `s3_logging_bucket` output will be `null` (`bool`, default: `false`). |
| 107 | + - **`s3_prefix`**: Prefix for logging files in S3 (`string`, default: `"s3/"`). Must be a valid string. |
| 108 | + - **`cloudfront_prefix`**: Prefix for CloudFront logs in S3 (`string`, default: `"cloudfront/"`). Must be a valid string. |
| 109 | + - **`log_retention_days`**: Retention period for logs (`number`, default: `30`). |
| 110 | + - **`enable_encryption`**: Enable encryption for logs (`bool`, default: `true`). |
| 111 | + - **`encryption_algorithm`**: Algorithm for log encryption (`string`, default: `"AES256"`). |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +### Tags |
| 116 | + |
| 117 | +- **`tags`**: Map of tags to assign to the resources (`map(string)`, default: `{}`). |
| 118 | + |
| 119 | +## Outputs |
| 120 | + |
| 121 | +| Name | Description | |
| 122 | +|------|-------------| |
| 123 | +| <a name="output_acm_certificate_arn"></a> [acm\_certificate\_arn](#output\_acm\_certificate\_arn) | The ARN of the ACM certificate used for the CloudFront distribution, if HTTPS is enabled. | |
| 124 | +| <a name="output_cloudfront_distribution_arn"></a> [cloudfront\_distribution\_arn](#output\_cloudfront\_distribution\_arn) | The ARN of the CloudFront distribution, if CDN is enabled. Null if CDN is disabled. | |
| 125 | +| <a name="output_cloudfront_distribution_id"></a> [cloudfront\_distribution\_id](#output\_cloudfront\_distribution\_id) | The ID of the CloudFront distribution, if CDN is enabled. Null if CDN is disabled. | |
| 126 | +| <a name="output_cloudfront_dns_name"></a> [cloudfront\_dns\_name](#output\_cloudfront\_dns\_name) | The DNS name for the CloudFront distribution, managed by Route 53, if CDN is enabled. | |
| 127 | +| <a name="output_cloudfront_website_url"></a> [cloudfront\_website\_url](#output\_cloudfront\_website\_url) | The website URL served through CloudFront when CDN is enabled. Empty if CDN is disabled. | |
| 128 | +| <a name="output_s3_bucket_arn"></a> [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | The ARN of the S3 bucket. | |
| 129 | +| <a name="output_s3_bucket_id"></a> [s3\_bucket\_id](#output\_s3\_bucket\_id) | The unique ID of the S3 bucket. | |
| 130 | +| <a name="output_s3_bucket_region"></a> [s3\_bucket\_region](#output\_s3\_bucket\_region) | The AWS region where the S3 bucket is deployed. | |
| 131 | +| <a name="output_s3_logging_bucket"></a> [s3\_logging\_bucket](#output\_s3\_logging\_bucket) | The ID of the S3 bucket used for logging, if logging is enabled. Null if logging is disabled. | |
| 132 | +| <a name="output_s3_website_url"></a> [s3\_website\_url](#output\_s3\_website\_url) | The HTTP URL of the S3 static website. Note: HTTPS is not natively supported by S3. | |
| 133 | +| <a name="output_website_url"></a> [website\_url](#output\_website\_url) | The dynamic website URL, using Route 53 custom domain if CDN is enabled, otherwise S3. | |
0 commit comments