99
1010 "github.com/gophercloud/gophercloud"
1111 "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
12+
13+ registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
1214)
1315
1416// Artifact is an artifact implementation that contains built images.
@@ -22,9 +24,16 @@ type Artifact struct {
2224 // OpenStack connection for performing API stuff.
2325 Client * gophercloud.ServiceClient
2426
27+ // SourceImage ID of the created image this is actually resolved
28+ // based on a few configured config attributes
29+ SourceImage string
30+
31+ // The region is read from the env OS_REGION_NAME if not provided
32+ Region string
33+
2534 // StateData should store data such as GeneratedData
2635 // to be shared with post-processors
27- StateData map [string ]interface {}
36+ StateData map [string ]any
2837}
2938
3039func (a * Artifact ) BuilderId () string {
@@ -44,7 +53,21 @@ func (a *Artifact) String() string {
4453 return fmt .Sprintf ("An image was created: %v" , a .ImageId )
4554}
4655
47- func (a * Artifact ) State (name string ) interface {} {
56+ func (a * Artifact ) State (name string ) any {
57+
58+ if name == registryimage .ArtifactStateURI {
59+ img , err := registryimage .FromArtifact (a ,
60+ registryimage .WithRegion (a .Region ),
61+ registryimage .WithSourceID (a .SourceImage ),
62+ )
63+
64+ if err != nil {
65+ log .Printf ("[DEBUG] error encountered when creating a registry image %v" , err )
66+ return nil
67+ }
68+ return img
69+
70+ }
4871 return a .StateData [name ]
4972}
5073
0 commit comments