@@ -20,7 +20,7 @@ resource "azurerm_subnet" "subnet" {
2020 address_prefix = " ${ var . subnet_prefix } "
2121}
2222
23- resource "azurerm_network_security_group" "tf-guide -sg" {
23+ resource "azurerm_network_security_group" "tf-ansible -sg" {
2424 name = " ${ var . prefix } -sg"
2525 location = " ${ var . location } "
2626 resource_group_name = " ${ azurerm_resource_group . terraform_ansible . name } "
@@ -50,21 +50,21 @@ resource "azurerm_network_security_group" "tf-guide-sg" {
5050 }
5151}
5252
53- resource "azurerm_network_interface" "tf-guide -nic" {
54- name = " ${ var . prefix } tf-guide -nic"
53+ resource "azurerm_network_interface" "tf-ansible -nic" {
54+ name = " ${ var . prefix } tf-ansible -nic"
5555 location = " ${ var . location } "
5656 resource_group_name = " ${ azurerm_resource_group . terraform_ansible . name } "
57- network_security_group_id = " ${ azurerm_network_security_group . tf-guide -sg . id } "
57+ network_security_group_id = " ${ azurerm_network_security_group . tf-ansible -sg . id } "
5858
5959 ip_configuration {
6060 name = " ${ var . prefix } ipconfig"
6161 subnet_id = " ${ azurerm_subnet . subnet . id } "
6262 private_ip_address_allocation = " Dynamic"
63- public_ip_address_id = " ${ azurerm_public_ip . tf-guide -pip . id } "
63+ public_ip_address_id = " ${ azurerm_public_ip . tf-ansible -pip . id } "
6464 }
6565}
6666
67- resource "azurerm_public_ip" "tf-guide -pip" {
67+ resource "azurerm_public_ip" "tf-ansible -pip" {
6868 name = " ${ var . prefix } -ip"
6969 location = " ${ var . location } "
7070 resource_group_name = " ${ azurerm_resource_group . terraform_ansible . name } "
@@ -78,7 +78,7 @@ resource "azurerm_virtual_machine" "site" {
7878 resource_group_name = " ${ azurerm_resource_group . terraform_ansible . name } "
7979 vm_size = " ${ var . vm_size } "
8080
81- network_interface_ids = [" ${ azurerm_network_interface . tf-guide -nic . id } " ]
81+ network_interface_ids = [" ${ azurerm_network_interface . tf-ansible -nic . id } " ]
8282 delete_os_disk_on_termination = " true"
8383
8484 storage_image_reference {
@@ -109,14 +109,23 @@ resource "azurerm_virtual_machine" "site" {
109109 }
110110 }
111111
112+
113+
112114 # This is to ensure SSH comes up before we run the local exec.
113115 provisioner "remote-exec" {
114116 inline = [" echo 'Hello World'" ]
117+
118+ connection {
119+ type = " ssh"
120+ host = " ${ azurerm_public_ip . tf-ansible-pip . ip_address } "
121+ user = " ${ var . admin_username } "
122+ private_key = " ${ var . ssh_key } "
123+ }
115124 }
116125
117126# TODO: have Dylan help with apache.yml playbook
118127 provisioner "local-exec" {
119- command = " ansible-playbook -i '${ self . public_ip } ,' --private-key ${ var . ssh_key } apache .yml"
128+ command = " ansible-playbook -i '${ azurerm_public_ip . tf-ansible-pip . ip_address } ,' --private-key ${ var . ssh_key } httpd .yml"
120129 }
121130
122131}
0 commit comments