Skip to content

Commit

Permalink
Write atomic outputs to Secrets Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Nov 8, 2024
1 parent 1325f78 commit 2db11d5
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 1 deletion.
25 changes: 25 additions & 0 deletions configuration/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions configuration/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
terraform {
backend "s3" {
key = "infrastructure_configuration.tfstate"
}

required_providers {
aws = "~> 5.19"
}
required_version = ">= 1.3.0"
}

provider "aws" {
default_tags {
tags = local.tags
}
}

locals {
# environment = module.core.outputs.stack.environment
namespace = module.core.outputs.stack.namespace
prefix = module.core.outputs.stack.prefix
tags = merge(
module.core.outputs.stack.tags,
{
Component = "configuration",
Git = "github.com/nulib/infrastructure"
Project = "Infrastructure"
}
)
}

module "core" {
source = "../modules/remote_state"
component = "core"
}
11 changes: 11 additions & 0 deletions configuration/secrets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "aws_secretsmanager_secret" "data_services" {
for_each = var.secrets
name = "${local.prefix}/infrastructure/${each.key}"
description = "${each.key} secrets for ${local.namespace}"
}

resource "aws_secretsmanager_secret_version" "config_secrets" {
for_each = var.secrets
secret_id = aws_secretsmanager_secret.data_services[each.key].id
secret_string = jsonencode(each.value)
}
3 changes: 3 additions & 0 deletions configuration/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "secrets" {
type = map(any)
}
20 changes: 20 additions & 0 deletions core/secrets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
locals {
secrets = {
wildcard_cert = {
domain = aws_acm_certificate.wildcard_cert.domain_name
certificate_arn = aws_acm_certificate.wildcard_cert.arn
}
}
}

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

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)
}
2 changes: 1 addition & 1 deletion fcrepo/secrets.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
secrets = {
fcrepo = {
endpoint = "http://${aws_service_discovery_service.fcrepo.name}.${module.core.outputs.vpc.service_discovery_dns_zone.name}:8080/rest"
endpoint = "http://${aws_service_discovery_service.fcrepo.name}.${module.core.outputs.vpc.service_discovery_dns_zone.name}:8080/rest/"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions iiif-server/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Resources:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Sub "${Namespace}/infrastructure/iiif"
Description: !Sub "iiif secrets for ${Namespace}"
SecretString:
Fn::ToJsonString:
base: !Sub "https://${Hostname}.${DomainName}/"
Expand Down

0 comments on commit 2db11d5

Please sign in to comment.