Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write outputs to Secrets Manager for use by other applications #6

Merged
merged 1 commit into from
Nov 8, 2024
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
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
Loading