Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 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
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"
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 = "github.com/hashicorp/terraform-random-tfe-utility//fixtures/test_proxy_init?ref=pravi/IND-5861"
source = "github.com/hashicorp/terraform-random-tfe-utility//fixtures/test_proxy_init?ref=main"

Copilot uses AI. Check for mistakes.

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
57 changes: 32 additions & 25 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module "service_accounts" {
postgres_client_key_secret_id = var.postgres_client_key_secret_id
postgres_ca_certificate_secret_id = var.postgres_ca_certificate_secret_id
vm_key_secret_id = var.vm_key_secret_id
redis_enable_iam_auth = var.redis_passwordless_aws_use_instance_profile
redis_replication_group_id = var.redis_passwordless_aws_use_instance_profile ? local.redis.cluster_id : null
redis_iam_user_name = var.redis_passwordless_aws_use_instance_profile ? local.redis.iam_user : null
Comment on lines +48 to +50
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.

Circular dependency detected: module.service_accounts (lines 48-50) references local.redis.cluster_id and local.redis.iam_user, which come from module.redis outputs. However, module.redis (line 88) depends on module.vm.tfe_instance_sg, and module.vm is declared after both modules. This creates a dependency cycle: service_accounts → redis → vm. Consider restructuring to break this cycle, perhaps by making the IAM policy attachment conditional or by passing the security group ID differently.

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +50
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.

Potential runtime error: Lines 49-50 reference local.redis.cluster_id and local.redis.iam_user, but these fields don't exist in local.redis_default (see locals.tf). If redis_passwordless_aws_use_instance_profile is enabled without active-active mode, the module will fail. Add validation to ensure redis_passwordless_aws_use_instance_profile can only be true when operational_mode == "active-active", or add cluster_id and iam_user fields to redis_default in locals.tf.

Copilot uses AI. Check for mistakes.
}

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -79,12 +82,10 @@ module "redis" {
source = "./modules/redis"
count = local.enable_redis_module && var.enable_redis_sentinel == false || local.enable_redis_module && local.redis_mtls_enabled == false ? 1 : 0

active_active = var.operational_mode == "active-active"
friendly_name_prefix = var.friendly_name_prefix
network_id = local.network_id
network_private_subnet_cidrs = var.network_private_subnet_cidrs
network_subnets_private = local.network_private_subnets
tfe_instance_sg = module.vm.tfe_instance_sg
active_active = var.operational_mode == "active-active"
friendly_name_prefix = var.friendly_name_prefix
network_subnets_private = local.network_private_subnets
tfe_instance_sg = module.vm.tfe_instance_sg

cache_size = var.redis_cache_size
engine_version = var.redis_engine_version
Expand All @@ -94,6 +95,7 @@ module "redis" {
redis_encryption_in_transit = var.redis_encryption_in_transit
redis_encryption_at_rest = var.redis_encryption_at_rest
redis_use_password_auth = var.redis_use_password_auth
redis_enable_iam_auth = var.redis_passwordless_aws_use_instance_profile
redis_port = var.redis_encryption_in_transit ? "6380" : "6379"
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.

The redis_authentication_mode variable is not being passed to the redis module, but it's used in modules/redis/main.tf line 6 to determine password authentication. Add redis_authentication_mode = var.redis_authentication_mode to the module inputs.

Suggested change
redis_port = var.redis_encryption_in_transit ? "6380" : "6379"
redis_port = var.redis_encryption_in_transit ? "6380" : "6379"
redis_authentication_mode = var.redis_authentication_mode

Copilot uses AI. Check for mistakes.
}

Expand Down Expand Up @@ -253,7 +255,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"
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/runtime_container_engine_config?ref=pravi/IND-5861"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=main"

Copilot uses AI. Check for mistakes.
count = var.is_replicated_deployment ? 0 : 1

tfe_license = var.hc_license
Expand Down Expand Up @@ -312,21 +314,25 @@ 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 = var.redis_passwordless_aws_use_instance_profile ? false : local.redis.use_password_auth
redis_passwordless_aws_use_instance_profile = var.redis_passwordless_aws_use_instance_profile && !var.redis_use_password_auth
redis_passwordless_aws_region = var.redis_passwordless_aws_region
redis_passwordless_aws_host_name = var.redis_passwordless_aws_use_instance_profile && !var.redis_use_password_auth ? local.redis.cluster_id : local.redis.hostname
redis_passwordless_aws_iam_user = var.redis_passwordless_aws_use_instance_profile && !var.redis_use_password_auth ? local.redis.iam_user : null
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
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems there is another issue here, if this was the case then the existing tests would have failed and same way of configuration is also used for database, I request to pls have a look at this issue



trusted_proxies = local.trusted_proxies
Expand All @@ -343,7 +349,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.
count = var.is_replicated_deployment ? 0 : 1

cloud = "aws"
Expand Down Expand Up @@ -388,7 +394,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"
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/settings?ref=pravi/IND-5861"
source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/settings?ref=main"

Copilot uses AI. Check for mistakes.
count = var.is_replicated_deployment ? 1 : 0

# TFE Base Configuration
Expand Down Expand Up @@ -450,7 +456,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.
count = var.is_replicated_deployment ? 1 : 0

# TFE & Replicated Configuration data
Expand Down Expand Up @@ -540,6 +546,7 @@ module "vm" {
network_private_subnet_cidrs = local.network_private_subnet_cidrs
node_count = var.node_count
user_data_base64 = var.is_replicated_deployment ? module.tfe_init_replicated[0].tfe_userdata_base64_encoded : module.tfe_init_fdo[0].tfe_userdata_base64_encoded
existing_security_group_id = var.existing_vm_security_group_id
}

module "edb" {
Expand Down
1 change: 1 addition & 0 deletions modules/database/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ output "name" {
output "password" {
value = aws_db_instance.postgresql.password
description = "The password of the main PostgreSQL user."
sensitive = true
}

output "username" {
Expand Down
105 changes: 59 additions & 46 deletions modules/redis/main.tf
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

# Redis module - simplified to reuse TFE security group instead of creating separate ones
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" {
count = var.active_active && local.redis_use_password_auth ? 1 : 0
byte_length = 16
}

resource "aws_security_group" "redis" {
count = var.active_active ? 1 : 0
description = "The security group of the Redis deployment for TFE."
name = "${var.friendly_name_prefix}-tfe-redis"
vpc_id = var.network_id
resource "aws_elasticache_subnet_group" "tfe" {
count = var.active_active ? 1 : 0
name = "${var.friendly_name_prefix}-tfe-redis"
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

}

resource "aws_security_group_rule" "redis_tfe_ingress" {
count = var.active_active ? 1 : 0
security_group_id = aws_security_group.redis[0].id
type = "ingress"
from_port = var.redis_port
to_port = var.redis_port
protocol = "tcp"
source_security_group_id = var.tfe_instance_sg
}
# Note: For IAM authentication, we let AWS manage the built-in "default" user
# We don't explicitly manage it since it's needed for IAM authentication with username "default"

resource "aws_security_group_rule" "redis_tfe_egress" {
count = var.active_active ? 1 : 0
security_group_id = aws_security_group.redis[0].id
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = var.tfe_instance_sg
}
# 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"

resource "aws_security_group_rule" "redis_ingress" {
count = var.active_active ? 1 : 0
security_group_id = aws_security_group.redis[0].id
type = "ingress"
from_port = var.redis_port
to_port = var.redis_port
protocol = "tcp"
cidr_blocks = var.network_private_subnet_cidrs
}
# 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"
}

resource "aws_security_group_rule" "redis_egress" {
count = var.active_active ? 1 : 0
security_group_id = aws_security_group.redis[0].id
type = "egress"
from_port = var.redis_port
to_port = var.redis_port
protocol = "tcp"
cidr_blocks = var.network_private_subnet_cidrs
}

resource "aws_elasticache_subnet_group" "tfe" {
count = var.active_active ? 1 : 0
name = "${var.friendly_name_prefix}-tfe-redis"
subnet_ids = var.network_subnets_private
# ElastiCache User Group for IAM authentication
# AWS requires the "default" user to be included in all user groups
# We include both "default" (for IAM auth) and our custom IAM user
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", # AWS-managed default user for IAM authentication
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" {
Expand All @@ -77,15 +78,27 @@ resource "aws_elasticache_replication_group" "redis" {
engine_version = var.engine_version
parameter_group_name = var.parameter_group_name
port = var.redis_port
security_group_ids = [aws_security_group.redis[0].id]
security_group_ids = [var.tfe_instance_sg] # Reuse TFE security group instead of creating separate one
snapshot_retention_limit = 0
subnet_group_name = aws_elasticache_subnet_group.tfe[0].name

# 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
# For IAM authentication, auth_token must be null to force IAM-only authentication
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

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
]
}
18 changes: 14 additions & 4 deletions modules/redis/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ output "password" {
}

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 = local.redis_use_iam_auth ? 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 for IAM authentication, null for password authentication."
}

output "redis_port" {
Expand Down Expand Up @@ -61,6 +61,16 @@ output "aws_elasticache_subnet_group_name" {
}

output "aws_security_group_redis" {
value = var.active_active ? aws_security_group.redis[0].id : ""
description = "The identity of the security group attached to the Redis Elasticache replication group."
value = var.active_active ? var.tfe_instance_sg : ""
description = "The identity of the security group used by Redis Elasticache replication group (shared with TFE instances)."
}

output "cluster_id" {
value = var.active_active ? aws_elasticache_replication_group.redis[0].replication_group_id : ""
description = "The Redis cluster ID for IAM authentication."
}

output "iam_user" {
value = local.redis_use_iam_auth ? aws_elasticache_user.iam_user[0].user_name : null
description = "The custom IAM user for Redis IAM authentication."
}
16 changes: 6 additions & 10 deletions modules/redis/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ variable "tfe_instance_sg" {
type = string
}

variable "network_id" {
description = "The identity of the VPC in which the security group attached to the Redis Elasticache replication group will be deployed."
type = string
}

variable "network_subnets_private" {
description = "A list of the identities of the private subnetworks in which the Redis Elasticache replication group will be deployed."
type = list(string)
Expand All @@ -31,11 +26,6 @@ variable "friendly_name_prefix" {
description = "(Required) Friendly name prefix used for tagging and naming AWS resources."
}

variable "network_private_subnet_cidrs" {
type = list(string)
description = "(Optional) List of private subnet CIDR ranges to create in VPC."
}

variable "redis_port" {
type = number
description = "Set port for Redis. Defaults to 6379 default port"
Expand Down Expand Up @@ -67,6 +57,12 @@ variable "parameter_group_name" {
description = "Redis parameter group name."
}

variable "redis_enable_iam_auth" {
type = bool
description = "Enable IAM authentication for Redis ElastiCache."
default = false
}

# Security
variable "redis_encryption_in_transit" {
type = bool
Expand Down
32 changes: 32 additions & 0 deletions modules/service_accounts/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

data "aws_region" "current" {}
data "aws_caller_identity" "current" {}

resource "aws_iam_instance_profile" "tfe" {
count = var.existing_iam_instance_profile_name == null ? 1 : 0

Expand Down Expand Up @@ -114,3 +117,32 @@ 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 = [
"arn:aws:elasticache:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:replicationgroup:${var.redis_replication_group_id}",
"arn:aws:elasticache:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:user:${var.redis_iam_user_name}"
]
},
]
})
}
Loading
Loading