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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ which describes the environment mapped in this [architecture diagram][arch-diagr
- [A domain registered with Route53][aws-route53]
- Note: if you want to use different domain per environment (staging/production), you need to have multiple hosted zones. The available zones in Route53 can be found by running this command. `aws route53 list-hosted-zones`

_Optional Prerequisites_
- [Sendgrid account][sendgrid] with developer [API key][sendgrid-apikey]: this will enable transactional email sending with simple API calls.

## Getting Started

This is meant to be used with the `zero` tool and not directly. See
Expand Down Expand Up @@ -73,3 +76,5 @@ Project board: [zenhub][zenhub-board]
[aws-cli]: https://docs.aws.amazon.com/polly/latest/dg/setup-aws-cli.html
[aws-route53]: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-register.html
[zenhub-board]: https://app.zenhub.com/workspaces/commit-zero-5da8decc7046a60001c6db44/board?filterLogic=any&repos=203630543,247773730,257676371,258369081
[sendgrid]: https://signup.sendgrid.com
[sendgrid-apikey]: https://app.sendgrid.com/settings/api_keys
1 change: 1 addition & 0 deletions templates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ teardown-secrets:
export AWS_PAGER='' && export AWS_DEFAULT_REGION=<% index .Params `region` %> && \
aws secretsmanager list-secrets --region <% index .Params `region` %> --query "SecretList[?Tags[?Key=='project' && Value=='$(PROJECT)']].[Name] | [0][0]" | xargs aws secretsmanager delete-secret --region <% index .Params `region` %> --secret-id && \
aws secretsmanager list-secrets --region <% index .Params `region` %> --query "SecretList[?Tags[?Key=='rds' && Value=='$(PROJECT)-$(ENVIRONMENT)']].[Name] | [0][0]" | xargs aws secretsmanager delete-secret --region <% index .Params `region` %> --secret-id && \
aws secretsmanager list-secrets --region <% index .Params `region` %> --query "SecretList[?Tags[?Key=='sendgrid' && Value=='$(PROJECT)']].[Name] | [0][0]" | xargs aws secretsmanager delete-secret --region <% index .Params `region` %> --secret-id && \
aws iam delete-access-key --user-name $(PROJECT)-ci-user --access-key-id $(shell aws iam list-access-keys --user-name $(PROJECT)-ci-user --query "AccessKeyMetadata[0].AccessKeyId" | sed 's/"//g') && \
aws iam delete-user --user-name $(PROJECT)-ci-user

Expand Down
8 changes: 8 additions & 0 deletions templates/terraform/bootstrap/secrets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ module "rds_master_secret_prod" {
random_length = 32
tags = map("rds", "${local.project}-prod")
}

module "sendgrid_api_key" {
source = "../../modules/secret"
name = "${local.project}-sendgrid-<% index .Params `randomSeed` %>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes the same api key will be shared for both staging / production, which I think is probably fine for now.

type = "string"
value = "<% index .Params `sendgridApiKey` %>"
tags = map("sendgrid", local.project)
}
3 changes: 3 additions & 0 deletions templates/terraform/environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ module "prod" {
<% if ne (index .Params `loggingType`) "kibana" %># <% end %>logging_es_instance_count = "2" # Must be a mulitple of the az count
<% if ne (index .Params `loggingType`) "kibana" %># <% end %>logging_volume_size_in_gb = "50" # Maximum value is limited by the instance type
# See https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-limits.html

sendgrid_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
sendgrid_api_key_secret_name = "<% .Name %>-sendgrid-<% index .Params `randomSeed` %>"
}
3 changes: 3 additions & 0 deletions templates/terraform/environments/stage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ module "stage" {
<% if ne (index .Params `loggingType`) "kibana" %># <% end %>logging_es_instance_count = "1" # Must be a mulitple of the az count
<% if ne (index .Params `loggingType`) "kibana" %># <% end %>logging_volume_size_in_gb = "10" # Maximum value is limited by the instance type
# See https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-limits.html

sendgrid_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
sendgrid_api_key_secret_name = "<% .Name %>-sendgrid-<% index .Params `randomSeed` %>"
}
9 changes: 9 additions & 0 deletions templates/terraform/modules/environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,12 @@ module "logging" {
ebs_volume_size_in_gb = var.logging_volume_size_in_gb
create_service_role = var.logging_create_service_role
}

module "sendgrid" {
source = "commitdev/zero/aws//modules/sendgrid"
version = "0.0.2"
count = var.sendgrid_enabled ? 1 : 0

zone_name = var.domain_name
sendgrid_api_key_secret_name = var.sendgrid_api_key_secret_name
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost all the logic has been moved to commitdev/terraform-aws-zero@bd194a0 with the external-datasource 🎉

}
10 changes: 10 additions & 0 deletions templates/terraform/modules/environment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,13 @@ variable "enable_cluster_logging" {
type = bool
default = false
}

variable "sendgrid_enabled" {
description = "If enabled, creates route53 entries for domain authentication"
type = bool
}

variable "sendgrid_api_key_secret_name" {
description = "AWS secret manager's secret name storing the sendgrid api key"
type = string
}
3 changes: 3 additions & 0 deletions zero-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ parameters:
options:
- "cloudwatch"
- "kibana"
- field: sendgridApiKey
label: "API key to setup email integration (optional: leave blank to opt-out of Sendgrid setup)"
info: Signup at https://signup.sendgrid.com or create an API key from https://app.sendgrid.com/settings/api_keys. Sendgrid is an email delivery service enabling transactional email sending and more.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a note here that they can leave this blank to not set up sendgrid?

- field: accountId
label: AWS Account ID
execute: aws sts get-caller-identity --query "Account" | tr -d '"'
Expand Down