Skip to content

Commit

Permalink
Create discrete secrets for each deployed component
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Sep 18, 2024
1 parent c0b3e3f commit db5faf2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 74 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ Each folder should follow the same naming conventions:
* `data.tf` – Contains terraform `data` sources, if there are enough of them to warrant splitting them out
* `outputs.tf` – Contains only terraform outputs

## Secrets

Instead of using Terraform variables (and `.tfvars` files), which come with a host of security/maintenance/synchronization issues, each component or project should store a JSON string of their secrets in [AWS Server Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) under the `/tfvars/` namespace. These secrets can be referenced using the [`secrets` module](modules/secrets/README.md) in this repository. Please see that module's README file and other components within this repository for examples.

## Common Configuration

Each folder should be initialized the same way:
Expand Down
1 change: 0 additions & 1 deletion core/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ locals {
environment = coalesce(var.environment, substr(terraform.workspace, 0, 1))
namespace = join("-", [var.stack_name, local.environment])
common_tags = {
Department = "RDC"
Environment = terraform.workspace
Terraform = "true"
}
Expand Down
19 changes: 19 additions & 0 deletions fcrepo/secrets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
locals {
secrets = {
fcrepo = {
endpoint = "http://${aws_service_discovery_service.fcrepo.name}.${module.core.outputs.vpc.service_discovery_dns_zone.name}:8080/rest"
}
}
}

resource "aws_secretsmanager_secret" "data_services" {
for_each = local.secrets
name = "${local.namespace}/infrastructure/${each.key}"
description = "${each.key} secrets for ${local.namespace}"
}

resource "aws_secretsmanager_secret_version" "config_secrets" {
for_each = local.secrets
secret_id = aws_secretsmanager_secret.data_services[each.key].id
secret_string = jsonencode(each.value)
}
49 changes: 0 additions & 49 deletions modules/secrets/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions modules/secrets/main.tf

This file was deleted.

3 changes: 0 additions & 3 deletions modules/secrets/outputs.tf

This file was deleted.

13 changes: 0 additions & 13 deletions modules/secrets/variables.tf

This file was deleted.

20 changes: 20 additions & 0 deletions solrcloud/secrets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
locals {
secrets = {
solrcloud = {
solr_url = local.solr_endpoint
zookeeper_servers = local.zookeeper_servers
}
}
}

resource "aws_secretsmanager_secret" "data_services" {
for_each = local.secrets
name = "${local.namespace}/infrastructure/${each.key}"
description = "${each.key} secrets for ${local.namespace}"
}

resource "aws_secretsmanager_secret_version" "config_secrets" {
for_each = local.secrets
secret_id = aws_secretsmanager_secret.data_services[each.key].id
secret_string = jsonencode(each.value)
}

0 comments on commit db5faf2

Please sign in to comment.