Skip to content

Commit

Permalink
Resolve #3, environment variables'
Browse files Browse the repository at this point in the history
  • Loading branch information
o0th committed May 25, 2020
1 parent e31ea69 commit 7dffae3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
38 changes: 37 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
### mongo with efs

```hcl
module "mongo_efs" {
source = "github.com/clibot/terraform-aws-ecs-mongo"
name = "mongo-efs"
image = "docker.io/mongo:4.2.6"
cluster = aws_ecs_cluster.development.name
cpu = 256
memory = 512
volume_type = "efs"
vpc_id = module.develop_vpc.vpc_id
vpc_cidr = module.develop_vpc.vpc_cidr_block
subnets = [
module.develop_vpc.public_subnets[0],
module.develop_vpc.public_subnets[1],
module.develop_vpc.public_subnets[2]
]
}
```

### mongo with ebs

When using ebs the variable `volume_size` is required, default is `0`

```hcl
module "mongo_ebs" {
source = "github.com/clibot/terraform-aws-ecs-mongo"
Expand All @@ -26,7 +55,9 @@ module "mongo_ebs" {
}
```

### mongo with efs
### mongo with environment variables

Is it possible to specify environment variables to pass to the docker image, default is `[]`

```hcl
module "mongo_efs" {
Expand All @@ -50,5 +81,10 @@ module "mongo_efs" {
module.develop_vpc.public_subnets[1],
module.develop_vpc.public_subnets[2]
]
environment = [
{ name = "MONGO_INITDB_ROOT_USERNAME", value = "admin" },
{ name = "MONGO_INITDB_ROOT_PASSWORD", value = "asdomaresemperdomina" }
]
}
```
7 changes: 6 additions & 1 deletion container-definitions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"image": "${image}",
"cpu": ${cpu},
"memory": ${memory},
"environment": [],
"environment": [
%{ for variable in jsondecode(environment) ~}
{ "name": "${variable.name}", "value": "${variable.value}" },
%{ endfor ~}
{ "name": "_", "value": "_" }
],
"portMappings": [{
"containerPort": 27017,
"hostPort": 27017,
Expand Down
1 change: 1 addition & 0 deletions services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data "template_file" "container_definitions" {
memory = var.memory
volume_name = var.name
volume_path = "/data/db"
environment = jsonencode(var.environment)
logs_group = var.name
logs_stream_prefix = var.name
logs_region = data.aws_region.this.name
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ variable "volume_size" {
type = number
default = 0
}

variable "environment" {
type = list(object({ name = string, value = string }))
default = []
}

0 comments on commit 7dffae3

Please sign in to comment.