#Terraform and its management of DNS in route53

#Setup the domain in route53
resource "aws_route53_zone" "ahoskingit" {
    name = "ahoskingit.com"
}

resource "aws_route53_record" "ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "ahoskingit.com"
    type = "A"
    ttl = "5"
    records = ["${var.site5_ip}"]
}

resource "aws_route53_record" "ahoskingit_www" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "www.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.ahoskingit.name}"]
}

resource "aws_route53_record" "home_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "home.ahoskingit.com"
    type = "A"
    ttl = "5"
    records = ["${var.home_ip}"]
}

resource "aws_route53_record" "baby_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "baby.ahoskingit.com"
    type = "A"
    ttl = "5"
    records = ["${var.home_ip}"]
}

resource "aws_route53_record" "kfa_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "kfa.ahoskingit.com"
    type = "A"
    ttl = "5"
    records = ["${var.kfa_ip}"]
}

resource "aws_route53_record" "lab_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "lab.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.kfa_ahoskingit.name}"]
}

resource "aws_route53_record" "logs_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "logs.ahoskingit.com"
    type = "A"
    ttl = "5"
    records = ["${var.home_ip}"]
}

resource "aws_route53_record" "inventory_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "inventory.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "requests_plex_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "requests.plex.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}
resource "aws_route53_record" "plex_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "plex.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "ns1_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "ns1.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "docs_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "docs.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "cloud_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "cloud.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "goals_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "goals.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "office_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "office.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "support_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "support.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "git_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "git.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "gitlab_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "gitlab"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

resource "aws_route53_record" "monitors_ahoskingit" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "monitors.ahoskingit.com"
    type = "CNAME"
    ttl = "5"
    records = ["${aws_route53_record.home_ahoskingit.name}"]
}

#Route53 DNS entry
#resource "aws_route53_record" "www_ahoskingit" {
#    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
#    name = "www.ahoskingit.com"
#    type = "A"
#    ttl = "5"
#    records = ["${var.home_ip}"]
#}

# email MX records for DNS
resource "aws_route53_record" "ahoskingit_mx" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "${aws_route53_zone.ahoskingit.name}"
    type = "MX"
    ttl = "60"
    records = ["1 ASPMX.L.GOOGLE.COM",
               "5 ALT1.ASPMX.L.GOOGLE.COM",
               "5 ALT2.ASPMX.L.GOOGLE.COM",
               "10 ALT3.ASPMX.L.GOOGLE.COM",
               "10 ALT4.ASPMX.L.GOOGLE.COM"]
}
resource "aws_route53_record" "ahoskingit_txt" {
    zone_id = "${aws_route53_zone.ahoskingit.zone_id}"
    name = "${aws_route53_zone.ahoskingit.name}"
    type = "TXT"
    ttl = "60"
    records = ["google-site-verification=8-QKnBQElI58gnygDWcCzvDGRh31c_bFmNMaSd0fCwE"]
}
