-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
88 lines (78 loc) · 2.38 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#######################
# TAGS #
#######################
resource "digitalocean_tag" "module" {
name = "devops"
}
resource "digitalocean_tag" "email" {
name = var.email
}
resource "digitalocean_ssh_key" "LexKey" {
name = "LexKey"
public_key = var.pub_key
}
#######################
# VPS #
#######################
resource "digitalocean_droplet" "web" {
count = var.web_count
image = "ubuntu-20-04-x64"
name = "web-${count.index+1}"
region = "nyc1"
size = "s-1vcpu-1gb"
ssh_keys = [digitalocean_ssh_key.LexKey.fingerprint]
tags = [digitalocean_tag.module.id,digitalocean_tag.email.id]
}
resource "digitalocean_droplet" "lb" {
count = var.lb_count
image = "ubuntu-20-04-x64"
name = "lb-${count.index+1}"
region = "nyc1"
size = "s-1vcpu-1gb"
ssh_keys = [digitalocean_ssh_key.LexKey.fingerprint]
tags = [digitalocean_tag.module.id,digitalocean_tag.email.id]
}
#######################
# DNS #
#######################
data "aws_route53_zone" "dzone" {
name = var.dns_zone
}
resource "aws_route53_record" "LB_DNS_RECORDS" {
count = var.lb_count
zone_id = data.aws_route53_zone.dzone.zone_id
name = "lex-lb-${count.index+1}.${data.aws_route53_zone.dzone.name}"
type = "A"
ttl = "300"
records = [digitalocean_droplet.lb[count.index].ipv4_address]
}
# OPTIONAL FIX WHEN POSSIBLE
# resource "aws_route53_record" "LB_APP_A_RECORD" {
# count = var.lb_count
# zone_id = data.aws_route53_zone.dzone.zone_id
# name = "lex-app.${data.aws_route53_zone.dzone.name}"
# type = "A"
# ttl = "30"
# set_identifier = "app"
# multivalue_answer_routing_policy = true
# records = [digitalocean_droplet.lb[count.index].ipv4_address]
# }
resource "aws_route53_record" "WEB_DNS_RECORDS" {
count = var.web_count
zone_id = data.aws_route53_zone.dzone.zone_id
name = "lex-web-${count.index+1}.${data.aws_route53_zone.dzone.name}"
type = "A"
ttl = "300"
records = [digitalocean_droplet.web[count.index].ipv4_address]
}
#######################
# CONFIGURE #
#######################
resource "null_resource" "Ansible" {
depends_on = [
local_file.AnsibleInventory
]
provisioner "local-exec" {
command = "sleep 45 && ansible-playbook ans/ng-role-playbook.yaml -i ans/inventory -u root"
}
}