locals {
  environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
  partition_vars = read_terragrunt_config(find_in_parent_folders("partition.hcl"))
  region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
  account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))
  global_vars = read_terragrunt_config(find_in_parent_folders("globals.hcl"))
}

terraform {
  # Double slash is intentional and required to show root of modules
  source = "git@github.xdr.accenturefederalcyber.com:mdr-engineering/xdr-terraform-modules.git//base/transit_gateway_interconnect_vpn?ref=v1.24.0"
}

dependency "transit-gateway-hub" {
  config_path = "../008-transit-gateway-hub"
}

dependency "interconnect-instances" {
  config_path = local.account_vars.locals.interconnect_instances_path
}

# Include all settings from the root terragrunt.hcl file
include {
  path = find_in_parent_folders()
}

# These are the variables we have to pass in to use the module specified in the terragrunt source above
inputs = {
  # All of the inputs from the inherited hcl files are available automatically
  # (via the `inputs` section of the root `terragrunt.hcl`). However, modules
  # will be more flexible if you specify particular input values.
  name = "${local.partition_vars.locals.aws_partition_alias}-${local.environment_vars.locals.environment}"
  tags = {
    Purpose = "Transit Gateway VPN"
    Terraform = "aws/${basename(get_parent_terragrunt_dir())}/${path_relative_to_include()}/"
  }
  interconnect_public_ips = dependency.interconnect-instances.outputs.public_ips
  interconnect_private_ips = dependency.interconnect-instances.outputs.private_ips
  transit_gateway_id = dependency.transit-gateway-hub.outputs.tgw_id
}
