Skip to content

Commit

Permalink
Expose publicIP correctly for Azure Webserver (pulumi#93)
Browse files Browse the repository at this point in the history
Use the workaround from hashicorp/terraform-provider-azurerm#764 (comment) to correctly get ahold of the public IP address for an Azure VM.

It's slightly unfortunate that the Azure API requires this, but better to make this example work correctly than leave the TODO in place.
  • Loading branch information
lukehoban committed Jun 28, 2018
1 parent 0ddc583 commit 723deea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 2 additions & 3 deletions azure-js-webserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ passwords](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/faq#w
1. Check the IP address:

```
$ pulumi stack output privateIP
10.0.2.4
$ pulumi stack output publicIP
40.112.181.239
```

*TODO*: Expose the Public IP address as well so that the VM can be SSH'd into or CURL'd directly.
12 changes: 9 additions & 3 deletions azure-js-webserver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ let vm = new azure.compute.VirtualMachine("server-vm", {
},
});

// Note - due to a bug in the terraform-provider-azurerm, the public IP address is not yet populated corerctly.
exports.publicIP = publicIP.ipAddress;
exports.privateIP = networkInterface.privateIpAddress;
// The public IP address is not allocated until the VM is running, so we wait
// for that resource to create, and then lookup the IP address again to report
// its public IP.
exports.publicIP = vm.id.apply(_ =>
azure.network.getPublicIP({
name: publicIP.name,
resourceGroupName: publicIP.resourceGroupName,
}).then(ip => ip.ipAddress)
);

0 comments on commit 723deea

Please sign in to comment.