Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
7a7fcfe
Add AWS IAM Redis passwordless authentication support
raviharshicorp Sep 30, 2025
72fd992
Update terraform-random-tfe-utility module references to use pravi/IN…
raviharshicorp Oct 1, 2025
5c39336
Update remaining terraform-random-tfe-utility references to pravi/IND…
raviharshicorp Oct 1, 2025
13e0d4f
feat: add Redis passwordless AWS host name support
raviharshicorp Nov 4, 2025
37867eb
fix: add explicit default user for Redis IAM authentication
raviharshicorp Nov 4, 2025
45cbee2
fix: improve default user access string for ElastiCache user group
raviharshicorp Nov 4, 2025
b5b2712
fix: correct authentication mode type for default user
raviharshicorp Nov 4, 2025
7dc969f
fix: use built-in AWS ElastiCache default user instead of creating one
raviharshicorp Nov 4, 2025
d9bda60
fix: enable transit encryption when using IAM authentication
raviharshicorp Nov 4, 2025
3ba107d
debug: Add comprehensive Redis IAM username troubleshooting outputs
raviharshicorp Nov 6, 2025
d87c702
fix: Add comprehensive debug outputs for Redis IAM authentication tro…
raviharshicorp Nov 6, 2025
7760248
Fix Redis TLS CA certificate path for IAM authentication
raviharshicorp Nov 6, 2025
ca0a764
Fix Redis passwordless test: Remove PostgreSQL passwordless confusion
raviharshicorp Nov 6, 2025
329ddef
Fix module references to use pravi/IND-5861 branch consistently
raviharshicorp Nov 6, 2025
bdf9339
fix: Add AWS IAM Redis passwordless authentication support
raviharshicorp Nov 6, 2025
ff3841b
fix: Replace redis_enable_iam_auth with redis_passwordless_aws_use_ia…
raviharshicorp Nov 6, 2025
359b88d
fix: Restore corrupted standalone-vault/main.tf and apply terraform fmt
raviharshicorp Nov 7, 2025
7fd34a7
fix: update Redis AWS IAM variable to match TFE documentation
raviharshicorp Nov 18, 2025
77aeb56
Add Redis passwordless AWS region and hostname variables
raviharshicorp Nov 18, 2025
c08fc28
Fix Redis IAM authentication by adding missing IAM user configuration
raviharshicorp Nov 18, 2025
59ae7e9
Add missing Redis IAM policy to service accounts module
raviharshicorp Nov 18, 2025
2db6119
Fix Redis authentication flag for IAM authentication
raviharshicorp Nov 18, 2025
b0c0fae
Fix Redis authentication conflict - disable traditional AUTH for IAM …
raviharshicorp Nov 19, 2025
6d045b6
Fix Redis IAM user group - remove default user for IAM authentication
raviharshicorp Nov 19, 2025
2ddb81d
Remove duplicate redis_enable_iam_auth variable
raviharshicorp Nov 19, 2025
9eab717
Restore accidentally removed Redis security variables
raviharshicorp Nov 19, 2025
331897d
Fix AWS ElastiCache user group - add required default user
raviharshicorp Nov 19, 2025
c4d6a21
Fix ElastiCache IAM auth - use AWS built-in default user
raviharshicorp Nov 19, 2025
192c04a
Fix Redis IAM authentication - set TFE_REDIS_USE_AUTH=true
raviharshicorp Nov 19, 2025
5f05872
Revert incorrect TFE_REDIS_USE_AUTH change
raviharshicorp Nov 19, 2025
ee17b75
Add explicit Redis security group rule comment
raviharshicorp Nov 19, 2025
85d8019
Fix Redis security group mismatch and reduce EC2 costs
raviharshicorp Nov 19, 2025
18efb8b
Fix Redis module syntax error
raviharshicorp Nov 19, 2025
60d9716
Add clarifying comment to Redis module
raviharshicorp Nov 19, 2025
a8a53c5
Fix Redis module outputs to reference TFE security group
raviharshicorp Nov 19, 2025
51a61ad
Fix Redis IAM authentication configuration
raviharshicorp Nov 19, 2025
fa227d6
Fix Redis IAM policy to allow both default and custom users
raviharshicorp Nov 19, 2025
9bac62a
Enable custom IAM user testing for Redis
raviharshicorp Nov 19, 2025
09778aa
Fix Redis IAM authentication by using explicit resource ARNs
raviharshicorp Nov 20, 2025
c41ee19
Fix Redis locals reference - remove non-existent .enabled attribute
raviharshicorp Nov 20, 2025
45f3b2f
Clean up Redis passwordless implementation
raviharshicorp Nov 20, 2025
61673bd
Remove unnecessary database identifier outputs - not needed for Redis…
raviharshicorp Nov 21, 2025
a33c463
Remove PostgreSQL IAM description - not needed for Redis passwordless
raviharshicorp Nov 21, 2025
1a92048
Revert sentinel/mTLS certificate path changes - not needed for Redis …
raviharshicorp Nov 21, 2025
4eeb04b
Revert ALB health check changes - not needed for Redis IAM auth testing
raviharshicorp Nov 21, 2025
681b718
Fix Aurora outputs.tf - restore missing closing brace (syntax error)
raviharshicorp Nov 21, 2025
0d46f46
Fix Redis username output to use actual IAM user instead of 'default'
raviharshicorp Nov 21, 2025
f2aecd5
Remove default user from Redis IAM policy - use only specific IAM user
raviharshicorp Nov 21, 2025
7cdd3b2
Remove unrelated VM security group changes - not needed for Redis IAM…
raviharshicorp Nov 21, 2025
9f3ce61
Restore VM security group logic - required for Redis IAM auth connect…
raviharshicorp Nov 21, 2025
3d8fd7b
Revert node_count default change - not related to Redis IAM auth
raviharshicorp Nov 21, 2025
0d125c0
Fix Redis certificate paths - only pass paths when mTLS is enabled
raviharshicorp Nov 21, 2025
62fb075
Decouple Redis encryption from IAM auth - they are independent features
raviharshicorp Nov 21, 2025
7f8376f
Remove unused redis_passwordless_aws_region variable
raviharshicorp Nov 24, 2025
a55b07e
Add missing redis_authentication_mode to Redis module
raviharshicorp Nov 24, 2025
3ff3ab3
Fix circular dependency in Redis module
raviharshicorp Nov 24, 2025
6a6b3a6
Add validation for mutually exclusive Redis authentication options
raviharshicorp Nov 24, 2025
de31c27
Clarify existing_vm_security_group_id description
raviharshicorp Nov 24, 2025
87fd295
Fix Redis passwordless IAM auth for standalone mode
raviharshicorp Nov 24, 2025
d937b79
Fix typo: 'authentincation' → 'authentication'
raviharshicorp Nov 24, 2025
1a775f5
Fix Terraform variable validation errors
raviharshicorp Nov 24, 2025
e69b364
Fix duplicate local attribute names
raviharshicorp Nov 24, 2025
c87fdf6
Trigger CI refresh - fix duplicate attribute names
raviharshicorp Nov 24, 2025
d9a55e3
Fix terraform fmt whitespace issue
raviharshicorp Nov 24, 2025
2c50863
Fix tflint naming convention and unused declaration warnings
raviharshicorp Nov 24, 2025
881c641
Suppress tflint unused declarations warnings for validation locals
raviharshicorp Nov 24, 2025
f151253
Temporarily revert conditional Redis cert paths and security group fo…
raviharshicorp Nov 24, 2025
b954e95
HOTFIX: Restore missing IAM authentication parameters
raviharshicorp Nov 24, 2025
8366ffe
Fix formatting: Convert literal \n to actual newlines and remove extr…
raviharshicorp Nov 24, 2025
07432c6
Fix Redis module: Add missing required variables
raviharshicorp Nov 24, 2025
e316724
Add missing redis_enable_iam_auth variable to Redis module
raviharshicorp Nov 24, 2025
c7c5325
fix: Add missing Redis outputs for passwordless authentication testing
raviharshicorp Nov 24, 2025
62392a8
fix: Replace aws_security_group.redis[0].id with var.tfe_instance_sg …
raviharshicorp Nov 24, 2025
a572905
fix: Add missing cluster_id and iam_user outputs to Redis module
raviharshicorp Nov 24, 2025
154807a
Fix duplicate Redis outputs - remove duplicated cluster_id and iam_us…
raviharshicorp Nov 25, 2025
c1f8428
Fix: Restore conditional Redis certificate paths for IAM auth
raviharshicorp Nov 25, 2025
91c2955
Remove Redis certificate paths entirely when mTLS disabled
raviharshicorp Nov 25, 2025
e49230b
Fix linting issues: formatting and unused variables
raviharshicorp Nov 25, 2025
762f429
Clean up unnecessary comments in Redis module
raviharshicorp Nov 25, 2025
f5d9cb7
Clean up outputs and address PR review feedback
raviharshicorp Nov 25, 2025
45ef6ca
Add back Redis mTLS certificate paths for compatibility
raviharshicorp Nov 25, 2025
357d3a2
Make Redis certificate paths conditional on mTLS being enabled
raviharshicorp Nov 25, 2025
759bef2
Remove Redis certificate paths entirely when mTLS disabled
raviharshicorp Nov 25, 2025
7c87074
Revert Redis security group changes to maintain compatibility with ot…
raviharshicorp Nov 25, 2025
6ee636a
Remove unused network_private_subnet_cidrs variable from Redis module
raviharshicorp Nov 25, 2025
ab99974
Remove network_private_subnet_cidrs from Redis module call
raviharshicorp Nov 25, 2025
34f0970
Add conditional logic for Redis certificate paths
raviharshicorp Nov 25, 2025
aaf3610
Restore missing security group rules in Redis module
raviharshicorp Nov 25, 2025
3641c33
Restore missing variables in Redis module
raviharshicorp Nov 25, 2025
1fc86e8
Revert unrelated VM module changes
raviharshicorp Nov 25, 2025
099f9e2
Remove existing_security_group_id parameter and variable
raviharshicorp Nov 25, 2025
5577e5f
Add missing network_private_subnet_cidrs to Redis module call
raviharshicorp Nov 25, 2025
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
2 changes: 1 addition & 1 deletion fixtures/test_proxy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ resource "aws_instance" "proxy" {
}

