From 12728b827e6c59541a1b6180c1cb911a7d80ac8a Mon Sep 17 00:00:00 2001 From: Richard Gooch Date: Fri, 5 Apr 2019 09:48:57 -0700 Subject: [PATCH] Add more special character mappings for AMI name. --- imagepublishers/amipublisher/libAws.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/imagepublishers/amipublisher/libAws.go b/imagepublishers/amipublisher/libAws.go index 19c9897f..9465cc8f 100644 --- a/imagepublishers/amipublisher/libAws.go +++ b/imagepublishers/amipublisher/libAws.go @@ -20,6 +20,23 @@ const ( rootDevName = "/dev/sda1" ) +var ( + amiNameReplacer = strings.NewReplacer( + "@", "@@", + "~", "@tilde@", + "!", "@bang@", + "#", "@hash@", + "$", "@dollar@", + "%", "@percent@", + "^", "@caret@", + "&", "@ampersand@", + "*", "@asterix@", // the gaul. + "=", "@equal@", + "+", "@plus@", + ":", ".", + ) +) + func attachVolume(awsService *ec2.EC2, instance *ec2.Instance, volumeId string, logger log.Logger) error { usedBlockDevices := make(map[string]struct{}) @@ -730,7 +747,7 @@ func registerAmi(awsService *ec2.EC2, snapshotId string, s3Manifest string, Architecture: aws.String("x86_64"), Description: aws.String(imageName), EnaSupport: aws.Bool(publishOptions.EnaSupport), - Name: aws.String(strings.Replace(amiName, ":", ".", -1)), + Name: aws.String(amiNameReplacer.Replace(amiName)), RootDeviceName: aws.String(rootDevName), SriovNetSupport: aws.String("simple"), VirtualizationType: aws.String("hvm"),