-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
75 lines (63 loc) · 1.92 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
data "hcloud_ssh_key" "devops" {
name = "REBRAIN.SSH.PUB.KEY"
}
resource "hcloud_ssh_key" "asduk_key" {
name = "asduk_key"
public_key = file(var.asduk_key)
}
data "hcloud_server" "serverinfo" {
id = hcloud_server.devops_23uk.id
}
resource "hcloud_server" "devops_23uk" {
image = "centos-7"
name = "devops-23uk"
server_type = "cx11"
labels = {
module = "devops"
email = "23uk_at_tut_by"
}
location = "fsn1"
ssh_keys = [data.hcloud_ssh_key.devops.id,hcloud_ssh_key.asduk_key.id]
provisioner "local-exec" {
command = <<EOF
echo --- > host.yml
echo all: >> host.yml
echo " children:" >> host.yml
echo " rebrain:" >> host.yml
echo " hosts:" >> host.yml
echo " ANS01:" >> host.yml
echo " ansible_host: 23uk.devops.rebrain.srwx.net" >> host.yml
echo " vars:" >> host.yml
echo " ansible_user: root" >> host.yml
echo " ansible_ssh_private_key_file: ./.ssh/id_rsa" >> host.yml
echo --- > playbook.yml
echo "- name: Install Nginx" >> playbook.yml
echo " hosts: all" >> playbook.yml
echo " become: yes" >> playbook.yml
echo " tasks:" >> playbook.yml
echo " - name: Install epel-release" >> playbook.yml
echo " yum: name=epel-release state=latest \n" >> playbook.yml
echo " - name: Install Nginx" >> playbook.yml
echo " yum: name=nginx state=latest \n" >> playbook.yml
echo " - name: Autostart webserver" >> playbook.yml
echo " service: name=nginx state=started enabled=yes" >> playbook.yml
EOF
}
}
data "aws_route53_zone" "dns" {
name = "devops.rebrain.srwx.net."
private_zone = false
}
resource "aws_route53_record" "dns_rebrain" {
zone_id = data.aws_route53_zone.dns.zone_id
name = "23uk.devops.rebrain.srwx.net"
type = "A"
ttl = "30"
records = [data.hcloud_server.serverinfo.ipv4_address]
}
output "server_ip" {
value = data.hcloud_server.serverinfo.ipv4_address
}
output "aws_route53_zone" {
value = data.aws_route53_zone.dns.zone_id
}