/** * Adds a firewall rule to the default network so that we can connect to our clients externally. */ private void createFirewall() throws IOException { Firewall firewallRule = new Firewall() .setName("cloud-loadtest-framework-firewall-rule") .setDescription("A firewall rule to allow the driver to coordinate load test instances.") .setAllowed(ImmutableList.of( new Firewall.Allowed() .setIPProtocol("tcp") .setPorts(Collections.singletonList("5000")))); try { compute.firewalls().insert(projectName, firewallRule).execute(); } catch (GoogleJsonResponseException e) { if (e.getStatusCode() != ALREADY_EXISTS) { throw e; } compute.firewalls() .update(projectName, "cloud-loadtest-framework-firewall-rule", firewallRule).execute(); } }