locals {
  ami_map = {
    "base"       = data.aws_ami.base.image_id,
    "minion"     = data.aws_ami.minion.image_id,
    "master"     = data.aws_ami.master.image_id,
    #    "ubuntu1804" = data.aws_ami.ubuntu1804.image_id,
  }
  # We need some data from the block devices
  block_device_mappings = {
    "base"       = {
      for bd in data.aws_ami.base.block_device_mappings:
        bd.device_name => bd
    }
    "minion"     = {
      for bd in data.aws_ami.minion.block_device_mappings:
        bd.device_name => bd
    }
    "master"     = {
      for bd in data.aws_ami.master.block_device_mappings:
        bd.device_name => bd
    }
    #    "ubuntu1804" = data.aws_ami.ubuntu1804.image_id,
  }
}

data "aws_ami" "base" {
  most_recent = true
  owners = [ var.common_services_account ]

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name = "root-device-type"
    values = ["ebs"]
  }

  filter {
    name = "name"
    values = [ "MSOC_RedHat_Base_*" ]
  }
}

data "aws_ami" "minion" {
  most_recent = true
  owners = [ var.common_services_account ]

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name = "root-device-type"
    values = ["ebs"]
  }

  filter {
    name = "name"
    values = [ "MSOC_RedHat_Minion_*" ]
  }
}

data "aws_ami" "master" {
  most_recent = true
  owners = [ var.common_services_account ]

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name = "root-device-type"
    values = ["ebs"]
  }

  filter {
    name = "name"
    values = [ "MSOC_RedHat_Master_*" ]
  }
}

# Not presently in commercial
#data "aws_ami" "ubuntu1804" {
#  most_recent = true
#  owners = [ var.common_services_account ]
#
#  filter {
#    name   = "virtualization-type"
#    values = ["hvm"]
#  }
#
#  filter {
#    name = "root-device-type"
#    values = ["ebs"]
#  }
#
#  filter {
#    name = "name"
#    values = [ "MSOC_Ubuntu_1804_*" ]
#  }
#}
