Skip to content

Commit 615240e

Browse files
committed
feat: Use SSM to pass parameters between layers.
1 parent 410a865 commit 615240e

File tree

14 files changed

+115
-34
lines changed

14 files changed

+115
-34
lines changed

tofu/config/foundation/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ module "logging" {
3030

3131
tags = resource.aws_servicecatalogappregistry_application.application.application_tag
3232
}
33+
34+
module "outputs" {
35+
source = "../../modules/outputs"
36+
37+
prefix = "/${var.project}/${var.environment}"
38+
39+
outputs = {
40+
"application/arn" = aws_servicecatalogappregistry_application.application.arn
41+
"logging/bucket" = module.logging.bucket
42+
"logging/key" = module.logging.kms_key_arn
43+
}
44+
}

tofu/config/foundation/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
output "application_tags" {
2-
description = "The tags for the Service Catalog App Registry application."
3-
value = aws_servicecatalogappregistry_application.application.application_tag
1+
output "application_arn" {
2+
description = "ARN of the Service Catalog App Registry application."
3+
value = aws_servicecatalogappregistry_application.application.arn
44
}
55

66
output "logging_bucket" {

tofu/config/networking/main.tf

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,39 @@ terraform {
77
}
88
}
99

10+
module "inputs" {
11+
source = "../../modules/inputs"
12+
13+
prefix = "/${var.project}/${var.environment}"
14+
15+
inputs = ["application/arn", "logging/key"]
16+
}
17+
1018
# TODO: Air gap this VPC from the internet.
1119
module "vpc" {
1220
source = "github.com/codeforamerica/tofu-modules-aws-vpc?ref=1.1.2"
1321

1422
project = var.project
1523
environment = var.environment
1624
cidr = var.vpc_cidr
17-
logging_key_id = var.logging_key_arn
25+
logging_key_id = module.inputs.values["logging/key"]
1826
private_subnets = var.vpc_private_subnet_cidrs
1927

2028
# TODO: We don't need public subnets or a NAT gateway for an air gapped VPC.
2129
public_subnets = var.vpc_public_subnet_cidrs
2230
single_nat_gateway = true
2331

24-
tags = var.tags
32+
tags = merge({ awsApplication : module.inputs.values["application/arn"] }, var.tags)
33+
}
34+
35+
module "outputs" {
36+
source = "../../modules/outputs"
37+
38+
prefix = "/${var.project}/${var.environment}"
39+
40+
outputs = {
41+
"vpc/id" = module.vpc.vpc_id
42+
"vpc/private_subnets" = join(",", module.vpc.private_subnets)
43+
"vpc/public_subnets" = join(",", module.vpc.public_subnets)
44+
}
2545
}

tofu/config/networking/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ variable "environment" {
44
default = "development"
55
}
66

7-
variable "logging_key_arn" {
8-
type = string
9-
description = "The ARN of the KMS key for logging."
10-
}
11-
127
variable "program" {
138
type = string
149
description = "Program the application belongs to."

tofu/config/service/main.tf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ terraform {
77
}
88
}
99

10+
module "inputs" {
11+
source = "../../modules/inputs"
12+
13+
prefix = "/${var.project}/${var.environment}"
14+
15+
inputs = ["application/arn", "logging/bucket", "vpc/id", "vpc/private_subnets"]
16+
}
17+
1018
module "system" {
1119
source = "../../modules/system"
1220

1321
environment = var.environment
1422
project = var.project
1523
export_expiration = var.export_expiration
1624
key_recovery_period = var.key_recovery_period
17-
logging_bucket = var.logging_bucket
18-
vpc_id = var.vpc_id
19-
database_subnets = var.database_subnet_ids
20-
tags = var.tags
25+
logging_bucket = module.inputs.values["logging/bucket"]
26+
vpc_id = module.inputs.values["vpc/id"]
27+
database_subnets = split(",", module.inputs.values["vpc/private_subnets"])
28+
tags = merge({ awsApplication : module.inputs.values["application/arn"] }, var.tags)
2129
}

tofu/config/service/variables.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ variable "key_recovery_period" {
2121
}
2222
}
2323

24-
variable "logging_bucket" {
25-
type = string
26-
description = "The name of the S3 bucket for logging."
27-
}
28-
2924
variable "program" {
3025
type = string
3126
description = "Program the application belongs to."
@@ -49,18 +44,3 @@ variable "tags" {
4944
description = "Tags to apply to all resources."
5045
default = {}
5146
}
52-
53-
variable "vpc_id" {
54-
type = string
55-
description = "ID of the VPC to deploy resources into."
56-
}
57-
58-
variable "database_subnet_ids" {
59-
type = list(string)
60-
description = "The IDs of the subnets to use for the database."
61-
}
62-
63-
variable "container_subnet_ids" {
64-
type = list(string)
65-
description = "The IDs of the subnets to use for container resources."
66-
}

tofu/modules/inputs/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data "aws_ssm_parameter" "this" {
2+
for_each = toset(var.inputs)
3+
4+
name = join("/", compact([var.prefix, each.value]))
5+
}

tofu/modules/inputs/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "values" {
2+
description = "Map of input names to their values."
3+
value = { for k, v in data.aws_ssm_parameter.this : k => v.insecure_value }
4+
}

tofu/modules/inputs/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "inputs" {
2+
type = list(string)
3+
description = "Inputs to be read from SSM Parameter Store."
4+
default = []
5+
}
6+
7+
variable "prefix" {
8+
type = string
9+
description = "Prefix to prepend to all input names."
10+
default = null
11+
}

tofu/modules/inputs/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.9"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 6.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)