terraform-provider-aviatrix icon indicating copy to clipboard operation
terraform-provider-aviatrix copied to clipboard

Add LB zone_id output for aviatrix_gateway

Open Merlz opened this issue 4 years ago • 1 comments

If you want to add a Route53 Alias entry for the LB (optionally) created by aviatrix_gateway module, then the load balancer zone_id needs to be used in the Route53 Alias record zone_id

Example:

resource "aws_route53_record" "www" {
  zone_id = var.route53_zone_id
  name    = "vpn.example.com"
  type    = "A"

  alias {
    name                   = aviatrix_gateway.avx_vpn_gw.elb_dns_name
    zone_id                = aviatrix_gateway.avx_vpn_gw.elb_zone_id ????
    evaluate_target_health = true
  }
}

A temporary workaround is to use something like this:

data "aws_lb" "vpn_gw_lb" {
  count = var.enable_elb ? 1 : 0
  name = var.elb_name

  depends_on = [aviatrix_gateway.avx_vpn_gw]
}

resource "aws_route53_record" "avx_vpn_gw_lb" {
  count = var.create_gateways && var.enable_elb && var.dns_zone_id != null && var.dns_zone_name != null ? 1 : 0

  name    = "vpn.${var.dns_zone_name}"
  zone_id = var.dns_zone_id
  type    = "A"

  alias {
    name                   = aviatrix_gateway.avx_vpn_gw[0].elb_dns_name
    zone_id                = data.aws_lb.vpn_gw_lb[0].zone_id
    evaluate_target_health = true
  }

  depends_on = [aviatrix_gateway.avx_vpn_gw]
}

Then use this datasource in the alias->zone_id, but it would be better to have the LB zone_id output since using a datasource creates a perpetual TF plan/apply change on each run.

Merlz avatar Sep 02 '20 14:09 Merlz