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:
Gavin Williams 2022-08-09 16:17:04 +01:00 committed by GitHub
parent 8c1720cee3
commit d72ae6a5da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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