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
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@ apply-k8s-utils:
terraform init; \
terraform apply

.PHONY: apply apply-remote-state apply-secrets apply-env apply-k8s-utils
teardown: teardown-k8s-utils teardown-env teardown-secrets teardown-remote-state

teardown-remote-state:
pushd terraform/bootstrap/remote-state; \
terraform destroy;

teardown-secrets:
pushd terraform/bootstrap/secrets; \
terraform destroy -auto-approve;

teardown-env:
pushd terraform/environments/$(ENV); \
terraform destroy -auto-approve;

teardown-k8s-utils:
pushd kubernetes/terraform/environments/$(ENV); \
terraform destroy;

.PHONY: apply apply-remote-state apply-secrets apply-env apply-k8s-utils teardown-k8s-utils teardown-env teardown-secrets teardown-remote-state
74 changes: 26 additions & 48 deletions terraform/bootstrap/secrets/main.tf
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@
provider "aws" {
region = "<% index .Params `region` %>"
}

terraform {
required_version = ">= 0.12"
}

# Create the CI User
resource "aws_iam_user" "ci_user" {
name = "ci-user"
}

# Create a keypair to be used by CI systems
resource "aws_iam_access_key" "ci_user" {
user = aws_iam_user.ci_user.name
}

# Add the keys to AWS secrets manager
module "ci_user_keys" {
source = "../../modules/secret"

name = "ci-user-aws-keys"
type = "map"
values = map("access_key_id", aws_iam_access_key.ci_user.id, "secret_key", aws_iam_access_key.ci_user.secret)
}


# Create db credentials
# Unfortunately tf doesn't yet allow you to use for_each with calls to modules
locals {
project = "<% .Name %>"
}

module "db_password-staging" {
source = "../../modules/secret"

name = "${local.project}-staging-rds-master-password"
type = "random"
}

module "db_password-production" {
source = "../../modules/secret"

name = "${local.project}-production-rds-master-password"
type = "random"
random_length = 32
}
provider "aws" {
region = "<% index .Params `region` %>"
}

terraform {
required_version = ">= 0.12"
}

# Create the CI User
resource "aws_iam_user" "ci_user" {
name = "${var.project}-ci-user"
}

# Create a keypair to be used by CI systems
resource "aws_iam_access_key" "ci_user" {
user = aws_iam_user.ci_user.name
}

# Add the keys to AWS secrets manager
module "ci_user_keys" {
source = "../../modules/secret"

name_prefix = "ci-user-aws-keys"
type = "map"
values = map("access_key_id", aws_iam_access_key.ci_user.id, "secret_key", aws_iam_access_key.ci_user.secret)
}
2 changes: 1 addition & 1 deletion terraform/environments/production/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module "production" {
region = "<% index .Params `region` %>"
allowed_account_ids = ["<% index .Params `accountId` %>"]
# ECR configuration
ecr_repositories = ["production"]
ecr_repositories = ["<% .Name %>-production"]

# EKS configuration
eks_cluster_version = "1.15"
Expand Down
2 changes: 1 addition & 1 deletion terraform/environments/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module "staging" {
region = "<% index .Params `region` %>"
allowed_account_ids = ["<% index .Params `accountId` %>"]
# ECR configuration
ecr_repositories = [ "gql-server" ]
ecr_repositories = [ "<% .Name %>-staging" ]

# EKS configuration
eks_cluster_version = "1.15"
Expand Down
13 changes: 10 additions & 3 deletions terraform/modules/database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ module "rds_security_group" {
data "aws_caller_identity" "current" {
}

# This is created by bootstrap/secrets
# creating RDS password in secret-manager
module "db_password" {
source = "../secret"
name_prefix = "${var.project}-${var.environment}-rds-master-password"
type = "random"
}

# RDS does not support secret-manager, have to provide the actual string
data "aws_secretsmanager_secret_version" "rds_master_secret" {
secret_id = "${var.project}-${var.environment}-rds-master-password"
secret_id = module.db_password.secret_name
}

module "rds" {
Expand Down Expand Up @@ -64,7 +71,7 @@ module "rds" {

# DB parameter and option group
family = "postgres11"
major_engine_version = "11.5"
major_engine_version = "11"

final_snapshot_identifier = "final-snapshot"
deletion_protection = true
Expand Down
4 changes: 2 additions & 2 deletions terraform/modules/environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module "eks" {
}

data "aws_iam_user" "ci_user" {
user_name = "ci-user" # Should have been created in the bootstrap process
user_name = "${var.project}-ci-user" # Should have been created in the bootstrap process
}

module "wildcard_domain" {
Expand Down Expand Up @@ -97,5 +97,5 @@ module "ecr" {

environment = var.environment
ecr_repositories = var.ecr_repositories
ecr_principals = [data.aws_iam_user.ci_user.arn]
ecr_principals = [aws_iam_user.ci_user.arn]
}
2 changes: 1 addition & 1 deletion terraform/modules/secret/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add the keys to AWS secrets manager
resource "aws_secretsmanager_secret" "secret" {
name = var.name
name_prefix = var.name_prefix
}

resource "aws_secretsmanager_secret_version" "string_secret" {
Expand Down
5 changes: 3 additions & 2 deletions terraform/modules/secret/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
variable "name" {
description = "The name of the secret in Secrets Manager"
variable "name_prefix" {
default = "secret-key"
description = "The name prefix of the secret in Secrets Manager"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add a default for this? Since it's really only for testing and not something that normal users should care about we should try to keep it under the hood as much as possible.

}

variable type {
Expand Down