module "test_proxy_init" {
source = "github.com/hashicorp/terraform-random-tfe-utility//fixtures/test_proxy_init?ref=main"
source = "github.com/hashicorp/terraform-random-tfe-utility//fixtures/test_proxy_init?ref=pravi/IND-5861"

mitmproxy_ca_certificate_secret = var.mitmproxy_ca_certificate_secret != null ? var.mitmproxy_ca_certificate_secret : null
mitmproxy_ca_private_key_secret = var.mitmproxy_ca_private_key_secret != null ? var.mitmproxy_ca_private_key_secret : null
Expand Down
39 changes: 20 additions & 19 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ module "aurora_database" {
# Docker Compose File Config for TFE on instance(s) using Flexible Deployment Options
# ------------------------------------------------------------------------------------
module "runtime_container_engine_config" {
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=main"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=pravi/IND-5861"
count = var.is_replicated_deployment ? 0 : 1

tfe_license = var.hc_license
Expand Down Expand Up @@ -312,21 +312,22 @@ module "runtime_container_engine_config" {
s3_server_side_encryption_kms_key_id = local.kms_key_arn
s3_use_instance_profile = var.aws_access_key_id == null ? "1" : "0"

redis_host = local.redis.hostname
redis_user = local.redis.username
redis_password = local.redis.password
redis_use_tls = local.redis.use_tls
redis_use_auth = local.redis.use_password_auth
redis_use_sentinel = var.enable_redis_sentinel
redis_sentinel_hosts = local.redis.sentinel_hosts
redis_sentinel_leader_name = local.redis.sentinel_leader
redis_sentinel_user = local.redis.sentinel_username
redis_sentinel_password = local.redis.sentinel_password
redis_use_mtls = var.enable_redis_mtls
enable_sentinel_mtls = var.enable_sentinel_mtls
redis_ca_cert_path = "/etc/ssl/private/terraform-enterprise/redis/cacert.pem"
redis_client_cert_path = "/etc/ssl/private/terraform-enterprise/redis/cert.pem"
redis_client_key_path = "/etc/ssl/private/terraform-enterprise/redis/key.pem"
redis_host = local.redis.hostname
redis_user = local.redis.username
redis_password = local.redis.password
redis_use_tls = local.redis.use_tls
redis_use_auth = local.redis.use_password_auth
redis_passwordless_aws_use_iam = var.redis_passwordless_aws_use_iam
redis_use_sentinel = var.enable_redis_sentinel
redis_sentinel_hosts = local.redis.sentinel_hosts
redis_sentinel_leader_name = local.redis.sentinel_leader
redis_sentinel_user = local.redis.sentinel_username
redis_sentinel_password = local.redis.sentinel_password
redis_use_mtls = var.enable_redis_mtls
enable_sentinel_mtls = var.enable_sentinel_mtls
redis_ca_cert_path = var.enable_redis_mtls || var.enable_sentinel_mtls ? "/etc/ssl/private/terraform-enterprise/redis/cacert.pem" : null
redis_client_cert_path = var.enable_redis_mtls || var.enable_sentinel_mtls ? "/etc/ssl/private/terraform-enterprise/redis/cert.pem" : null
redis_client_key_path = var.enable_redis_mtls || var.enable_sentinel_mtls ? "/etc/ssl/private/terraform-enterprise/redis/key.pem" : null


trusted_proxies = local.trusted_proxies
Expand All @@ -343,7 +344,7 @@ module "runtime_container_engine_config" {
# AWS cloud init used to install and configure TFE on instance(s) using Flexible Deployment Options
# --------------------------------------------------------------------------------------------------
module "tfe_init_fdo" {
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init?ref=main"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init?ref=pravi/IND-5861"
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module source references a feature branch (pravi/IND-5861) instead of main. According to the PR description, this should be updated to main before merging.

Suggested change
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init?ref=pravi/IND-5861"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init?ref=main"

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be changed before merging

count = var.is_replicated_deployment ? 0 : 1

cloud = "aws"
Expand Down Expand Up @@ -388,7 +389,7 @@ module "tfe_init_fdo" {
# TFE and Replicated settings to pass to the tfe_init_replicated module for replicated deployment
# --------------------------------------------------------------------------------------------
module "settings" {
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/settings?ref=main"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/settings?ref=pravi/IND-5861"
count = var.is_replicated_deployment ? 1 : 0

# TFE Base Configuration
Expand Down Expand Up @@ -450,7 +451,7 @@ module "settings" {
# AWS user data / cloud init used to install and configure TFE on instance(s)
# -----------------------------------------------------------------------------
module "tfe_init_replicated" {
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init_replicated?ref=main"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init_replicated?ref=pravi/IND-5861"
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module source references a feature branch (pravi/IND-5861) instead of main. According to the PR description, this should be updated to main before merging.

Suggested change
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init_replicated?ref=pravi/IND-5861"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/tfe_init_replicated?ref=main"

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be changed before merging.

count = var.is_replicated_deployment ? 1 : 0

# TFE & Replicated Configuration data
Expand Down
30 changes: 21 additions & 9 deletions modules/application_load_balancer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ resource "aws_lb_target_group" "tfe_tg_443" {
vpc_id = var.network_id

health_check {
path = "/_health_check"
protocol = "HTTPS"
matcher = "200-399"
path = "/_health_check"
protocol = "HTTPS"
matcher = "200-399"
timeout = 15
interval = 60
healthy_threshold = 2
unhealthy_threshold = 10
}
}

Expand All @@ -140,9 +144,13 @@ resource "aws_lb_target_group" "tfe_tg_8800" {
vpc_id = var.network_id

health_check {
path = "/"
protocol = "HTTPS"
matcher = "200-399"
path = "/"
protocol = "HTTPS"
matcher = "200-399"
timeout = 15
interval = 60
healthy_threshold = 2
unhealthy_threshold = 10
}
}

Expand All @@ -166,9 +174,13 @@ resource "aws_lb_target_group" "tfe_tg_admin_api" {
vpc_id = var.network_id

health_check {
path = "/api/v1/ping"
protocol = "HTTPS"
matcher = "200-399,400,401,403"
path = "/api/v1/ping"
protocol = "HTTPS"
matcher = "200-399,400,401,403"
timeout = 15
interval = 60
healthy_threshold = 2
unhealthy_threshold = 10
}
}

Expand Down
10 changes: 10 additions & 0 deletions modules/aurora_database_cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ output "parameters" {
description = "PostgreSQL server parameters for the connection URI."
}

output "identifier" {
value = aws_rds_cluster.aurora_postgresql.cluster_identifier
description = "The database identifier of the PostgreSQL Aurora cluster."
}

output "dbi_resource_id" {
value = aws_rds_cluster.aurora_postgresql.cluster_resource_id
description = "The DBI resource ID of the PostgreSQL Aurora cluster for IAM authentication."
}

15 changes: 14 additions & 1 deletion modules/database/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@ output "name" {

output "password" {
value = aws_db_instance.postgresql.password
description = "The password of the main PostgreSQL user."
description = "The password of the PostgreSQL master user. Required for creating IAM-enabled database users."
sensitive = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ Good idea.

}

output "username" {
value = aws_db_instance.postgresql.username
description = "The name of the main PostgreSQL user."
}



output "identifier" {
value = aws_db_instance.postgresql.identifier
description = "The database identifier of the PostgreSQL RDS instance."
}

output "dbi_resource_id" {
value = aws_db_instance.postgresql.resource_id
description = "The DBI resource ID of the PostgreSQL RDS instance for IAM authentication."
}

output "parameters" {
value = var.db_parameters
description = "PostgreSQL server parameters for the connection URI."
Expand Down
57 changes: 55 additions & 2 deletions modules/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

locals {
redis_use_password_auth = var.redis_use_password_auth || var.redis_authentication_mode == "PASSWORD"
redis_use_iam_auth = var.redis_enable_iam_auth && !var.redis_use_password_auth
}

resource "random_id" "redis_password" {
Expand Down Expand Up @@ -63,6 +64,47 @@ resource "aws_elasticache_subnet_group" "tfe" {
subnet_ids = var.network_subnets_private
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens here if we use existing security groups

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always creates a new subnet group, even when using existing security groups. This could cause conflicts or resource duplication.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it works with the existing configuration we should continue to do so. wydt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't worked with existing configuration.

When using existing security groups, EC2 instances get the existing security group.
But Redis always creates its own subnet group regardless of security group configuration.
This lead to Redis being deployed in different subnets than the EC2 instances.
This cause connectivity issues between EC2 and Redis, breaking IAM authentication

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted to the original code. it seems to work with existing config.

}

# ElastiCache User for IAM authentication
resource "aws_elasticache_user" "iam_user" {
count = var.active_active && local.redis_use_iam_auth ? 1 : 0
user_id = "${var.friendly_name_prefix}-iam-user"
user_name = "${var.friendly_name_prefix}-iam-user"

# For IAM authentication, we don't set passwords but use IAM policies
authentication_mode {
type = "iam"
}

# Access string for Redis commands - IAM auth compatible
# Use default access string for TFE with IAM authentication
access_string = "on ~* &* +@all"
engine = "REDIS"

tags = {
Name = "${var.friendly_name_prefix}-redis-iam-user"
}
}

# ElastiCache User Group for IAM authentication
# Note: AWS ElastiCache has a built-in "default" user that must be included in user groups
resource "aws_elasticache_user_group" "iam_group" {
count = var.active_active && local.redis_use_iam_auth ? 1 : 0
engine = "REDIS"
user_group_id = "${var.friendly_name_prefix}-iam-group"
user_ids = [
"default", # Built-in AWS ElastiCache default user
aws_elasticache_user.iam_user[0].user_id
]

tags = {
Name = "${var.friendly_name_prefix}-redis-iam-group"
}

depends_on = [
aws_elasticache_user.iam_user
]
}

resource "aws_elasticache_replication_group" "redis" {
count = var.active_active ? 1 : 0
node_type = var.cache_size
Expand All @@ -83,9 +125,20 @@ resource "aws_elasticache_replication_group" "redis" {

# Password used to access a password protected server.
# Can be specified only if transit_encryption_enabled = true.
auth_token = var.redis_encryption_in_transit && local.redis_use_password_auth ? random_id.redis_password[0].hex : null
transit_encryption_enabled = var.redis_encryption_in_transit
auth_token = var.redis_encryption_in_transit && local.redis_use_password_auth ? random_id.redis_password[0].hex : null

# Transit encryption is required when using user groups (IAM authentication)
transit_encryption_enabled = var.redis_encryption_in_transit || local.redis_use_iam_auth

at_rest_encryption_enabled = var.redis_encryption_at_rest
kms_key_id = var.redis_encryption_at_rest ? var.kms_key_arn : null

# IAM authentication configuration
user_group_ids = local.redis_use_iam_auth ? [aws_elasticache_user_group.iam_group[0].user_group_id] : null

# Ensure proper dependency ordering for IAM authentication
depends_on = [
aws_elasticache_user_group.iam_group,
aws_elasticache_user.iam_user
]
}
24 changes: 20 additions & 4 deletions modules/redis/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@ output "hostname" {
}

output "password" {
value = try(random_id.redis_password[0].hex, "")
description = "The password which is required to create connections with the Redis Elasticache replication group."
value = try(random_id.redis_password[0].hex, null)
description = "The password which is required to create connections with the Redis Elasticache replication group. Returns null when using IAM authentication."
}

output "username" {
value = null
description = "The username which is required to create connections with the Redis Elasticache replication group. Defaults to null to maintain the output interface with the redis-sentinel module."
value = try(aws_elasticache_user.iam_user[0].user_name, null)
description = "The username which is required to create connections with the Redis Elasticache replication group. Returns IAM username when IAM auth is enabled, otherwise null to maintain the output interface with the redis-sentinel module."
}

# DEBUG: Redis IAM username debug
output "debug_redis_iam_auth_enabled" {
value = local.redis_use_iam_auth
description = "DEBUG: Whether Redis IAM auth is enabled"
}

output "debug_redis_iam_user_name" {
value = try(aws_elasticache_user.iam_user[0].user_name, "NOT_CREATED")
description = "DEBUG: The actual Redis IAM username created"
}

output "debug_redis_iam_user_id" {
value = try(aws_elasticache_user.iam_user[0].user_id, "NOT_CREATED")
description = "DEBUG: The actual Redis IAM user ID created"
}

output "redis_port" {
Expand Down
6 changes: 6 additions & 0 deletions modules/redis/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ variable "redis_use_password_auth" {
type = bool
description = "Determine if a password is required for Redis."
}

variable "redis_enable_iam_auth" {
type = bool
description = "Whether to enable IAM authentication for Redis. Used for passwordless authentication."
default = false
}
31 changes: 31 additions & 0 deletions modules/service_accounts/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,34 @@ resource "aws_iam_policy" "kms_policy" {
]
})
}

# Redis IAM authentication policy
resource "aws_iam_role_policy_attachment" "redis_iam_policy" {
count = var.existing_iam_instance_profile_name == null && var.redis_enable_iam_auth ? 1 : 0

role = local.iam_instance_role.name
policy_arn = aws_iam_policy.redis_iam_policy[0].arn
}

resource "aws_iam_policy" "redis_iam_policy" {
count = var.existing_iam_instance_profile_name == null && var.redis_enable_iam_auth ? 1 : 0

name = "${var.friendly_name_prefix}-redis-iam"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"elasticache:Connect"
]
Effect = "Allow"
Resource = "*"
Condition = {
StringEquals = {
"elasticache:Username" = "${var.friendly_name_prefix}-iam-user"
}
}
},
]
})
}
6 changes: 6 additions & 0 deletions modules/service_accounts/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ variable "postgres_client_key_secret_id" {
default = null
description = "The secrets manager secret ID of the Base64 & PEM encoded private key for postgres."
}

variable "redis_enable_iam_auth" {
type = bool
description = "Whether to enable IAM authentication for Redis. Used for passwordless authentication."
default = false
}
32 changes: 32 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,35 @@ output "s3_bucket" {
value = local.object_storage.s3_bucket
description = "S3 bucket name"
}

# DEBUG: Redis configuration debug outputs
output "debug_redis_config" {
value = {
redis_passwordless_aws_use_iam = var.redis_passwordless_aws_use_iam
redis_use_password_auth = var.redis_use_password_auth
redis_hostname = local.redis.hostname
redis_username = local.redis.username
redis_password_set = local.redis.password != null ? "YES" : "NO"
redis_use_tls = local.redis.use_tls
redis_iam_auth_condition = var.redis_passwordless_aws_use_iam && !var.redis_use_password_auth
}
description = "DEBUG: Complete Redis configuration for troubleshooting"
}

output "debug_redis_username_chain" {
value = {
raw_redis_username = local.redis.username
redis_user_var_passed = var.redis_passwordless_aws_use_iam && !var.redis_use_password_auth ? local.redis.hostname : ""
friendly_name_prefix = var.friendly_name_prefix
}
description = "DEBUG: Redis username propagation chain"
}

output "debug_module_values" {
value = {
redis_passwordless_aws_use_iam = var.redis_passwordless_aws_use_iam && !var.redis_use_password_auth
redis_passwordless_aws_region = var.redis_passwordless_aws_use_iam && !var.redis_use_password_auth ? data.aws_region.current.name : ""
redis_passwordless_aws_host_name = var.redis_passwordless_aws_use_iam && !var.redis_use_password_auth ? local.redis.hostname : ""
}
description = "DEBUG: Values passed to terraform-random-tfe-utility module"
}
2 changes: 1 addition & 1 deletion tests/standalone-vault/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module "kms" {
}

module "hcp_vault" {
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//fixtures/test_hcp_vault?ref=main"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//fixtures/test_hcp_vault?ref=pravi/IND-5861"

hcp_vault_cluster_id = local.test_name
hcp_vault_cluster_hvn_id = "team-tfe-dev-hvn"
Expand Down
Loading
Loading