├── .ebextensions └── efs_mount.config ├── .gitignore ├── CHANGELOG.md ├── README.md ├── cloudfront ├── main.tf ├── outputs.tf └── variables.tf ├── eb-env ├── main.tf ├── outputs.tf └── variables.tf ├── example.tf ├── exampleWithCloudfront.tf ├── package.json ├── r53-alias ├── main.tf └── variables.tf └── yarn.lock /.ebextensions/efs_mount.config: -------------------------------------------------------------------------------- 1 | ################################################################################################ 2 | # This script mount the EFS volume related to passed environment variables 3 | ################################################################################################ 4 | # https://github.com/awslabs/elastic-beanstalk-docs/blob/master/configuration-files/aws-provided/instance-configuration/storage-efs-mountfilesystem.config 5 | 6 | packages: 7 | yum: 8 | nfs-utils: [] 9 | jq: [] 10 | 11 | commands: 12 | 01_mount: 13 | command: "/tmp/mount-efs.sh" 14 | 15 | files: 16 | "/tmp/mount-efs.sh": 17 | mode: "000755" 18 | content : | 19 | #!/bin/bash 20 | 21 | EFS_REGION=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.AWS_REGION') 22 | EFS_MOUNT_DIR=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_MOUNT_DIRECTORY') 23 | EFS_FILE_SYSTEM_ID=$(/opt/elasticbeanstalk/bin/get-config environment | jq -r '.EFS_ID') 24 | 25 | echo "Mounting EFS filesystem ${EFS_FILE_SYSTEM_ID} to directory ${EFS_MOUNT_DIR} ..." 26 | 27 | echo 'Stopping NFS ID Mapper...' 28 | service rpcidmapd status &> /dev/null 29 | if [ $? -ne 0 ] ; then 30 | echo 'rpc.idmapd is already stopped!' 31 | else 32 | service rpcidmapd stop 33 | if [ $? -ne 0 ] ; then 34 | echo 'ERROR: Failed to stop NFS ID Mapper!' 35 | exit 1 36 | fi 37 | fi 38 | 39 | echo 'Checking if EFS mount directory exists...' 40 | if [ ! -d ${EFS_MOUNT_DIR} ]; then 41 | echo "Creating directory ${EFS_MOUNT_DIR} ..." 42 | mkdir -p ${EFS_MOUNT_DIR} 43 | if [ $? -ne 0 ]; then 44 | echo 'ERROR: Directory creation failed!' 45 | exit 1 46 | fi 47 | chmod 777 ${EFS_MOUNT_DIR} 48 | if [ $? -ne 0 ]; then 49 | echo 'ERROR: Permission update failed!' 50 | exit 1 51 | fi 52 | else 53 | echo "Directory ${EFS_MOUNT_DIR} already exists!" 54 | fi 55 | 56 | mountpoint -q ${EFS_MOUNT_DIR} 57 | if [ $? -ne 0 ]; then 58 | echo "mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 ${EFS_FILE_SYSTEM_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}" 59 | mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 ${EFS_FILE_SYSTEM_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR} 60 | if [ $? -ne 0 ] ; then 61 | echo 'ERROR: Mount command failed!' 62 | exit 1 63 | fi 64 | else 65 | echo "Directory ${EFS_MOUNT_DIR} is already a valid mountpoint!" 66 | fi 67 | 68 | echo 'EFS mount complete.' 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ project files 2 | .idea 3 | *.iml 4 | 5 | # Terraform files 6 | /.terraform/ 7 | 8 | node_modules/ 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). 5 | 6 | #### [1.11.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.10.0...1.11.0) 7 | > 29 November 2018 8 | - Added instance volume settings [`99109ec`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/99109ecc35f7c354a684b4e10b1bd4b47465eb9b) 9 | - Updated default instance to t3 and AMI [`d7af965`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/d7af9657c8fc1c39ed65228ad91a76041928a244) 10 | 11 | #### [1.10.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.9.0...1.10.0) 12 | > 16 October 2018 13 | - Disabled Cloudfront geo restrictions by default [`a66669b`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/a66669bea1416c96e89f41e1c1329732e151da7d) 14 | - Added vars for cloudfront geo restrictions [`9821c64`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/9821c64eeacead4a08701b47e0bbebaf31b92b70) 15 | 16 | #### [1.9.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.8.0...1.9.0) 17 | > 1 October 2018 18 | - Added Support for aws:elb:healthcheck [`b4e8090`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/b4e80907abde51af1a1437d2217317eae56db952) 19 | - Updated changlog v1.8.0 [`3dbea98`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/3dbea98156ef3c908d31f462857a13fecbd9a9f5) 20 | 21 | #### [1.8.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.7.2...1.8.0) 22 | > 26 April 2018 23 | - Added changelog [`71fcedc`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/71fcedcbe23f90a5e14c64a3387bc36fa8c04a33) 24 | - Added support for auto-scaling trigger options [`f166e1a`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/f166e1a057c43f7920a03ad3c76eb32480d0f9c3) 25 | 26 | #### [1.7.2](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.7.1...1.7.2) 27 | > 9 April 2018 28 | - Fixed exclusive iam role policy attachment [`c1123de`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/c1123defefa7501044230248c39f65833f74e059) 29 | 30 | #### [1.7.1](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.7.0...1.7.1) 31 | > 6 April 2018 32 | - Fixed EB Environment Service Role [`202bb00`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/202bb00aee569396449b109c7d7bf11692ffe2cd) 33 | 34 | #### [1.7.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.6.0...1.7.0) 35 | > 5 April 2018 36 | - Added support for Notification Topic ARN [`34127ef`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/34127efa766be53565372af02ea5b1101e58f2c9) 37 | 38 | #### [1.6.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.5.0...1.6.0) 39 | > 19 March 2018 40 | - Added Cloudfront forward header setting [`6507fbe`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/6507fbeddbdddc9b577097d46a8e5426600206f9) 41 | 42 | #### [1.5.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.4.0...1.5.0) 43 | > 16 March 2018 44 | - Added Auto disable classic ELB setting on Single Instance config [`ee0ecfc`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/ee0ecfca1e8241110a1353722490d77f40c0ec1b) 45 | - Added Environment Type setting (SingleInstance / LoadBalanced) [`563b99e`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/563b99ed5a29250716fe19282336613efd8f2e65) 46 | 47 | #### [1.4.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.3.0...1.4.0) 48 | > 12 December 2017 49 | - Support Enhanced health reporting [`ff7f840`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/ff7f8405f5b0e4f42d0e75b869ede6aaca47b7bf) 50 | 51 | #### [1.3.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.2.0...1.3.0) 52 | > 16 November 2017 53 | - Add cloudfront support [`c3f1a4c`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/c3f1a4cb3fd59e609c11a6bf9ca7f721c99e038a) 54 | 55 | #### [1.2.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.1.0...1.2.0) 56 | > 6 July 2017 57 | - Change defautl ignore healthcheck to false [`91de78a`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/91de78a2f95e386dc5b8bee32932fc781088aeae) 58 | 59 | #### [1.1.0](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/compare/1.0.0...1.1.0) 60 | > 15 June 2017 61 | - Add EFS support [`10c98f9`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/10c98f9eba6b752db51d5eede56c11a8a1d5b211) 62 | 63 | #### 1.0.0 64 | > 24 May 2017 65 | - update solution_stack_name [`26d643f`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/26d643fa7c9f2cd6329a572c3a84517a896fb6bf) 66 | - Change exemple values [`52f5429`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/52f5429f130fa77b973cf7e67ed91dfc986d663a) 67 | - Improve documentation [`37b3faa`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/37b3faa6f2d914f2aacee97b2dca44eefec145b2) 68 | - First implementation [`d917fc9`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/d917fc9d98cf5a9a9de95ebc85c16108f3671c8a) 69 | - Initial commit [`04a32e9`](https://github.com/BasileTrujillo/terraform-elastic-beanstalk-php/commit/04a32e9f9b08e1322639a7d5562c8f4afeb623ab) 70 | 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Terraform AWS Elastic Beanstalk PHP 2 | 3 | Terraform script to setup AWS Elastic Beanstalk with a load-balanced or Single Instance PHP app. 4 | 5 | ## What this script does 6 | 7 | * Create an Elastic Beanstalk Application and environment. 8 | * Setup the EB environment with PHP, an Elastic Loadbalancer and forward port from HTTP / HTTPS to the specified instance port. 9 | * (Optionnal) Create a Route53 Alias to link your domain to the EB domain name 10 | * (Optionnal) Create a Cloudfront distribution on top of your Elastic Beanstalk environment 11 | 12 | 13 | ## Usage 14 | 15 | Create a `main.tf` file with the following configuration: 16 | 17 | ### First: create an EB Application 18 | 19 | ```hcl 20 | ################################################## 21 | ## Your variables 22 | ################################################## 23 | variable "aws_region" { 24 | type = "string" 25 | default = "eu-west-1" 26 | } 27 | variable "env" { 28 | type = "string" 29 | default = "dev" 30 | } 31 | variable "service_name" { 32 | type = "string" 33 | default = "php-app-test" 34 | } 35 | 36 | 37 | ################################################## 38 | ## AWS config 39 | ################################################## 40 | provider "aws" { 41 | region = "${var.aws_region}" 42 | } 43 | 44 | 45 | ################################################## 46 | ## Elastic Beanstalk config 47 | ################################################## 48 | resource "aws_elastic_beanstalk_application" "eb_app" { 49 | name = "${var.service_name}" 50 | description = "My awesome nodeJs App" 51 | } 52 | ``` 53 | 54 | ### Then, create an EB environment using the module 55 | 56 | ```hcl 57 | ################################################## 58 | ## Elastic Beanstalk config 59 | ################################################## 60 | module "eb_env" { 61 | source = "github.com/BasileTrujillo/terraform-elastic-beanstalk-php//eb-env" 62 | aws_region = "${var.aws_region}" 63 | 64 | # Application settings 65 | env = "${var.env}" 66 | service_name = "${var.service_name}" 67 | service_description = "My awesome php App" 68 | 69 | # PHP settings 70 | php_version = "7.0" 71 | document_root = "/public" 72 | memory_limit = "512M" 73 | zlib_php_compression = "Off" 74 | allow_url_fopen = "On" 75 | display_errors = "On" 76 | max_execution_time = "60" 77 | composer_options = "" 78 | 79 | # Instance settings 80 | instance_type = "t2.micro" 81 | min_instance = "2" 82 | max_instance = "4" 83 | 84 | # ELB 85 | enable_https = "false" # If set to true, you will need to add an ssl_certificate_id (see L70 in app/variables.tf) 86 | 87 | # Security 88 | vpc_id = "vpc-xxxxxxx" 89 | vpc_subnets = "subnet-xxxxxxx" 90 | elb_subnets = "subnet-xxxxxxx" 91 | security_groups = "sg-xxxxxxx" 92 | } 93 | ``` 94 | 95 | ### Link your domain using Route53 96 | 97 | Add to the previous script the following lines: 98 | 99 | ```hcl 100 | ################################################## 101 | ## Route53 config 102 | ################################################## 103 | module "app_dns" { 104 | source = "github.com/BasileTrujillo/terraform-elastic-beanstalk-php//r53-alias" 105 | aws_region = "${var.aws_region}" 106 | 107 | domain = "example.io" 108 | domain_name = "my-app.example.io" 109 | eb_cname = "${module.eb_env.eb_cname}" 110 | } 111 | ``` 112 | 113 | ### Add an Elastic File System to your EB 114 | 115 | * First, create the EFS before the Elastic Beanstalk Environment: 116 | ```hcl 117 | ################################################## 118 | ## AWS Elastic File System 119 | ################################################## 120 | resource "aws_efs_file_system" "file_storage" { 121 | creation_token = "${var.service_name}-${var.env}" 122 | 123 | tags { 124 | Name = "${var.service_name}-${var.env}" 125 | } 126 | } 127 | 128 | resource "aws_efs_mount_target" "file_storage_target" { 129 | file_system_id = "${aws_efs_file_system.file_storage.id}" 130 | subnet_id = "${var.vpc_subnets}" 131 | security_groups = ["${var.security_groups}"] 132 | } 133 | ``` 134 | 135 | * Then set `efs_id` & `efs_mount_directory` to the Elastic Beanstalk Environment module: 136 | ```hcl 137 | ################################################## 138 | ## Elastic Beanstalk config 139 | ################################################## 140 | module "eb_env" { 141 | source = "github.com/BasileTrujillo/terraform-elastic-beanstalk-php//eb-env" 142 | aws_region = "${var.aws_region}" 143 | 144 | # Application settings 145 | env = "${var.env}" 146 | service_name = "${var.service_name}" 147 | service_description = "My awesome php App" 148 | 149 | # PHP settings 150 | php_version = "7.0" 151 | document_root = "/public" 152 | memory_limit = "512M" 153 | zlib_php_compression = "Off" 154 | allow_url_fopen = "On" 155 | display_errors = "On" 156 | max_execution_time = "60" 157 | composer_options = "" 158 | 159 | # Instance settings 160 | instance_type = "t2.micro" 161 | min_instance = "2" 162 | max_instance = "4" 163 | 164 | # ELB 165 | enable_https = "false" # If set to true, you will need to add an ssl_certificate_id (see L70 in app/variables.tf) 166 | 167 | # Security 168 | vpc_id = "vpc-xxxxxxx" 169 | vpc_subnets = "subnet-xxxxxxx" 170 | elb_subnets = "subnet-xxxxxxx" 171 | security_groups = "sg-xxxxxxx" 172 | 173 | # EFS 174 | efs_id="${aws_efs_file_system.file_storage.id}" 175 | efs_mount_directory="/var/app/efs" 176 | } 177 | ``` 178 | 179 | * Finally, copy `.ebextensions/efs_mount.config` to your `.ebextensions` project directory and deploy using AWS EB CLI 180 | 181 | ### Example 182 | 183 | * Take a look at [example.tf](./example.tf) for an example with Elastic Beanstalk and Route53. 184 | * Take a look at [example_with_cloudfront.tf](./example_with_cloudfront.tf) for an example with Elastic Beanstalk, Cloudfront and Route53. 185 | 186 | ## Customize 187 | 188 | Many options are available through variables. Feel free to look into `variables.tf` inside each module to see all parameters you can setup. 189 | 190 | # Tips 191 | 192 | Elastic Beanstalk PHP Tips: 193 | 194 | * Install PDO DBLIB (PDO MSSQL Driver) for PHP 7.0: add the following lines to `.ebextensions/dblib.config` 195 | 196 | ```yaml 197 | packages: 198 | yum: 199 | freetds: [] 200 | freetds-devel: [] 201 | php70-pdo-dblib: [] 202 | ``` 203 | 204 | * Install PDO DBLIB (PDO MSSQL Driver) for PHP 5.6: add the following lines to `.ebextensions/dblib.config` 205 | 206 | ```yaml 207 | packages: 208 | yum: 209 | freetds: [] 210 | freetds-devel: [] 211 | php56-mssql: [] 212 | ``` 213 | 214 | ## Terraform related documentation 215 | 216 | * Elastic Beanstalk Application: https://www.terraform.io/docs/providers/aws/r/elastic_beanstalk_application.html 217 | * Elastic Beanstalk Environment: https://www.terraform.io/docs/providers/aws/r/elastic_beanstalk_environment.html 218 | * CloudFront: https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html 219 | * Route53: https://www.terraform.io/docs/providers/aws/d/route53_zone.html -------------------------------------------------------------------------------- /cloudfront/main.tf: -------------------------------------------------------------------------------- 1 | ################################################## 2 | ## AWS config 3 | ################################################## 4 | provider "aws" { 5 | region = "${var.aws_region}" 6 | } 7 | 8 | ################################################## 9 | ## S3 Bucket for CloudFront Logs 10 | ################################################## 11 | resource "aws_s3_bucket" "cf_log_bucket" { 12 | region = "${var.aws_region}" 13 | bucket = "${var.env}-${var.service_name}-cf-logs" 14 | acl = "log-delivery-write" 15 | 16 | lifecycle_rule { 17 | id = "log-rotation" 18 | prefix = "${var.log_prefix}" 19 | enabled = "${var.log_lifecycle_rule_enabled}" 20 | 21 | transition { 22 | days = "${var.log_standard_ia_retention_days}" 23 | storage_class = "STANDARD_IA" 24 | } 25 | 26 | transition { 27 | days = "${var.log_glacier_retention_days}" 28 | storage_class = "GLACIER" 29 | } 30 | 31 | expiration { 32 | days = "${var.log_expiration_days}" 33 | } 34 | } 35 | } 36 | 37 | ################################################## 38 | ## Cloudfront distribution 39 | ################################################## 40 | resource "aws_cloudfront_distribution" "app_cdn" { 41 | origin { 42 | domain_name = "${var.origin_domain_name}" 43 | origin_id = "${var.env}-${var.service_name}" 44 | 45 | custom_origin_config { 46 | http_port = "${var.custom_origin_http_port}" 47 | https_port = "${var.custom_origin_https_port}" 48 | origin_protocol_policy = "${var.custom_origin_protocol_policy}" 49 | origin_ssl_protocols = "${var.custom_origin_ssl_protocols}" 50 | } 51 | } 52 | 53 | aliases = ["${var.domain_name}"] 54 | enabled = "${var.enabled}" 55 | is_ipv6_enabled = "${var.is_ipv6_enabled}" 56 | comment = "${var.service_name} (${var.env})" 57 | 58 | logging_config { 59 | include_cookies = "${var.log_include_cookies}" 60 | bucket = "${aws_s3_bucket.cf_log_bucket.bucket_domain_name}" 61 | prefix = "${var.log_prefix}" 62 | } 63 | 64 | default_cache_behavior { 65 | allowed_methods = "${var.cache_allowed_methods}" 66 | cached_methods = "${var.cached_methods}" 67 | target_origin_id = "${var.env}-${var.service_name}" 68 | compress = "${var.cache_compress}" 69 | 70 | forwarded_values { 71 | // Query String Forwarding and Caching 72 | query_string = "${var.cache_forward_query_string}" 73 | 74 | cookies { // Forward Cookies 75 | forward = "${var.cache_forward_cookies}" 76 | } 77 | 78 | // Cache Based on Selected Request Headers 79 | headers = "${var.cache_forward_headers}" 80 | } 81 | 82 | viewer_protocol_policy = "${var.cache_viewer_protocol_policy}" 83 | min_ttl = "${var.cache_min_ttl}" 84 | default_ttl = "${var.cache_default_ttl}" 85 | max_ttl = "${var.cache_max_ttl}" 86 | } 87 | 88 | # https://aws.amazon.com/fr/cloudfront/pricing/ 89 | price_class = "${var.price_class}" 90 | 91 | restrictions { 92 | geo_restriction { 93 | restriction_type = "${var.geo_restriction_type}" 94 | locations = "${var.geo_restriction_locations}" 95 | } 96 | } 97 | 98 | tags { 99 | Name = "${var.env}-${var.service_name}" 100 | Environment = "${var.env}" 101 | } 102 | 103 | viewer_certificate { 104 | cloudfront_default_certificate = "${var.cloudfront_default_certificate}" 105 | acm_certificate_arn = "${var.ssl_certificate_id}" 106 | ssl_support_method = "${var.ssl_support_method}" 107 | minimum_protocol_version = "TLSv1" 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /cloudfront/outputs.tf: -------------------------------------------------------------------------------- 1 | ################################################## 2 | ## App Variables Output 3 | ################################################## 4 | output "cf_cname" { 5 | value = "${aws_cloudfront_distribution.app_cdn.domain_name}" 6 | } 7 | output "cf_hosted_zone_id" { 8 | value = "${aws_cloudfront_distribution.app_cdn.hosted_zone_id}" 9 | } 10 | -------------------------------------------------------------------------------- /cloudfront/variables.tf: -------------------------------------------------------------------------------- 1 | ################################################## 2 | ## App Variables 3 | ################################################## 4 | variable "aws_region" { 5 | type = "string" 6 | default = "eu-west-1" 7 | description = "The AWS Region" 8 | } 9 | 10 | # Application 11 | variable "service_name" { 12 | type = "string" 13 | description = "The application name" 14 | } 15 | variable "env" { 16 | type = "string" 17 | default = "dev" 18 | description = "The environment (dev, stage, prod)" 19 | } 20 | variable "enabled" { 21 | type = "string" 22 | default = "true" 23 | description = "Enable or disable cloudfront distribution." 24 | } 25 | variable "is_ipv6_enabled" { 26 | type = "string" 27 | default = "true" 28 | description = "Enable or disable IPv6" 29 | } 30 | 31 | ## Cloudfront settings 32 | variable "domain_name" { 33 | type = "string" 34 | description = "Final Domain name associated to cloudfront" 35 | } 36 | variable "origin_domain_name" { 37 | type = "string" 38 | description = "Origin Domain name (in our case, the EB CNAME)" 39 | } 40 | variable "custom_origin_http_port" { 41 | type = "string" 42 | default = "80" 43 | description = "Custom Origin HTTP Port" 44 | } 45 | variable "custom_origin_https_port" { 46 | type = "string" 47 | default = "443" 48 | description = "Custom Origin HTTPS Port" 49 | } 50 | variable "custom_origin_protocol_policy" { 51 | type = "string" 52 | default = "http-only" 53 | description = "Terminaison between cloudfront and the origin. One of http-only, https-only, or match-viewer." 54 | } 55 | variable "custom_origin_ssl_protocols" { 56 | type = "list" 57 | default = ["SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"] 58 | description = "The SSL/TLS protocols that you want CloudFront to use when communicating with your origin over HTTPS. A list of one or more of SSLv3, TLSv1, TLSv1.1, and TLSv1.2." 59 | } 60 | variable "price_class" { 61 | type = "string" 62 | default = "PriceClass_100" 63 | description = "The price class for this distribution. One of PriceClass_All, PriceClass_200, PriceClass_100" 64 | } 65 | 66 | 67 | ## Log settings 68 | variable "log_prefix" { 69 | type = "string" 70 | default = "log/" 71 | description = "S3 Bucket Prefix for loging" 72 | } 73 | variable "log_lifecycle_rule_enabled" { 74 | type = "string" 75 | default = "true" 76 | description = "Enable or disable lifecycle rule for log bucket" 77 | } 78 | variable "log_standard_ia_retention_days" { 79 | type = "string" 80 | default = "30" 81 | description = "Log lifecycle rule for Standard IA Retention days" 82 | } 83 | variable "log_glacier_retention_days" { 84 | type = "string" 85 | default = "60" 86 | description = "Log lifecycle rule for Glacier Retention days" 87 | } 88 | variable "log_expiration_days" { 89 | type = "string" 90 | default = "90" 91 | description = "Log lifecycle rule for expiration days" 92 | } 93 | variable "log_include_cookies" { 94 | type = "string" 95 | default = "false" 96 | description = "Enable or disable cookie loging" 97 | } 98 | 99 | # Default Cache Behavior 100 | variable "cache_allowed_methods" { 101 | type = "list" 102 | default = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] 103 | description = "Controls which HTTP methods CloudFront processes and forwards to your Amazon S3 bucket or your custom origin." 104 | } 105 | variable "cached_methods" { 106 | type = "list" 107 | default = ["GET", "HEAD"] 108 | description = "Controls whether CloudFront caches the response to requests using the specified HTTP methods." 109 | } 110 | variable "cache_compress" { 111 | type = "string" 112 | default = "true" 113 | description = "Whether you want CloudFront to automatically compress content for web requests that include Accept-Encoding: gzip in the request header (default: false)." 114 | } 115 | variable "cache_forward_query_string" { 116 | type = "string" 117 | default = "true" 118 | description = "Indicates whether you want CloudFront to forward query strings to the origin that is associated with this cache behavior." 119 | } 120 | variable "cache_forward_cookies" { 121 | type = "string" 122 | default = "all" 123 | description = "Specifies whether you want CloudFront to forward cookies to the origin that is associated with this cache behavior. You can specify all, none or whitelist. If whitelist, you must include the subsequent whitelisted_names" 124 | } 125 | variable "cache_forward_headers" { 126 | type = "list" 127 | default = [] 128 | description = "Specifies the Headers, if any, that you want CloudFront to vary upon for this cache behavior. Specify * to include all headers." 129 | } 130 | variable "cache_viewer_protocol_policy" { 131 | type = "string" 132 | default = "redirect-to-https" 133 | description = "Use this element to specify the protocol that users can use to access the files in the origin specified by TargetOriginId when a request matches the path pattern in PathPattern. One of allow-all, https-only, or redirect-to-https." 134 | } 135 | variable "cache_min_ttl" { 136 | type = "string" 137 | default = "0" 138 | description = "The minimum amount of time that you want objects to stay in CloudFront caches before CloudFront queries your origin to see whether the object has been updated." 139 | } 140 | variable "cache_max_ttl" { 141 | type = "string" 142 | default = "86400" # 24h 143 | description = "The maximum amount of time (in seconds) that an object is in a CloudFront cache before CloudFront forwards another request to your origin to determine whether the object has been updated. Only effective in the presence of Cache-Control max-age, Cache-Control s-maxage, and Expires headers." 144 | } 145 | variable "cache_default_ttl" { 146 | type = "string" 147 | default = "3600" # 1h 148 | description = "The default amount of time (in seconds) that an object is in a CloudFront cache before CloudFront forwards another request in the absence of an Cache-Control max-age or Expires header." 149 | } 150 | 151 | # Geo Restrictions 152 | variable "geo_restriction_type" { 153 | type = "string" 154 | default = "none" 155 | description = "The method that you want to use to restrict distribution of your content by country: none, whitelist, or blacklist." 156 | } 157 | variable "geo_restriction_locations" { 158 | type = "list" 159 | default = [] # http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm 160 | description = "The ISO 3166-1-alpha-2 codes for which you want CloudFront either to distribute your content (whitelist) or not distribute your content (blacklist)." 161 | } 162 | 163 | # SSL settings 164 | variable "cloudfront_default_certificate" { 165 | type = "string" 166 | default = "true" 167 | description = "true if you want viewers to use HTTPS to request your objects and you're using the CloudFront domain name for your distribution. Specify this, acm_certificate_arn, or iam_certificate_id." 168 | } 169 | variable "ssl_support_method" { 170 | type = "string" 171 | default = "sni-only" 172 | description = "Specifies how you want CloudFront to serve HTTPS requests. One of vip or sni-only. Required if you specify acm_certificate_arn or iam_certificate_id. NOTE: vip causes CloudFront to use a dedicated IP address and may incur extra charges." 173 | } 174 | variable "ssl_certificate_id" { 175 | type = "string" 176 | default = "" 177 | description = "ARN of an SSL certificate to bind to the listener." 178 | } 179 | variable "minimum_protocol_version" { 180 | type = "string" 181 | default = "TLSv1" 182 | description = "The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections. One of SSLv3 or TLSv1. Default: SSLv3. NOTE: If you are using a custom certificate (specified with acm_certificate_arn or iam_certificate_id), and have specified sni-only in ssl_support_method, TLSv1 must be specified." 183 | } -------------------------------------------------------------------------------- /eb-env/main.tf: -------------------------------------------------------------------------------- 1 | ################################################## 2 | ## AWS config 3 | ################################################## 4 | provider "aws" { 5 | region = "${var.aws_region}" 6 | } 7 | 8 | ################################################## 9 | ## IAM Roles and profiles 10 | ################################################## 11 | resource "aws_iam_instance_profile" "beanstalk_service" { 12 | name = "${var.service_name}-${var.env}-beanstalk-service-user" 13 | role = "${aws_iam_role.beanstalk_service.name}" 14 | } 15 | resource "aws_iam_instance_profile" "beanstalk_ec2" { 16 | name = "${var.service_name}-${var.env}-beanstalk-ec2-user" 17 | role = "${aws_iam_role.beanstalk_ec2.name}" 18 | } 19 | resource "aws_iam_role" "beanstalk_service" { 20 | name = "${var.service_name}-${var.env}-beanstalk-service-role" 21 | assume_role_policy = < eu-west-1 20 | description = "The Elastic Beanstalk Route53 Zone ID (related to the doc)" 21 | # http://docs.aws.amazon.com/general/latest/gr/rande.html#elasticbeanstalk_region 22 | } 23 | variable "eb_cname" { 24 | type = "string" 25 | description = "The Elastic Beanstalk CNAME" 26 | } 27 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | align-text@^0.1.1, align-text@^0.1.3: 6 | version "0.1.4" 7 | resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117" 8 | dependencies: 9 | kind-of "^3.0.2" 10 | longest "^1.0.1" 11 | repeat-string "^1.5.2" 12 | 13 | amdefine@>=0.0.4: 14 | version "1.0.1" 15 | resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" 16 | 17 | async@^1.4.0: 18 | version "1.5.2" 19 | resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" 20 | 21 | auto-changelog@^1.4.6: 22 | version "1.4.6" 23 | resolved "https://registry.yarnpkg.com/auto-changelog/-/auto-changelog-1.4.6.tgz#65d3c761c57dde7964e9ee550b27e45ca9772e56" 24 | dependencies: 25 | babel-polyfill "^6.26.0" 26 | commander "^2.9.0" 27 | fs-extra "^5.0.0" 28 | handlebars "^4.0.11" 29 | parse-github-url "^1.0.1" 30 | semver "^5.1.0" 31 | 32 | babel-polyfill@^6.26.0: 33 | version "6.26.0" 34 | resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153" 35 | dependencies: 36 | babel-runtime "^6.26.0" 37 | core-js "^2.5.0" 38 | regenerator-runtime "^0.10.5" 39 | 40 | babel-runtime@^6.26.0: 41 | version "6.26.0" 42 | resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" 43 | dependencies: 44 | core-js "^2.4.0" 45 | regenerator-runtime "^0.11.0" 46 | 47 | camelcase@^1.0.2: 48 | version "1.2.1" 49 | resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39" 50 | 51 | center-align@^0.1.1: 52 | version "0.1.3" 53 | resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad" 54 | dependencies: 55 | align-text "^0.1.3" 56 | lazy-cache "^1.0.3" 57 | 58 | cliui@^2.1.0: 59 | version "2.1.0" 60 | resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1" 61 | dependencies: 62 | center-align "^0.1.1" 63 | right-align "^0.1.1" 64 | wordwrap "0.0.2" 65 | 66 | commander@^2.9.0: 67 | version "2.15.1" 68 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" 69 | 70 | core-js@^2.4.0, core-js@^2.5.0: 71 | version "2.5.5" 72 | resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.5.tgz#b14dde936c640c0579a6b50cabcc132dd6127e3b" 73 | 74 | decamelize@^1.0.0: 75 | version "1.2.0" 76 | resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" 77 | 78 | fs-extra@^5.0.0: 79 | version "5.0.0" 80 | resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd" 81 | dependencies: 82 | graceful-fs "^4.1.2" 83 | jsonfile "^4.0.0" 84 | universalify "^0.1.0" 85 | 86 | graceful-fs@^4.1.2, graceful-fs@^4.1.6: 87 | version "4.1.11" 88 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" 89 | 90 | handlebars@^4.0.11: 91 | version "4.0.11" 92 | resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc" 93 | dependencies: 94 | async "^1.4.0" 95 | optimist "^0.6.1" 96 | source-map "^0.4.4" 97 | optionalDependencies: 98 | uglify-js "^2.6" 99 | 100 | is-buffer@^1.1.5: 101 | version "1.1.6" 102 | resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" 103 | 104 | jsonfile@^4.0.0: 105 | version "4.0.0" 106 | resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" 107 | optionalDependencies: 108 | graceful-fs "^4.1.6" 109 | 110 | kind-of@^3.0.2: 111 | version "3.2.2" 112 | resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" 113 | dependencies: 114 | is-buffer "^1.1.5" 115 | 116 | lazy-cache@^1.0.3: 117 | version "1.0.4" 118 | resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" 119 | 120 | longest@^1.0.1: 121 | version "1.0.1" 122 | resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" 123 | 124 | minimist@~0.0.1: 125 | version "0.0.10" 126 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" 127 | 128 | optimist@^0.6.1: 129 | version "0.6.1" 130 | resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" 131 | dependencies: 132 | minimist "~0.0.1" 133 | wordwrap "~0.0.2" 134 | 135 | parse-github-url@^1.0.1: 136 | version "1.0.2" 137 | resolved "https://registry.yarnpkg.com/parse-github-url/-/parse-github-url-1.0.2.tgz#242d3b65cbcdda14bb50439e3242acf6971db395" 138 | 139 | regenerator-runtime@^0.10.5: 140 | version "0.10.5" 141 | resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" 142 | 143 | regenerator-runtime@^0.11.0: 144 | version "0.11.1" 145 | resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" 146 | 147 | repeat-string@^1.5.2: 148 | version "1.6.1" 149 | resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" 150 | 151 | right-align@^0.1.1: 152 | version "0.1.3" 153 | resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef" 154 | dependencies: 155 | align-text "^0.1.1" 156 | 157 | semver@^5.1.0: 158 | version "5.5.0" 159 | resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" 160 | 161 | source-map@^0.4.4: 162 | version "0.4.4" 163 | resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b" 164 | dependencies: 165 | amdefine ">=0.0.4" 166 | 167 | source-map@~0.5.1: 168 | version "0.5.7" 169 | resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" 170 | 171 | uglify-js@^2.6: 172 | version "2.8.29" 173 | resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd" 174 | dependencies: 175 | source-map "~0.5.1" 176 | yargs "~3.10.0" 177 | optionalDependencies: 178 | uglify-to-browserify "~1.0.0" 179 | 180 | uglify-to-browserify@~1.0.0: 181 | version "1.0.2" 182 | resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7" 183 | 184 | universalify@^0.1.0: 185 | version "0.1.1" 186 | resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7" 187 | 188 | window-size@0.1.0: 189 | version "0.1.0" 190 | resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d" 191 | 192 | wordwrap@0.0.2: 193 | version "0.0.2" 194 | resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" 195 | 196 | wordwrap@~0.0.2: 197 | version "0.0.3" 198 | resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" 199 | 200 | yargs@~3.10.0: 201 | version "3.10.0" 202 | resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1" 203 | dependencies: 204 | camelcase "^1.0.2" 205 | cliui "^2.1.0" 206 | decamelize "^1.0.0" 207 | window-size "0.1.0" 208 | --------------------------------------------------------------------------------