Skip to content

Commit

Permalink
feat: Add support for choosing between a "Public" and an "Internal" L…
Browse files Browse the repository at this point in the history
…oad Balancer when deploying an Elastic Beanstalk application into a VPC
  • Loading branch information
ashovlin committed Jun 24, 2024
1 parent 2c676af commit 8fb4de8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public partial class Configuration
/// </summary>
public string LoadBalancerType { get; set; } = Recipe.LOADBALANCERTYPE_APPLICATION;

/// <summary>
/// Whether the load balancer is visibile to the public internet ("public") or only to the connected VPC ("internal").
/// </summary>
public string LoadBalancerScheme { get; set; } = Recipe.LOADBALANCERSCHEME_PUBLIC;

/// <summary>
/// The EC2 Key Pair used for the Beanstalk Application.
/// </summary>
Expand Down Expand Up @@ -131,7 +136,8 @@ public Configuration(
string loadBalancerType = Recipe.LOADBALANCERTYPE_APPLICATION,
string reverseProxy = Recipe.REVERSEPROXY_NGINX,
bool xrayTracingSupportEnabled = false,
string enhancedHealthReporting = Recipe.ENHANCED_HEALTH_REPORTING)
string enhancedHealthReporting = Recipe.ENHANCED_HEALTH_REPORTING,
string loadBalancerScheme = Recipe.LOADBALANCERSCHEME_PUBLIC)
{
ApplicationIAMRole = applicationIAMRole;
ServiceIAMRole = serviceIAMRole;
Expand All @@ -146,6 +152,7 @@ public Configuration(
VPC = vpc;
EnvironmentType = environmentType;
LoadBalancerType = loadBalancerType;
LoadBalancerScheme = loadBalancerScheme;
XRayTracingSupportEnabled = xrayTracingSupportEnabled;
ReverseProxy = reverseProxy;
EnhancedHealthReporting = enhancedHealthReporting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Recipe : Construct
public const string ENVIRONMENTTYPE_LOADBALANCED = "LoadBalanced";

public const string LOADBALANCERTYPE_APPLICATION = "application";
public const string LOADBALANCERSCHEME_PUBLIC = "public";

public const string REVERSEPROXY_NGINX = "nginx";

Expand Down Expand Up @@ -249,14 +250,19 @@ private void ConfigureBeanstalkEnvironment(Configuration settings, string beanst

if (settings.EnvironmentType.Equals(ENVIRONMENTTYPE_LOADBALANCED))
{
optionSettingProperties.Add(
new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:environment",
OptionName = "LoadBalancerType",
Value = settings.LoadBalancerType
}
);
optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:elasticbeanstalk:environment",
OptionName = "LoadBalancerType",
Value = settings.LoadBalancerType
});

optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:ec2:vpc",
OptionName = "ELBScheme",
Value = settings.LoadBalancerScheme
});

if (!string.IsNullOrEmpty(settings.HealthCheckURL))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public partial class Configuration
/// </summary>
public string LoadBalancerType { get; set; } = Recipe.LOADBALANCERTYPE_APPLICATION;

/// <summary>
/// Whether the load balancer is visibile to the public internet ("public") or only to the connected VPC ("internal").
/// </summary>
public string LoadBalancerScheme { get; set; } = Recipe.LOADBALANCERSCHEME_PUBLIC;

/// <summary>
/// The EC2 Key Pair used for the Beanstalk Application.
/// </summary>
Expand Down Expand Up @@ -135,7 +140,8 @@ public Configuration(
string environmentType = Recipe.ENVIRONMENTTYPE_SINGLEINSTANCE,
string loadBalancerType = Recipe.LOADBALANCERTYPE_APPLICATION,
bool xrayTracingSupportEnabled = false,
string enhancedHealthReporting = Recipe.ENHANCED_HEALTH_REPORTING)
string enhancedHealthReporting = Recipe.ENHANCED_HEALTH_REPORTING,
string loadBalancerScheme = Recipe.LOADBALANCERSCHEME_PUBLIC)
{
ApplicationIAMRole = applicationIAMRole;
ServiceIAMRole = serviceIAMRole;
Expand All @@ -150,6 +156,7 @@ public Configuration(
VPC = vpc;
EnvironmentType = environmentType;
LoadBalancerType = loadBalancerType;
LoadBalancerScheme = loadBalancerScheme;
XRayTracingSupportEnabled = xrayTracingSupportEnabled;
EnhancedHealthReporting = enhancedHealthReporting;
HealthCheckURL = healthCheckURL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Recipe : Construct
public const string ENVIRONMENTTYPE_LOADBALANCED = "LoadBalanced";

public const string LOADBALANCERTYPE_APPLICATION = "application";
public const string LOADBALANCERSCHEME_PUBLIC = "public";

public const string REVERSEPROXY_NGINX = "nginx";

Expand Down Expand Up @@ -258,6 +259,13 @@ private void ConfigureBeanstalkEnvironment(Configuration settings, string beanst
}
);

optionSettingProperties.Add(new CfnEnvironment.OptionSettingProperty
{
Namespace = "aws:ec2:vpc",
OptionName = "ELBScheme",
Value = settings.LoadBalancerScheme
});

if (!string.IsNullOrEmpty(settings.HealthCheckURL))
{
optionSettingProperties.Add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
},
{
"Id": "LoadBalancer",
"DisplayName": "LoadBalancer",
"DisplayName": "Load Balancer",
"Order": 70
},
{
Expand Down Expand Up @@ -302,6 +302,34 @@
"AdvancedSetting": true,
"Updatable": true
},
{
"Id": "LoadBalancerScheme",
"Name": "Load Balancer Scheme",
"Category": "LoadBalancer",
"Description": "Specify \"Internal\" if your application serves requests only from connected VPCs. Public load balancers serve requests from the Internet.",
"Type": "String",
"DefaultValue": "public",
"AllowedValues": [
"public",
"internal"
],
"ValueMapping": {
"public": "Public",
"internal": "Internal"
},
"DependsOn": [
{
"Id": "EnvironmentType",
"Value": "LoadBalanced"
},
{
"Id": "VPC.UseVPC",
"Value": true
}
],
"AdvancedSetting": true,
"Updatable": true
},
{
"Id": "ApplicationIAMRole",
"Name": "Application IAM Role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
},
{
"Id": "LoadBalancer",
"DisplayName": "LoadBalancer",
"DisplayName": "Load Balancer",
"Order": 70
},
{
Expand Down Expand Up @@ -291,6 +291,34 @@
"AdvancedSetting": true,
"Updatable": true
},
{
"Id": "LoadBalancerScheme",
"Name": "Load Balancer Scheme",
"Category": "LoadBalancer",
"Description": "Specify \"Internal\" if your application serves requests only from connected VPCs. Public load balancers serve requests from the Internet.",
"Type": "String",
"DefaultValue": "public",
"AllowedValues": [
"public",
"internal"
],
"ValueMapping": {
"public": "Public",
"internal": "Internal"
},
"DependsOn": [
{
"Id": "EnvironmentType",
"Value": "LoadBalanced"
},
{
"Id": "VPC.UseVPC",
"Value": true
}
],
"AdvancedSetting": true,
"Updatable": true
},
{
"Id": "ApplicationIAMRole",
"Name": "Application IAM Role",
Expand Down

0 comments on commit 8fb4de8

Please sign in to comment.