title: Automatically Grab Latest Google Cloud Platform Secret Version
body: <p>I'm trying to grab the latest secret version. Is there a way to do that without specifying the version number? Such as using the keyword &quot;latest&quot;. I'm trying to avoid having to iterate through all the secret versions with a for loop as GCP documentation shows:</p>
  <pre><code>try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
    // Build the parent name.
    SecretName projectName = SecretName.of(projectId, secretId);
  
    // Get all versions.
    ListSecretVersionsPagedResponse pagedResponse = client.listSecretVersions(projectName);
  
    // List all versions and their state.
    pagedResponse
        .iterateAll()
        .forEach(
            version -&gt; {
              System.out.printf(&quot;Secret version %s, %s\n&quot;, version.getName(), version.getState());
            });
  }
  </code></pre>