Skip to content

Commit ee1d076

Browse files
FrostyXsupakeen
authored andcommitted
Allow setting custom tags when uploading to AWS
Fix #242 See osbuild/images#1903 See osbuild/images#1915 See osbuild/images#1939
1 parent 87b9ded commit ee1d076

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cmd/image-builder/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support.
548548
uploadCmd.Flags().String("aws-ami-name", "", "name for the AMI in AWS (only for type=ami)")
549549
uploadCmd.Flags().String("aws-bucket", "", "target S3 bucket name for intermediate storage when creating AMI (only for type=ami)")
550550
uploadCmd.Flags().String("aws-region", "", "target region for AWS uploads (only for type=ami)")
551+
uploadCmd.Flags().StringArray("aws-tag", []string{}, "tag the AMI with this Key=Value (only for type=aws)")
551552
uploadCmd.Flags().String("libvirt-connection", "", "connection URI (only for type=libvirt)")
552553
uploadCmd.Flags().String("libvirt-pool", "", "pool name (only for type=libvirt)")
553554
uploadCmd.Flags().String("libvirt-volume", "", "volume name (only for type=libvirt)")

cmd/image-builder/upload.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ func uploaderForCmdAWS(cmd *cobra.Command, targetArchStr string, bootMode *platf
9797
if err != nil {
9898
return nil, err
9999
}
100+
tags, err := cmd.Flags().GetStringArray("aws-tag")
101+
if err != nil {
102+
return nil, err
103+
}
104+
var slicedTags []awscloud.AWSTag
105+
for _, tag := range tags {
106+
parts := strings.SplitN(tag, "=", 2)
107+
if len(parts) < 2 {
108+
return nil, fmt.Errorf("Invalid tag format: %s (expected key=value)", tag)
109+
}
110+
slicedTags = append(slicedTags, awscloud.AWSTag{
111+
Name: parts[0],
112+
Value: parts[1],
113+
})
114+
}
100115
if bootMode == nil {
101116
// If unset, default to BOOT_HYBIRD which translated
102117
// to "uefi-prefered" when registering the image.
@@ -133,6 +148,7 @@ func uploaderForCmdAWS(cmd *cobra.Command, targetArchStr string, bootMode *platf
133148
opts := &awscloud.UploaderOptions{
134149
TargetArch: targetArch,
135150
BootMode: bootMode,
151+
Tags: slicedTags,
136152
}
137153

138154
return awscloudNewUploader(region, bucketName, amiName, opts)

0 commit comments

Comments
 (0)