Skip to content

Commit

Permalink
update (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
yupwei68 authored Nov 23, 2020
1 parent 869704f commit f38e05f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ resource "azurerm_public_ip" "vm" {
tags = var.tags
}

// Dynamic public ip address will be got after it's assigned to a vm
data "azurerm_public_ip" "vm" {
count = var.nb_public_ip
name = azurerm_public_ip.vm[count.index].name
resource_group_name = data.azurerm_resource_group.vm.name
depends_on = [azurerm_virtual_machine.vm-linux, azurerm_virtual_machine.vm-windows]
}

resource "azurerm_network_security_group" "vm" {
name = "${var.vm_hostname}-nsg"
resource_group_name = data.azurerm_resource_group.vm.name
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output "public_ip_id" {

output "public_ip_address" {
description = "The actual ip address allocated for the resource."
value = azurerm_public_ip.vm.*.ip_address
value = data.azurerm_public_ip.vm.*.ip_address
}

output "public_ip_dns_name" {
Expand Down

0 comments on commit f38e05f

Please sign in to comment.