mirror of
https://github.com/terraform-aws-modules/terraform-aws-rds-proxy.git
synced 2025-12-17 08:21:12 +00:00
Fix issue when attempting to set create_proxy = false
Spotted this issue whilst trying to integrate this module into some existing code where we don't always want to create a RDS Proxy instance, but when we are creating a proxy we want a default set of endpoints. Setting `create_proxy = false` works for the majority of resources, however the `aws_db_proxy_endpoint` resource uses a `for_each` which will try and create endpoints against a non-existent DB proxy. So switch to using a `local` which gets set to an empty map if `var.create_proxy` is false.
This commit is contained in:
parent
8c1720cee3
commit
d72ae6a5da
1 changed files with 5 additions and 4 deletions
3
main.tf
3
main.tf
|
|
@ -2,6 +2,7 @@ locals {
|
||||||
role_arn = var.create_proxy && var.create_iam_role ? aws_iam_role.this[0].arn : var.role_arn
|
role_arn = var.create_proxy && var.create_iam_role ? aws_iam_role.this[0].arn : var.role_arn
|
||||||
role_name = coalesce(var.iam_role_name, var.name)
|
role_name = coalesce(var.iam_role_name, var.name)
|
||||||
policy_name = coalesce(var.iam_policy_name, var.name)
|
policy_name = coalesce(var.iam_policy_name, var.name)
|
||||||
|
db_proxy_endpoints = var.create_proxy ? var.db_proxy_endpoints : {}
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_region" "current" {}
|
data "aws_region" "current" {}
|
||||||
|
|
@ -68,7 +69,7 @@ resource "aws_db_proxy_target" "db_cluster" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_db_proxy_endpoint" "this" {
|
resource "aws_db_proxy_endpoint" "this" {
|
||||||
for_each = var.db_proxy_endpoints
|
for_each = local.db_proxy_endpoints
|
||||||
|
|
||||||
db_proxy_name = aws_db_proxy.this[0].name
|
db_proxy_name = aws_db_proxy.this[0].name
|
||||||
db_proxy_endpoint_name = each.value.name
|
db_proxy_endpoint_name = each.value.name
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue