Vault Automation cccc6f9e4c
Backport [VAULT-39160] actions(hcp): add support for testing custom images on HCP into ce/main (#9433)
[VAULT-39160] actions(hcp): add support for testing custom images on HCP (#9345)

Add support for running the `cloud` scenario with a custom image in the
int HCP environment. We support two new tags that trigger new
functionality. If the `hcp/build-image` tag is present on a PR at the
time of `build`, we'll automatically trigger a custom build for the int
environment. If the `hcp/test` tag is present, we'll trigger a custom
build and run the `cloud` scenario with the resulting image.

* Fix a bug in our custom build pattern to handle prerelease versions.
* pipeline(hcp): add `--github-output` support to `show image` and
  `wait image` commands.
* enos(hcp/create_vault_cluster): use a unique identifier for HVN
  and vault clusters.
* actions(enos-cloud): add workflow to execute the `cloud` enos
  scenario.
* actions(build): add support for triggering a custom build and running
  the `enos-cloud` scenario.
* add more debug logging and query without a status
* add shim build-hcp-image for CE workflows

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2025-09-19 09:00:55 -07:00

55 lines
1.3 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package hcp
import (
"context"
"encoding/json"
"fmt"
"log/slog"
)
// ShowImageReq is a request to wait for an image to be available in the
// image service.
type ShowImageReq struct {
Req *GetLatestProductVersionReq `json:"req,omitempty"`
WriteToGithubOutput bool `json:"write_to_github_output,omitempty"`
}
// ShowImageRes is a response to a ShowImageReq.
type ShowImageRes struct {
Res *GetLatestProductVersionRes `json:"res,omitempty"`
}
// Run runs the wait for image request.
func (r *ShowImageReq) Run(ctx context.Context, client *Client) (*ShowImageRes, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
slog.Default().DebugContext(ctx, "showing HCP image")
res := &ShowImageRes{}
var err error
res.Res, err = r.Req.Run(ctx, client)
return res, err
}
// ToGithubOutput marshals just the artifact response to JSON.
func (r *ShowImageRes) ToGithubOutput() ([]byte, error) {
if r == nil || r.Res == nil {
return nil, fmt.Errorf("unable to marshal unitialized response to GITHUB_OUTPUT")
}
b, err := json.Marshal(r.Res.Image)
if err != nil {
return nil, fmt.Errorf("marshaling show-image to GITHUB_OUTPUT JSON: %w", err)
}
return b, nil
}