Skip to content

Commit

Permalink
Merge pull request #43 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 3.6.0 - Redis
  • Loading branch information
briskt authored Jul 16, 2021
2 parents d56410b + 625fb25 commit c71541b
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 3 deletions.
13 changes: 13 additions & 0 deletions aws/ecs/service-no-alb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This module is used to create an ECS service as well as task definition
- `service_env` - Name of environment, used in naming task definition. Ex: `staging`
- `container_def_json` - JSON for container definition.
- `desired_count` - Number of tasks to run in service
- `volumes` - A list of volume definitions in JSON format that containers in your task may use

### Optional Inputs

Expand Down Expand Up @@ -41,5 +42,17 @@ module "ecsservice" {
service_env = "${var.app_env}"
container_def_json = "${file("task-definition.json")}"
desired_count = 2
volumes = [
{
name = "vol_name"
efs_volume_configuration = [
{
file_system_id = aws_efs_file_system.vol_name.id
root_directory = "/"
},
]
},
]
}
```
27 changes: 27 additions & 0 deletions aws/ecs/service-no-alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ resource "aws_ecs_task_definition" "td" {
container_definitions = var.container_def_json
task_role_arn = var.task_role_arn
network_mode = var.network_mode

dynamic "volume" {
for_each = var.volumes
content {
host_path = lookup(volume.value, "host_path", null)
name = volume.value.name

dynamic "docker_volume_configuration" {
for_each = lookup(volume.value, "docker_volume_configuration", [])
content {
autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null)
driver = lookup(docker_volume_configuration.value, "driver", null)
driver_opts = lookup(docker_volume_configuration.value, "driver_opts", null)
labels = lookup(docker_volume_configuration.value, "labels", null)
scope = lookup(docker_volume_configuration.value, "scope", null)
}
}

dynamic "efs_volume_configuration" {
for_each = lookup(volume.value, "efs_volume_configuration", [])
content {
file_system_id = lookup(efs_volume_configuration.value, "file_system_id", null)
root_directory = lookup(efs_volume_configuration.value, "root_directory", null)
}
}
}
}
}

/*
Expand Down
6 changes: 6 additions & 0 deletions aws/ecs/service-no-alb/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ variable "desired_count" {
type = string
}

variable "volumes" {
default = []
description = "A list of volume definitions in JSON format that containers in your task may use"
type = list(any)
}

/*
* Optional Variables
*/
Expand Down
2 changes: 1 addition & 1 deletion aws/elasticache/memcache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This module is used to create an Elasticache cluster of memcache servers

## Required Inputs

- `cluster_id` - ID/Name for Elasticache Cluster
- `cluster_id` - ID/Name for Elasticache Cluster. Max 20 characters.
- `security_group_ids` - List of security group IDs to place cluster in
- `subnet_group_name` - Name of subnet group to create and place cluster in.
- `subnet_ids` - List of subnet ids for subnet group.
Expand Down
3 changes: 1 addition & 2 deletions aws/elasticache/memcache/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "aws_elasticache_subnet_group" "memcache_subnet_group" {
* Create Cluster
*/
resource "aws_elasticache_cluster" "memcache" {
cluster_id = replace(var.cluster_id, "/(.{0,20})(.*)/", "$1")
cluster_id = replace(var.cluster_id, "/(.{0,20})(.*)/", "$1") // truncates to maximum of 20 characters
engine = "memcached"
node_type = var.node_type
port = var.port
Expand All @@ -25,4 +25,3 @@ resource "aws_elasticache_cluster" "memcache" {
app_env = var.app_env
}
}

45 changes: 45 additions & 0 deletions aws/elasticache/redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# aws/ecs/elasticache/redis - Create a Elasticache cluster of Redis servers
This module is used to create an Elasticache cluster of Redis servers

## What this does

- Create Elasticache subnet group spanning all provided `var.subnet_ids`.
- Create Elasticache cluster of Redis servers.

## Required Inputs

- `cluster_id` - ID/Name for Elasticache Cluster. Max 20 characters.
- `security_group_ids` - List of security group IDs to place cluster in
- `subnet_group_name` - Name of subnet group to create and place cluster in.
- `subnet_ids` - List of subnet ids for subnet group.
- `availability_zones` - List of availability zones to place cluster in.
- `app_name` - Application name to be tagged to cluster as `app_name`.
- `app_env` - Application environment to be tagged to cluster as `app_env`.

### Optional Inputs

- `node_type` - Instance node type. Default: `cache.t2.micro`
- `port` - Redis port. Default: `6379`
- `parameter_group_name` - Name of Redis parameter group to use. Default: `default.redisd1.4`
- `engine_version` - Redis engine version. Default: `6.x`'

## Outputs

- `cache_nodes` - List of cache nodes.
- `configuration_endpoint` - Redis configuration endpoint.
- `cluster_address` - DNS name for cache clusters without port.

## Usage Example

```hcl
module "redis" {
source = "github.com/silinternational/terraform-modules//aws/elasticache/redis"
cluster_id = "doorman-cache"
security_group_ids = [module.vpc.vpc_default_sg_id]
subnet_group_name = "doorman-cache-subnet"
subnet_ids = module.vpc.private_subnet_ids
availability_zones = module.vpc.aws_zones
app_name = "doorman"
app_env = "staging"
}
```
27 changes: 27 additions & 0 deletions aws/elasticache/redis/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Create Elasticache subnet group
*/
resource "aws_elasticache_subnet_group" "redis_subnet_group" {
name = var.subnet_group_name
subnet_ids = var.subnet_ids
}

/*
* Create Cluster
*/
resource "aws_elasticache_cluster" "redis" {
cluster_id = replace(var.cluster_id, "/(.{0,20})(.*)/", "$1") // truncates to maximum of 20 characters
engine = "redis"
engine_version = var.engine_version
node_type = var.node_type
port = var.port
num_cache_nodes = "1"
parameter_group_name = var.parameter_group_name
security_group_ids = var.security_group_ids
subnet_group_name = aws_elasticache_subnet_group.redis_subnet_group.name

tags = {
app_name = var.app_name
app_env = var.app_env
}
}
15 changes: 15 additions & 0 deletions aws/elasticache/redis/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Cluster outputs
*/
output "cache_nodes" {
value = aws_elasticache_cluster.redis.cache_nodes
}

output "configuration_endpoint" {
value = aws_elasticache_cluster.redis.configuration_endpoint
}

output "cluster_address" {
value = aws_elasticache_cluster.redis.cluster_address
}

52 changes: 52 additions & 0 deletions aws/elasticache/redis/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Required Variables
*/
variable "cluster_id" {
type = string
}

variable "security_group_ids" {
type = list(string)
}

variable "subnet_group_name" {
type = string
}

variable "subnet_ids" {
type = list(string)
}

variable "availability_zones" {
type = list(string)
}

variable "app_name" {
type = string
}

variable "app_env" {
type = string
}

/*
* Optional Variables
*/
variable "node_type" {
type = string
default = "cache.t2.micro"
}

variable "port" {
type = string
default = "6379"
}

variable "parameter_group_name" {
type = string
default = "default.redis6.x"
}

variable "engine_version" {
default = "6.x"
}
4 changes: 4 additions & 0 deletions aws/elasticache/redis/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit c71541b

Please sign in to comment.