Skip to content

Commit 4a1923f

Browse files
authored
Add env_vars variable (#94)
1 parent fe6d0d7 commit 4a1923f

File tree

7 files changed

+32
-21
lines changed

7 files changed

+32
-21
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ Available targets:
183183
| enable_log_publication_control | Copy the log files for your application's Amazon EC2 instances to the Amazon S3 bucket associated with your application | bool | `false` | no |
184184
| enable_stream_logs | Whether to create groups in CloudWatch Logs for proxy and deployment logs, and stream logs from each instance in your environment | bool | `false` | no |
185185
| enhanced_reporting_enabled | Whether to enable "enhanced" health reporting for this environment. If false, "basic" reporting is used. When you set this to false, you must also set `enable_managed_actions` to false | bool | `true` | no |
186+
| env_vars | Map of custom ENV variables to be provided to the application running on Elastic Beanstalk, e.g. env_vars = { DB_USER = 'admin' DB_PASS = 'xxxxxx' } | map(string) | `<map>` | no |
186187
| environment_type | Environment type, e.g. 'LoadBalanced' or 'SingleInstance'. If setting to 'SingleInstance', `rolling_update_type` must be set to 'Time', `updating_min_in_service` must be set to 0, and `loadbalancer_subnets` will be unused (it applies to the ELB, which does not exist in SingleInstance environments) | string | `LoadBalanced` | no |
187188
| force_destroy | Force destroy the S3 bucket for load balancer logs | bool | `false` | no |
188189
| health_streaming_delete_on_terminate | Whether to delete the log group when the environment is terminated. If false, the health data is kept RetentionInDays days. | bool | `false` | no |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| enable_log_publication_control | Copy the log files for your application's Amazon EC2 instances to the Amazon S3 bucket associated with your application | bool | `false` | no |
2828
| enable_stream_logs | Whether to create groups in CloudWatch Logs for proxy and deployment logs, and stream logs from each instance in your environment | bool | `false` | no |
2929
| enhanced_reporting_enabled | Whether to enable "enhanced" health reporting for this environment. If false, "basic" reporting is used. When you set this to false, you must also set `enable_managed_actions` to false | bool | `true` | no |
30+
| env_vars | Map of custom ENV variables to be provided to the application running on Elastic Beanstalk, e.g. env_vars = { DB_USER = 'admin' DB_PASS = 'xxxxxx' } | map(string) | `<map>` | no |
3031
| environment_type | Environment type, e.g. 'LoadBalanced' or 'SingleInstance'. If setting to 'SingleInstance', `rolling_update_type` must be set to 'Time', `updating_min_in_service` must be set to 0, and `loadbalancer_subnets` will be unused (it applies to the ELB, which does not exist in SingleInstance environments) | string | `LoadBalanced` | no |
3132
| force_destroy | Force destroy the S3 bucket for load balancer logs | bool | `false` | no |
3233
| health_streaming_delete_on_terminate | Whether to delete the log group when the environment is terminated. If false, the health data is kept RetentionInDays days. | bool | `false` | no |

examples/complete/fixtures.us-east-2.tfvars

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,12 @@ additional_settings = [
8080
namespace = "aws:elasticbeanstalk:managedactions"
8181
name = "ManagedActionsEnabled"
8282
value = "false"
83-
},
84-
// Environment variables
85-
{
86-
namespace = "aws:elasticbeanstalk:application:environment"
87-
name = "DB_HOST"
88-
value = "xxxxxxxxxxxxxx"
89-
},
90-
{
91-
namespace = "aws:elasticbeanstalk:application:environment"
92-
name = "DB_USERNAME"
93-
value = "yyyyyyyyyyyyy"
94-
},
95-
{
96-
namespace = "aws:elasticbeanstalk:application:environment"
97-
name = "DB_PASSWORD"
98-
value = "zzzzzzzzzzzzzzzzzzz"
99-
},
100-
{
101-
namespace = "aws:elasticbeanstalk:application:environment"
102-
name = "ANOTHER_ENV_VAR"
103-
value = "123456789"
10483
}
10584
]
85+
86+
env_vars = {
87+
"DB_HOST" = "xxxxxxxxxxxxxx"
88+
"DB_USERNAME" = "yyyyyyyyyyyyy"
89+
"DB_PASSWORD" = "zzzzzzzzzzzzzzzzzzz"
90+
"ANOTHER_ENV_VAR" = "123456789"
91+
}

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ module "elastic_beanstalk_environment" {
9494
solution_stack_name = var.solution_stack_name
9595

9696
additional_settings = var.additional_settings
97+
env_vars = var.env_vars
9798
}

examples/complete/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,9 @@ variable "additional_settings" {
196196
description = "Additional Elastic Beanstalk setttings. For full list of options, see https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html"
197197
default = []
198198
}
199+
200+
variable "env_vars" {
201+
type = map(string)
202+
default = {}
203+
description = "Map of custom ENV variables to be provided to the application running on Elastic Beanstalk, e.g. env_vars = { DB_USER = 'admin' DB_PASS = 'xxxxxx' }"
204+
}

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,16 @@ resource "aws_elastic_beanstalk_environment" "default" {
772772
value = setting.value.value
773773
}
774774
}
775+
776+
// Add environment variables if provided
777+
dynamic "setting" {
778+
for_each = var.env_vars
779+
content {
780+
namespace = "aws:elasticbeanstalk:application:environment"
781+
name = setting.key
782+
value = setting.value
783+
}
784+
}
775785
}
776786

777787
data "aws_elb_service_account" "main" {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ variable "additional_settings" {
381381
description = "Additional Elastic Beanstalk setttings. For full list of options, see https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html"
382382
}
383383

384+
variable "env_vars" {
385+
type = map(string)
386+
default = {}
387+
description = "Map of custom ENV variables to be provided to the application running on Elastic Beanstalk, e.g. env_vars = { DB_USER = 'admin' DB_PASS = 'xxxxxx' }"
388+
}
389+
384390
# From: http://docs.aws.amazon.com/general/latest/gr/rande.html#elasticbeanstalk_region
385391
# Via: https://github.com/hashicorp/terraform/issues/7071
386392
variable "alb_zone_id" {

0 commit comments

Comments
 (0)