Skip to content

Commit

Permalink
Merge branch 'main' into Fix-VM-size
Browse files Browse the repository at this point in the history
  • Loading branch information
ned1313 authored Aug 1, 2022
2 parents 87d4da5 + 54c1bc4 commit 0b136b7
Show file tree
Hide file tree
Showing 9 changed files with 508 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
47 changes: 37 additions & 10 deletions 08-meta-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,44 @@ Add a count argument to the Azure Virtual Machine resource in `main.tf` with a v
```hcl
# ...
resource "azurerm_virtual_machine" "training" {
count = 2
name = "${var.prefix}vm-${count.index + 1}"
location = azurerm_resource_group.training.location
resource_group_name = azurerm_resource_group.training.name
count = 2
name = "${var.prefix}vm-${count.index + 1}"
location = azurerm_resource_group.training.location
resource_group_name = azurerm_resource_group.training.name
network_interface_ids = [azurerm_network_interface.training[count.index].id]
vm_size = "Standard_D2s_v4"
# ... leave the rest of the resource block unchanged...
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "${var.prefix}disk-${count.index + 1}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "${var.computer_name}-${count.index + 1}"
admin_username = var.admin_username
admin_password = var.admin_password
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = var.EnvironmentTag
}
}
The name of the storage disk also needs to be updated to reflect the use of count:
Notice that the name of the storage disk also needs to be updated to reflect the use of count:
storage_os_disk {
name = "${var.prefix}disk-${count.index + 1}"
Expand All @@ -53,11 +81,10 @@ resource "azurerm_network_interface" "training" {
resource_group_name = azurerm_resource_group.training.name
ip_configuration {
name = "azureuser${var.prefix}ip"
name = "azureuser${var.prefix}ip-${count.index + 1}"
subnet_id = azurerm_subnet.training.id
private_ip_address_allocation = "dynamic"
#private_ip_address = "10.0.2.5"
public_ip_address_id = azurerm_public_ip.training[count.index].id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.training[count.index].id
}
}
Expand Down
14 changes: 3 additions & 11 deletions 09-provisioners.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ resource "azurerm_network_interface" "nic" {
ip_configuration {
name = "${var.prefix}NICConfg"
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "dynamic"
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.publicip.id
}
}
Expand Down Expand Up @@ -335,18 +335,10 @@ azurerm_virtual_machine.vm
azurerm_virtual_network.vnet
```

Taint our VM:
```shell
terraform taint azurerm_virtual_machine.vm
```

```text
Resource instance azurerm_virtual_machine.vm has been marked as tainted.
```
Replace our VM using the `terraform apply -replace` option:

Run an `apply` and confirm:
```shell
terraform apply
terraform apply -replace azurerm_virtual_machine.vm
```

```text
Expand Down
5 changes: 4 additions & 1 deletion 11-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ resource "azurerm_network_interface" "main" {
ip_configuration {
name = "config1"
subnet_id = azurerm_subnet.main.id
private_ip_address_allocation = "dynamic"
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.main.id
}
}
Expand All @@ -86,6 +86,9 @@ resource "azurerm_virtual_machine" "main" {
resource_group_name = azurerm_resource_group.main.name
network_interface_ids = [azurerm_network_interface.main.id]
vm_size = var.vm_size
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_image_reference {
publisher = "Canonical"
Expand Down
Loading

0 comments on commit 0b136b7

Please sign in to comment.