Skip to content

Commit

Permalink
Azure: directly attach an existing public IP to a VM from creation
Browse files Browse the repository at this point in the history
- Add the optional public IP address into the Options model
- Only attach the IP address to the first instance to create
  • Loading branch information
vinseon committed Apr 19, 2017
1 parent fc0944b commit b867861
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public Set<Instance> createInstance(Infrastructure infrastructure, Instance inst
secGrpName)
.get());

// Get existing public IP address if specified
Optional<PublicIpAddress> optionalPublicIpAddress = options.map(Options::getPublicIpAddress)
.map(publicIpAddress -> azureProviderUtils.searchPublicIpAddressByIp(azureService,
publicIpAddress)
.get());

// Prepare the VM(s)
Optional<Boolean> optionalStaticPublicIP = options.map(Options::getStaticPublicIP);
List<Creatable<VirtualMachine>> creatableVirtualMachines = IntStream.rangeClosed(1,
Expand Down Expand Up @@ -217,7 +223,8 @@ public Set<Instance> createInstance(Infrastructure infrastructure, Instance inst
creatableNetworkSecurityGroup,
optionalNetworkSecurityGroup.orElse(null),
creatablePublicIpAddress,
null);
instanceNumber == 1 ? optionalPublicIpAddress.orElse(null)
: null);

return prepareVirtualMachine(instance,
azureService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class Options {

private String region;

private String publicIpAddress;

private String privateNetworkCIDR;

private Boolean staticPublicIP;
Expand Down

0 comments on commit b867861

Please sign in to comment.