Skip to content

Commit a2754ef

Browse files
bhegazyaknysh
authored andcommitted
Add Loadbalancer stickiness option (cloudposse#84)
* add lb stickiness options * add variables for stickiness options * update stickiness options in readme * add stickiness option * remove lb_cookie from default values * Revert "remove lb_cookie from default values" This reverts commit add7a91. * remove stickiness type value * add stickiness settings for classic lb * remove policy name from stickiness option * test remove alb stickiness config * Revert "test remove alb stickiness config" This reverts commit 44a15d4. * remove stickiness type option
1 parent f1aa553 commit a2754ef

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Available targets:
128128
| ssh_listener_port | SSH port | string | `22` | no |
129129
| ssh_source_restriction | Used to lock down SSH access to the EC2 instances. | string | `0.0.0.0/0` | no |
130130
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | - | yes |
131+
| stickiness_enabled | Set to true to enable sticky sessions. This option is only applicable to environments with a classic load balancer or an application load balancer. | string | `false` | no |
132+
| stickiness_lb_cookie_duration | Lifetime, in seconds, of the sticky session cookie. This option is only applicable to environments with a classic load balancer or an application load balancer. | string | `86400` | no |
131133
| tags | Additional tags (e.g. `map('BusinessUnit`,`XYZ`) | map | `<map>` | no |
132134
| tier | Elastic Beanstalk Environment tier, e.g. ('WebServer', 'Worker') | string | `WebServer` | no |
133135
| update_level | The highest level of update to apply with managed platform updates | string | `minor` | no |

docs/terraform.md

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
| ssh_listener_port | SSH port | string | `22` | no |
6666
| ssh_source_restriction | Used to lock down SSH access to the EC2 instances. | string | `0.0.0.0/0` | no |
6767
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | - | yes |
68+
| stickiness_enabled | Set to true to enable sticky sessions. This option is only applicable to environments with a classic load balancer or an application load balancer. | string | `false` | no |
69+
| stickiness_lb_cookie_duration | Lifetime, in seconds, of the sticky session cookie. This option is only applicable to environments with a classic load balancer or an application load balancer. | string | `86400` | no |
6870
| tags | Additional tags (e.g. `map('BusinessUnit`,`XYZ`) | map | `<map>` | no |
6971
| tier | Elastic Beanstalk Environment tier, e.g. ('WebServer', 'Worker') | string | `WebServer` | no |
7072
| update_level | The highest level of update to apply with managed platform updates | string | `minor` | no |

main.tf

+23
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,29 @@ resource "aws_elastic_beanstalk_environment" "default" {
998998
name = "Protocol"
999999
value = "HTTP"
10001000
}
1001+
###===================== Load Balancer stickiness settings =====================================================###
1002+
setting {
1003+
namespace = "aws:elasticbeanstalk:environment:process:default"
1004+
name = "StickinessEnabled"
1005+
value = "${var.stickiness_enabled}"
1006+
}
1007+
setting {
1008+
namespace = "aws:elasticbeanstalk:environment:process:default"
1009+
name = "StickinessLBCookieDuration"
1010+
value = "${var.stickiness_lb_cookie_duration}"
1011+
}
1012+
# This should make it work with Classic Load balancer
1013+
# https://github.com/terraform-providers/terraform-provider-aws/issues/4000
1014+
setting {
1015+
namespace = "aws:elb:policies"
1016+
name = "Stickiness Policy"
1017+
value = "${var.stickiness_enabled}"
1018+
}
1019+
setting {
1020+
namespace = "aws:elb:policies"
1021+
name = "Stickiness Cookie Expiration"
1022+
value = "${var.stickiness_lb_cookie_duration}"
1023+
}
10011024

10021025
###===================== Notification =====================================================###
10031026

variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ variable "application_port" {
142142
description = "Port application is listening on"
143143
}
144144

145+
variable "stickiness_enabled" {
146+
default = "false"
147+
description = "Set to true to enable sticky sessions"
148+
}
149+
150+
variable "stickiness_lb_cookie_duration" {
151+
default = "86400"
152+
description = "Lifetime, in seconds, of the sticky session cookie"
153+
}
154+
145155
variable "ssh_listener_enabled" {
146156
default = "false"
147157
description = "Enable ssh port"

0 commit comments

Comments
 (0)