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

Preparation to add tags to secrets #356

Merged
merged 4 commits into from
Sep 6, 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
16 changes: 15 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,19 @@ locals {
xsiam_secrets_version_development = "9e0de226-ed1a-4dbc-a42a-e549ff86fb19"
xsiam_secrets_version_pre_production = "f3680e16-7395-4c82-947a-be9b5e09b79c"
xsiam_secrets_version_production = "a83ace3e-b154-4992-bde2-bf72e2aa9950"
}

## for resources which requires the tags map without the "Name" value
## It uses the "name" attribute internally and concatenates with other attributes
tags_admin_minus_name = { for k, v in module.admin_label.tags : k => v if !contains(["Name"], k) }
tags_dhcp_minus_name = { for k, v in module.dhcp_label.tags : k => v if !contains(["Name"], k) }
tags_dns_minus_name = { for k, v in module.dns_label.tags : k => v if !contains(["Name"], k) }

secret_manager_arns = {
codebuild_dhcp_env_admin_db = aws_secretsmanager_secret.codebuild_dhcp_env_admin_db.arn
codebuild_dhcp_env_db = aws_secretsmanager_secret.codebuild_dhcp_env_db.arn
staff_device_dhcp_sentry_dsn = aws_secretsmanager_secret.staff_device_dhcp_sentry_dsn.arn
staff_device_dns_sentry_dsn = aws_secretsmanager_secret.staff_device_dns_sentry_dsn_1.arn
staff_device_admin_sentry_dsn = aws_secretsmanager_secret.staff_device_admin_sentry_dsn_1.arn
codebuild_dhcp_env_admin_api = aws_secretsmanager_secret.codebuild_dhcp_env_admin_api.arn
}
}
84 changes: 84 additions & 0 deletions secrets_manager.admin.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
resource "aws_secretsmanager_secret" "codebuild_dhcp_env_admin_db" {
name = "/codebuild/dhcp/${terraform.workspace}/admin/db"
# description = "DNS & DHCP ADMIN - Service RDS Database username & password."
provider = aws.env
# tags = merge(local.tags_admin_minus_name,
# { "Name" : "/codebuild/dhcp/${terraform.workspace}/admin/db" }
# )
}

data "aws_secretsmanager_secret_version" "codebuild_dhcp_env_admin_db" {
secret_id = aws_secretsmanager_secret.codebuild_dhcp_env_admin_db.id
provider = aws.env
}

resource "aws_secretsmanager_secret_version" "codebuild_dhcp_env_admin_db" {
provider = aws.env
secret_id = aws_secretsmanager_secret.codebuild_dhcp_env_admin_db.id
secret_string = jsonencode(
merge(
{
"username" : "adminuser",
"password" : random_password.codebuild_dhcp_env_admin_db.result
},
module.admin.admin_db_details
)
)
}

resource "random_password" "codebuild_dhcp_env_admin_db" {
length = 24
special = true
override_special = "_!%^"

lifecycle {
ignore_changes = [
length,
override_special
]
}
}


resource "aws_secretsmanager_secret" "codebuild_dhcp_env_admin_api" {
name = "/codebuild/dhcp/${terraform.workspace}/admin/api"
# description = "DNS & DHCP ADMIN - Prometheus - HTTP API"
provider = aws.env
# tags = merge(local.tags_admin_minus_name,
# { "Name" : "/codebuild/dhcp/${terraform.workspace}/admin/api" }
# )
}

data "aws_secretsmanager_secret_version" "codebuild_dhcp_env_admin_api" {
secret_id = aws_secretsmanager_secret.codebuild_dhcp_env_admin_api.id
provider = aws.env
}

resource "aws_secretsmanager_secret_version" "codebuild_dhcp_env_admin_api" {
provider = aws.env
secret_id = aws_secretsmanager_secret.codebuild_dhcp_env_admin_api.id
secret_string = jsonencode(
merge(
{
"endpoint" : "REPLACE_ME",
"basic_auth_username" : "REPLACE_ME",
"basic_auth_password" : "REPLACE_ME",
}
)
)
}

resource "aws_secretsmanager_secret" "staff_device_admin_sentry_dsn_1" {
name = "/staff-device/admin/sentry_dsn"
# description = "DNS & DHCP ADMIN - Sentry - Application monitoring and debugging software - Data Source Name (DSN)."
provider = aws.env
# tags = merge(local.tags_admin_minus_name,
# { "Name" : "/staff-device/admin/sentry_dsn" }
# )
}

resource "aws_secretsmanager_secret_version" "staff_device_admin_sentry_dsn" {
provider = aws.env
secret_id = aws_secretsmanager_secret.staff_device_admin_sentry_dsn_1.id
secret_string = "REPLACE_ME"
}
55 changes: 55 additions & 0 deletions secrets_manager.dhcp.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
resource "aws_secretsmanager_secret" "codebuild_dhcp_env_db" {
name = "/codebuild/dhcp/${terraform.workspace}/db"
# description = "DHCP - Service RDS Database username & password."
provider = aws.env
# tags = merge(local.tags_dhcp_minus_name,
# { "Name" : "/codebuild/dhcp/${terraform.workspace}/db" }
# )
}

data "aws_secretsmanager_secret_version" "codebuild_dhcp_env_db" {
secret_id = aws_secretsmanager_secret.codebuild_dhcp_env_db.id
provider = aws.env
}

resource "aws_secretsmanager_secret_version" "codebuild_dhcp_env_db" {
provider = aws.env
secret_id = aws_secretsmanager_secret.codebuild_dhcp_env_db.id
secret_string = jsonencode(
merge(
{
"username" : "dhcpuser",
"password" : random_password.codebuild_dhcp_env_db.result
},
module.dhcp.dhcp_db_details
)
)
}

resource "random_password" "codebuild_dhcp_env_db" {
length = 24
special = true
override_special = "_!%^"

lifecycle {
ignore_changes = [
length,
override_special
]
}
}

resource "aws_secretsmanager_secret" "staff_device_dhcp_sentry_dsn" {
name = "/staff-device/dhcp/sentry_dsn"
# description = "DHCP - Sentry - Application monitoring and debugging software - Data Source Name (DSN)."
provider = aws.env
# tags = merge(local.tags_dhcp_minus_name,
# { "Name" : "/staff-device/dhcp/sentry_dsn" }
# )
}

resource "aws_secretsmanager_secret_version" "staff_device_dhcp_sentry_dsn" {
provider = aws.env
secret_id = aws_secretsmanager_secret.staff_device_dhcp_sentry_dsn.id
secret_string = "REPLACE_ME"
}
14 changes: 14 additions & 0 deletions secrets_manager.dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "aws_secretsmanager_secret" "staff_device_dns_sentry_dsn_1" {
name = "/staff-device/dns/sentry_dsn"
# description = "DNS - Sentry - Application monitoring and debugging software - Data Source Name (DSN)."
provider = aws.env
# tags = merge(local.tags_dns_minus_name,
# { "Name" : "/staff-device/dns/sentry_dsn" }
# )
}

resource "aws_secretsmanager_secret_version" "staff_device_dns_sentry_dsn" {
provider = aws.env
secret_id = aws_secretsmanager_secret.staff_device_dns_sentry_dsn_1.id
secret_string = "REPLACE_ME"
}
141 changes: 0 additions & 141 deletions secrets_manager.tf

This file was deleted.