From f38e05f2cd2bcd0231f1e8905c297176487a74ec Mon Sep 17 00:00:00 2001 From: Yuping Wei <56525716+yupwei68@users.noreply.github.com> Date: Mon, 23 Nov 2020 17:20:05 +0800 Subject: [PATCH] update (#154) --- main.tf | 8 ++++++++ outputs.tf | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 09ec309..5171079 100644 --- a/main.tf +++ b/main.tf @@ -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 diff --git a/outputs.tf b/outputs.tf index f15a08f..b21e103 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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" {