GoogleComputeEngineTemplateOptions options = GoogleComputeEngineTemplateOptions.class.cast(template.getOptions()).clone();
checkState(options.getNetwork().isPresent(), "network was not present in template options");
Hardware hardware = checkNotNull(template.getHardware(), "hardware must be set");
URI machineType = checkNotNull(hardware.getUri(), "hardware uri must be set");
InstanceTemplate instanceTemplate = InstanceTemplate.builder()
.forMachineType(machineType);
if (options.isEnableNat()) {
instanceTemplate.addNetworkInterface(options.getNetwork().get(), Type.ONE_TO_ONE_NAT);
} else {
instanceTemplate.addNetworkInterface(options.getNetwork().get());
}
LoginCredentials credentials = getFromImageAndOverrideIfRequired(template.getImage(), options);
ImmutableMap.Builder<String, String> metadataBuilder = metatadaFromTemplateOptions.apply(options);
instanceTemplate.metadata(metadataBuilder.build());
instanceTemplate.tags(options.getTags());
instanceTemplate.serviceAccounts(options.getServiceAccounts());
instanceTemplate.image(checkNotNull(template.getImage().getUri(), "image URI is null"));
Operation operation = api.getInstanceApiForProject(userProject.get())
.createInZone(name, instanceTemplate, template.getLocation().getId());
if (options.shouldBlockUntilRunning()) {