11locals {
22 cicd_secrets_prefix = " /cicd/common"
3- app_tf_prefix = " /app/tf"
43
54 secrets = [
6-
7- {
8- name = " ${ local . cicd_secrets_prefix } /github_repo_access"
9- description = " GitHub personal access token (PAT) for pulling repos from GitHub Cloud."
10- recovery_days = 7
11- },
125 {
13- name = " ${ local . cicd_secrets_prefix } /github_private_ssh_key"
14- description = " GitHub private SSH key used for pushing and signing commits in GitHub Cloud."
15- recovery_days = 7
16- },
17- {
18- name = " ${ local . app_tf_prefix } /splunk_access_ingest_token"
6+ name = " ${ local . cicd_secrets_prefix } /splunk_access_ingest_token"
197 description = " Splunk Observability Cloud Access Token for Ingest"
208 recovery_days = 7
219 },
2210 {
23- name = " ${ local . app_tf_prefix } /splunk_access_api_token"
24- description = " Splunk Observability Cloud Access Token for API"
25- recovery_days = 7
26- },
27- {
28- name = " ${ local . app_tf_prefix } /splunk_o11y_username"
11+ name = " ${ local . cicd_secrets_prefix } /splunk_o11y_username"
2912 description = " Splunk o11y Username"
3013 recovery_days = 7
3114 },
3215 {
33- name = " ${ local . app_tf_prefix } /splunk_o11y_password"
16+ name = " ${ local . cicd_secrets_prefix } /splunk_o11y_password"
3417 description = " Splunk o11y Password"
3518 recovery_days = 7
3619 },
3720 {
38- name = " ${ local . app_tf_prefix } /splunk_cloud_username"
21+ name = " ${ local . cicd_secrets_prefix } /splunk_cloud_username"
3922 description = " Splunk Cloud Username"
4023 recovery_days = 7
4124 },
4225 {
43- name = " ${ local . app_tf_prefix } /splunk_cloud_password"
26+ name = " ${ local . cicd_secrets_prefix } /splunk_cloud_password"
4427 description = " Splunk Cloud Password"
4528 recovery_days = 7
4629 },
4730 {
48- name = " ${ local . app_tf_prefix } /splunk_cloud_api_token"
31+ name = " ${ local . cicd_secrets_prefix } /splunk_cloud_api_token"
4932 description = " Splunk Cloud API token"
5033 recovery_days = 7
5134 },
5235 {
53- name = " ${ local . app_tf_prefix } /splunk_cloud_hec_token_eks"
36+ name = " ${ local . cicd_secrets_prefix } /splunk_cloud_hec_token_eks"
5437 description = " Splunk Cloud HEC token for eks"
5538 recovery_days = 7
5639 },
5740 ]
41+
42+ all_regions = toset (concat ([var . aws_region ], var. replica_regions ))
5843}
5944
6045# Psuedo-random seeds we use for initializing the secrets. If we don't do this,
@@ -68,6 +53,14 @@ data "aws_secretsmanager_random_password" "secret_seeds" {
6853 password_length = 16
6954}
7055
56+ resource "aws_kms_key" "regional" {
57+ for_each = local. all_regions
58+ provider = aws. by_region [each . value ]
59+
60+ description = " Customer managed CMK for SecretsManager in ${ each . key } "
61+ enable_key_rotation = true
62+ }
63+
7164# Actual object containing the secret.
7265resource "aws_secretsmanager_secret" "cicd_secrets" {
7366 for_each = {
@@ -76,26 +69,35 @@ resource "aws_secretsmanager_secret" "cicd_secrets" {
7669
7770 name = each. value . name
7871 description = each. value . description
72+ kms_key_id = aws_kms_key. regional [var . aws_region ]. arn
7973 recovery_window_in_days = each. value . recovery_days
8074 tags = local. all_security_tags
8175 tags_all = local. all_security_tags
8276
77+ dynamic "replica" {
78+ for_each = var. replica_regions
79+ content {
80+ region = replica. value
81+ kms_key_id = aws_kms_key. regional [replica . value ]. arn
82+ }
83+ }
84+
8385}
8486
8587# Force a delay between secret creation and seeding. We only need a few
8688# seconds, but if we don't do this, we get into a bad state requiring manual
8789# intervention and/or manual forced-deletion of secrets.
88- resource "time_sleep" "wait_30_seconds " {
90+ resource "time_sleep" "wait_60_seconds " {
8991 depends_on = [
9092 aws_secretsmanager_secret . cicd_secrets ,
9193 ]
92- create_duration = " 30s "
94+ create_duration = " 60s "
9395}
9496
9597# Only used for seeding purposes. Will not clobber/overwrite secrets afterward
9698# (i.e. if/when we set them manually via the AWS CLI or management console).
9799resource "aws_secretsmanager_secret_version" "cicd_secrets" {
98- depends_on = [time_sleep . wait_30_seconds ]
100+ depends_on = [time_sleep . wait_60_seconds ]
99101 for_each = {
100102 for key , val in local . secrets : val . name => val
101103 }
0 commit comments