func (kms *GoogleCloudKMS) CreateKeyVersion(ctx context.Context, parent string) (string, error) {
	result, err := kms.client.CreateCryptoKeyVersion(ctx, &kmspb.CreateCryptoKeyVersionRequest{
		Parent: parent,
	})
	if err != nil {
		return "", fmt.Errorf("failed to create key version: %w", err)
	}

	b := retry.WithMaxRetries(10, retry.NewConstant(500*time.Millisecond))
	if err := retry.Do(ctx, b, func(ctx context.Context) error {
		version, err := kms.client.GetCryptoKeyVersion(ctx, &kmspb.GetCryptoKeyVersionRequest{
			Name: result.Name,
		})
		if err != nil {
			return fmt.Errorf("failed to validate if key was created: %w", err)
		}

		if version.State == kmspb.CryptoKeyVersion_ENABLED {
			return nil
		}
		return retry.RetryableError(fmt.Errorf("key is not ready (%s)", version.State))
	}); err != nil {
		return "", err
	}

	return result.Name, nil
}
// CreateKeyVersion creates a new version for the given key. The parent key must
// already exist.
CreateKeyVersion creates a new version for the given key. The parent key must
already exist.
// CreateKeyVersion creates a new version for the given key . The parent key must // already exist .
func (kms *GoogleCloudKMS) CreateKeyVersion(ctx context.Context, parent string) (string, error) {
	result, err := kms.client.CreateCryptoKeyVersion(ctx, &kmspb.CreateCryptoKeyVersionRequest{
		Parent: parent,
	})
	if err != nil {
		return "", fmt.Errorf("failed to create key version: %w", err)
	}
	b := retry.WithMaxRetries(10, retry.NewConstant(500*time.Millisecond))
	if err := retry.Do(ctx, b, func(ctx context.Context) error {
		version, err := kms.client.GetCryptoKeyVersion(ctx, &kmspb.GetCryptoKeyVersionRequest{
			Name: result.Name,
		})
		if err != nil {
			return fmt.Errorf("failed to validate if key was created: %w", err)
		}
		if version.State == kmspb.CryptoKeyVersion_ENABLED {
			return nil
		}
		return retry.RetryableError(fmt.Errorf("key is not ready (%s)", version.State))
	}); err != nil {
		return "", err
	}
	return result.Name, nil
}
func ( kms * GoogleCloudKMS ) CreateKeyVersion ( ctx context . Context , parent string ) ( string , error ) { result , err := kms . client . CreateCryptoKeyVersion ( ctx , & kmspb . CreateCryptoKeyVersionRequest { Parent : parent , } ) if err != nil { return " " , fmt . Errorf ( " " , err ) } b := retry . WithMaxRetries ( 10 , retry . NewConstant ( 500 * time . Millisecond ) ) if err := retry . Do ( ctx , b , func ( ctx context . Context ) error { version , err := kms . client . GetCryptoKeyVersion ( ctx , & kmspb . GetCryptoKeyVersionRequest { Name : result . Name , } ) if err != nil { return fmt . Errorf ( " " , err ) } if version . State == kmspb . CryptoKeyVersion_ENABLED { return nil } return retry . RetryableError ( fmt . Errorf ( " " , version . State ) ) } ) ; err != nil { return " " , err } return result . Name , nil }
CreateKeyVersion creates a new version for the given key.
CreateKeyVersion creates a new version for the given key .