Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 77ddb75

Browse files
committed
updated lab
1 parent 06fd10e commit 77ddb75

19 files changed

+214
-719
lines changed

05-a2-forwarder.conf

Lines changed: 0 additions & 37 deletions
This file was deleted.

Automate2Server.tf

Lines changed: 0 additions & 107 deletions
This file was deleted.

AutomateServer.tf

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resource "azurerm_public_ip" "automate_pubip" {
44
location = "${var.azure_region}"
55
resource_group_name = "${azurerm_resource_group.rg.name}"
66
public_ip_address_allocation = "dynamic"
7-
domain_name_label = "${var.automate_server_name}"
7+
domain_name_label = "${var.automate_server_name}-${lower(substr("${join("", split(":", timestamp()))}", 8, -1))}"
88

99
tags {
1010
environment = "${var.azure_env}"
@@ -33,7 +33,6 @@ resource "azurerm_virtual_machine" "automate" {
3333
resource_group_name = "${azurerm_resource_group.rg.name}"
3434
network_interface_ids = ["${azurerm_network_interface.automate_ip.id}"]
3535
vm_size = "${var.automate_vm_size}"
36-
depends_on = ["azurerm_virtual_machine.chef"]
3736

3837
storage_image_reference {
3938
publisher = "Canonical"
@@ -72,46 +71,31 @@ resource "azurerm_virtual_machine" "automate" {
7271

7372
provisioner "file" {
7473
source = "labadmin"
75-
destination = "/home/labadmin/.ssh/id_rsa"
74+
destination = "/home/${var.username}/.ssh/id_rsa"
7675
}
7776

77+
provisioner "remote-exec" {
78+
inline = [
79+
"chmod 700 /home/${var.username}/.ssh/id_rsa",
80+
]
81+
}
7882
provisioner "file" {
7983
source = "labadmin.pub"
80-
destination = "/home/labadmin/.ssh/authorized_keys"
84+
destination = "/home/${var.username}/.ssh/authorized_keys"
8185
}
8286

8387
provisioner "file" {
8488
source = "InstallChefAutomate.sh"
8589
destination = "/tmp/InstallChefAutomate.sh"
8690
}
87-
88-
provisioner "file" {
89-
source = "automate.license"
90-
destination = "/tmp/automate.license"
91-
}
92-
93-
provisioner "file" {
94-
source = "05-a2-forwarder.conf"
95-
destination = "/tmp/05-a2-forwarder.conf"
96-
}
97-
98-
provisioner "file" {
99-
source = "profiles/"
100-
destination = "/tmp"
101-
}
102-
10391
provisioner "remote-exec" {
10492
inline = [
10593
"sudo chmod +x /tmp/InstallChefAutomate.sh",
106-
"sudo /tmp/InstallChefAutomate.sh ${var.automate_server_name} ${var.chef_server_name} ${var.chef_server_user} ${var.chef_server_org_shortname} ${var.automate_server_version} ${var.automate_server_user} ${var.automate_server_user_password} ${var.azure_region} ${var.username} ${var.inspec_version} > install.log",
94+
"sudo /tmp/InstallChefAutomate.sh ${azurerm_public_ip.automate_pubip.fqdn} ${azurerm_public_ip.chef_pubip.fqdn}",
10795
]
10896
}
10997
}
11098

111-
# output "aip" {
112-
# value = "${azurerm_public_ip.automate_pubip.ip_address}"
113-
# }
114-
11599
output "afqdn" {
116100
value = "${azurerm_public_ip.automate_pubip.fqdn}"
117101
}

AzureInfrastructure.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Create a resource group to contain all the objects
44
resource "azurerm_resource_group" "rg" {
5-
name = "${var.azure_rg_name}"
5+
name = "${var.azure_rg_name}-${join("", split(":", timestamp()))}" #Removing the colons since Azure doesn't allow them.
66
location = "${var.azure_region}"
77
}
88

@@ -14,15 +14,15 @@ resource "azurerm_virtual_network" "vnet" {
1414
resource_group_name = "${azurerm_resource_group.rg.name}"
1515
}
1616

17-
# Create the individual subnet for the web servers
17+
# Create the individual subnet for the servers
1818
resource "azurerm_subnet" "subnet" {
1919
name = "${var.azure_rg_name}_Subnet"
2020
resource_group_name = "${azurerm_resource_group.rg.name}"
2121
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
2222
address_prefix = "10.1.1.0/24"
2323
}
2424

25-
# create the network security group to allow inbound access to the server
25+
# create the network security group to allow inbound access to the servers
2626
resource "azurerm_network_security_group" "nsg" {
2727
name = "${var.azure_rg_name}_nsg"
2828
location = "${var.azure_region}"

ChefNodes.tf

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "azurerm_public_ip" "node_pubip" {
55
location = "${var.azure_region}"
66
resource_group_name = "${azurerm_resource_group.rg.name}"
77
public_ip_address_allocation = "dynamic"
8-
domain_name_label = "jm-node${count.index}"
8+
domain_name_label = "node${count.index}-${lower(substr("${join("", split(":", timestamp()))}", 8, -1))}"
99

1010
tags {
1111
environment = "${var.azure_env}"
@@ -22,9 +22,9 @@ resource "azurerm_network_interface" "node_ip" {
2222
ip_configuration {
2323
name = "node${count.index}_ipconf"
2424
subnet_id = "${azurerm_subnet.subnet.id}"
25-
private_ip_address_allocation = "dynamic"
26-
27-
# public_ip_address_id = ["${element(azurerm_public_ip.node_pubip.*.id, count.index)}"]
25+
private_ip_address_allocation = "static"
26+
private_ip_address = "${cidrhost("10.1.1.20/24", 20+count.index)}"
27+
public_ip_address_id = "${element(azurerm_public_ip.node_pubip.*.id, count.index + 1)}"
2828
}
2929
}
3030

@@ -36,7 +36,7 @@ resource "azurerm_virtual_machine" "node" {
3636
resource_group_name = "${azurerm_resource_group.rg.name}"
3737
network_interface_ids = ["${element(azurerm_network_interface.node_ip.*.id, count.index)}"]
3838
vm_size = "${var.chef_node_vm_size}"
39-
depends_on = ["azurerm_virtual_machine.automate2"]
39+
depends_on = ["azurerm_virtual_machine.chef"]
4040

4141
storage_image_reference {
4242
publisher = "Canonical"
@@ -53,7 +53,7 @@ resource "azurerm_virtual_machine" "node" {
5353
}
5454

5555
os_profile {
56-
computer_name = "jm-tr-node${count.index}"
56+
computer_name = "node${count.index}"
5757
admin_username = "${var.username}"
5858
admin_password = "${var.password}"
5959
}
@@ -66,26 +66,26 @@ resource "azurerm_virtual_machine" "node" {
6666
environment = "${var.azure_env}"
6767
}
6868

69-
# connection {
69+
connection {
70+
host = "${element(azurerm_public_ip.node_pubip.*.fqdn, count.index + 1)}"
71+
type = "ssh"
72+
user = "${var.username}"
73+
password = "${var.password}"
74+
}
7075

71-
# host = ["${element(azurerm_public_ip.node.*._pubip.fqdn, count.index)}"]
72-
# type = "ssh"
73-
# user = "${var.username}"
74-
# password = "${var.password}"
75-
# }
76+
provisioner "file" {
77+
source = "labadmin"
78+
destination = "/home/${var.username}/.ssh/id_rsa"
79+
}
7680

77-
# provisioner "file" {
78-
# source = "labadmin"
79-
# destination = "/home/labadmin/.ssh/id_rsa"
80-
# }
81+
provisioner "remote-exec" {
82+
inline = [
83+
"chmod 700 /home/${var.username}/.ssh/id_rsa",
84+
]
85+
}
8186

82-
# provisioner "file" {
83-
# source = "labadmin.pub"
84-
# destination = "/home/labadmin/.ssh/authorized_keys"
85-
# }
87+
provisioner "file" {
88+
source = "labadmin.pub"
89+
destination = "/home/${var.username}/.ssh/authorized_keys"
90+
}
8691
}
87-
88-
# output "node${count.index}fqdn" {
89-
# value = ["${element(azurerm_public_ip.node.*._pubip.fqdn, count.index)}"]
90-
# }
91-

ChefServer.tf

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resource "azurerm_public_ip" "chef_pubip" {
44
location = "${var.azure_region}"
55
resource_group_name = "${azurerm_resource_group.rg.name}"
66
public_ip_address_allocation = "dynamic"
7-
domain_name_label = "${var.chef_server_name}"
7+
domain_name_label = "${var.chef_server_name}-${lower(substr("${join("", split(":", timestamp()))}", 8, -1))}"
88

99
tags {
1010
environment = "${var.azure_env}"
@@ -20,10 +20,8 @@ resource "azurerm_network_interface" "chef_ip" {
2020
ip_configuration {
2121
name = "chef_ipconf"
2222
subnet_id = "${azurerm_subnet.subnet.id}"
23-
24-
# private_ip_address_allocation = "dynamic"
2523
private_ip_address_allocation = "static"
26-
private_ip_address = "10.1.1.10" # "${cidrhost(10.1.1.0/24, 10)}"
24+
private_ip_address = "10.1.1.10"
2725
public_ip_address_id = "${azurerm_public_ip.chef_pubip.id}"
2826
}
2927
}
@@ -35,6 +33,7 @@ resource "azurerm_virtual_machine" "chef" {
3533
resource_group_name = "${azurerm_resource_group.rg.name}"
3634
network_interface_ids = ["${azurerm_network_interface.chef_ip.id}"]
3735
vm_size = "${var.chef_vm_size}"
36+
depends_on = ["azurerm_virtual_machine.automate"]
3837

3938
storage_image_reference {
4039
publisher = "Canonical"
@@ -73,12 +72,18 @@ resource "azurerm_virtual_machine" "chef" {
7372

7473
provisioner "file" {
7574
source = "labadmin"
76-
destination = "/home/labadmin/.ssh/id_rsa"
75+
destination = "/home/${var.username}/.ssh/id_rsa"
76+
}
77+
78+
provisioner "remote-exec" {
79+
inline = [
80+
"chmod 700 /home/${var.username}/.ssh/id_rsa",
81+
]
7782
}
7883

7984
provisioner "file" {
8085
source = "labadmin.pub"
81-
destination = "/home/labadmin/.ssh/authorized_keys"
86+
destination = "/home/${var.username}/.ssh/authorized_keys"
8287
}
8388

8489
provisioner "file" {
@@ -89,7 +94,7 @@ resource "azurerm_virtual_machine" "chef" {
8994
provisioner "remote-exec" {
9095
inline = [
9196
"sudo chmod +x /tmp/InstallChefServer.sh",
92-
"sudo /tmp/InstallChefServer.sh ${var.automate_server_name} ${var.azure_region} ${var.chef_server_name} ${var.chef_server_version} ${var.chef_server_user} ${var.chef_server_user_password} ${var.chef_server_user_firstname} ${var.chef_server_user_lastname} ${var.chef_server_user_email} ${var.chef_server_org_shortname} '${var.chef_server_org_fullname}' ${var.chef_server_install_pushjobs} ${var.chef_server_pushjobs_version} ${var.chef_server_install_manage} ${var.chef_server_manage_version} ${var.chefdk_version} > install.log ",
97+
"sudo /tmp/InstallChefServer.sh ${azurerm_public_ip.automate_pubip.fqdn} ${azurerm_public_ip.chef_pubip.fqdn} ${var.chef_server_version} ${var.username} ${var.password} ${var.chef_server_user_firstname} ${var.chef_server_user_lastname} ${var.chef_server_user_email} ${var.chef_server_org_shortname} '${var.chef_server_org_fullname}' ${var.chef_server_install_pushjobs} ${var.chef_server_pushjobs_version} ${var.chef_server_install_manage} ${var.chef_server_manage_version} ${var.chefdk_version} > install.log ",
9398
]
9499
}
95100
}

0 commit comments

Comments
 (0)