This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsServer.tf
109 lines (91 loc) · 2.89 KB
/
JenkinsServer.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#create a public IP address for the virtual machine
resource "azurerm_public_ip" "jenkins_pubip" {
name = "jenkins_pubip"
location = var.azure_region
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Dynamic"
domain_name_label = "${var.jenkins_server_name}-${lower(substr(join("", split(":", timestamp())), 8, -1))}"
}
#create the network interface and put it on the proper vlan/subnet
resource "azurerm_network_interface" "jenkins_ip" {
name = "jenkins_ip"
location = var.azure_region
resource_group_name = azurerm_resource_group.rg.name
ip_configuration {
name = "jenkins_ipconf"
subnet_id = azurerm_subnet.subnet.id
# private_ip_address_allocation = "dynamic"
private_ip_address_allocation = "static"
private_ip_address = "10.1.1.13"
public_ip_address_id = azurerm_public_ip.jenkins_pubip.id
}
}
#create the actual VM
resource "azurerm_virtual_machine" "jenkins" {
name = "jenkins"
location = var.azure_region
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [azurerm_network_interface.jenkins_ip.id]
vm_size = var.jenkins_vm_size
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "jenkins_osdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = var.jenkins_server_name
admin_username = var.username
admin_password = var.password
}
os_profile_linux_config {
disable_password_authentication = false
}
connection {
host = azurerm_public_ip.jenkins_pubip.fqdn
type = "ssh"
user = var.username
password = var.password
}
provisioner "file" {
source = "labadmin"
destination = "/home/${var.username}/.ssh/id_rsa"
}
provisioner "remote-exec" {
inline = [
"chmod 700 /home/${var.username}/.ssh/id_rsa",
]
}
provisioner "file" {
source = "labadmin.pub"
destination = "/home/${var.username}/.ssh/authorized_keys"
}
provisioner "file" {
source = "jenkins.rc.local"
destination = "/home/${var.username}/rc.local"
}
provisioner "file" {
source = "InstalljenkinsServer.sh"
destination = "/tmp/InstalljenkinsServer.sh"
}
provisioner "file" {
source = "BootstrapNodes.sh"
destination = "/tmp/BootstrapNodes.sh"
}
provisioner "remote-exec" {
inline = [
"sudo chmod +x /tmp/InstalljenkinsServer.sh",
"sudo chmod +x /tmp/BootstrapNodes.sh",
"sudo /tmp/BootstrapNodes.sh ${var.username} ${var.password} > bootstrap_nodes.log",
]
}
}
output "jfqdn" {
value = azurerm_public_ip.jenkins_pubip.fqdn
}