use of com.google.cloud.compute.v1.SetDeletionProtectionInstanceRequest in project java-docs-samples by GoogleCloudPlatform.
the class SetDeleteProtection method setDeleteProtection.
// Updates the "Delete Protection" setting of given instance.
public static void setDeleteProtection(String projectId, String zone, String instanceName, boolean deleteProtection) throws IOException, ExecutionException, InterruptedException {
try (InstancesClient instancesClient = InstancesClient.create()) {
SetDeletionProtectionInstanceRequest request = SetDeletionProtectionInstanceRequest.newBuilder().setProject(projectId).setZone(zone).setResource(instanceName).setDeletionProtection(deleteProtection).build();
instancesClient.setDeletionProtectionAsync(request).get();
// Retrieve the updated setting from the instance.
System.out.printf("Updated Delete Protection setting: %s", instancesClient.get(projectId, zone, instanceName).getDeletionProtection());
}
}
Aggregations