Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions templates/kubernetes/terraform/environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ module "kubernetes" {

notification_service_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
notification_service_highly_available = true

cache_store = "<% index .Params `cacheStore` %>"
}
2 changes: 2 additions & 0 deletions templates/kubernetes/terraform/environments/stage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ module "kubernetes" {

notification_service_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
notification_service_highly_available = false

cache_store = "<% index .Params `cacheStore` %>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
data "aws_elasticache_replication_group" "redis" {
count = var.cache_store == "redis" ? 1 : 0

replication_group_id = "${var.project}-${var.environment}-redis"
}

data "aws_elasticache_cluster" "memcached" {
count = var.cache_store == "memcached" ? 1 : 0

cluster_id = "${var.project}-${var.environment}-memcached"
}

locals {
endpoint_address = var.cache_store == "redis" ? data.aws_elasticache_replication_group.redis[0].primary_endpoint_address : var.cache_store == "memcached" ? data.aws_elasticache_cluster.memcached[0].cluster_address : ""
}

resource "kubernetes_service" "app_cache" {
count = local.endpoint_address == "" ? 0 : 1

## this should match the deployable backend's name/namespace
metadata {
namespace = kubernetes_namespace.app_namespace.metadata[0].name
name = "cache-${var.cache_store}"
}
spec {
type = "ExternalName"
external_name = local.endpoint_address
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ variable "notification_service_highly_available" {
type = bool
default = true
}

variable "cache_store" {
description = "Cache store - redis or memcached"
type = string
default = "none"
}
9 changes: 9 additions & 0 deletions templates/terraform/environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ module "prod" {
sendgrid_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
sendgrid_api_key_secret_name = "${local.project}-sendgrid-<% index .Params `randomSeed` %>"

# Cache configuration
## you may define "redis" or "memcached" as your cache store. If you define "none", there will be no cache service launched.
## Check https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/SelectEngine.html to compare redis or memcached.
cache_store = "<% index .Params `cacheStore` %>"

## See how to define node and instance type: https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/nodes-select-size.html
cache_cluster_size = 1
cache_instance_type = "cache.r6g.large"

# Roles configuration
roles = [
{
Expand Down
9 changes: 9 additions & 0 deletions templates/terraform/environments/stage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ module "stage" {
sendgrid_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
sendgrid_api_key_secret_name = "${local.project}-sendgrid-<% index .Params `randomSeed` %>"

# Cache configuration
## you may define "redis" or "memcached" as your cache store. If you define "none", there will be no cache service launched.
## Check https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/SelectEngine.html to compare redis or memcached.
cache_store = "<% index .Params `cacheStore` %>"

Comment thread
sshi100 marked this conversation as resolved.
## See how to define node and instance type: https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/nodes-select-size.html
cache_cluster_size = 1
cache_instance_type = "cache.t2.micro"

# Roles configuration
roles = [
{
Expand Down
21 changes: 21 additions & 0 deletions templates/terraform/modules/environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,27 @@ module "user_access" {
users = local.user_access_users
}

module "cache" {
Comment thread
bmonkman marked this conversation as resolved.
count = var.cache_store == "none" ? 0 : 1

source = "commitdev/zero/aws//modules/cache"
version = "0.1.16"

project = var.project
environment = var.environment

cache_store = var.cache_store

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

cluster_size = var.cache_cluster_size
instance_type = var.cache_instance_type
availability_zones = module.vpc.azs
security_groups = [module.eks.worker_security_group_id]

redis_transit_encryption_enabled = var.cache_redis_transit_encryption_enabled
}

output "s3_hosting" {
description = "used by access policy for s3 hosting bucket"
Expand Down
24 changes: 24 additions & 0 deletions templates/terraform/modules/environment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,27 @@ variable "ci_user_name" {
type = string
description = "CI user name"
}

variable "cache_instance_type" {
type = string
default = "cache.t2.micro"
description = "Elastic cache instance type"
}

variable "cache_cluster_size" {
type = number
default = 1
description = "Number of nodes in cluster"
}

variable "cache_store" {
type = string
default = "none"
Comment thread
bmonkman marked this conversation as resolved.
description = "Cache store - redis or memcached"
}

variable "cache_redis_transit_encryption_enabled" {
description = "Enable TLS for redis traffic. When this is enabled, your application needs to handle TLS connection. Note: redis-cli can not handle TLS."
type = bool
default = true
}
6 changes: 6 additions & 0 deletions zero-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ parameters:
options:
- "postgres"
- "mysql"
- field: cacheStore
label: "Cache store to use (default: no cache)"
options:
- "none"
- "redis"
- "memcached"
- field: loggingType
label: Application logging to configure. Cloudwatch is cheaper with a more limited feature set. Elasticsearch + Kibana will set up more infrastructure but enable a much richer logging search and visualization experience.
options:
Expand Down