It's not possible to share encrypted AMI's

This commit is contained in:
Rickard von Essen 2016-12-04 15:14:53 +01:00
parent 8b13b75097
commit d7a7d8c852
No known key found for this signature in database
GPG Key ID: E0C0327388876CBA
3 changed files with 7 additions and 6 deletions

View File

@ -58,8 +58,8 @@ func (c *AMIConfig) Prepare(ctx *interpolate.Context) []error {
c.AMIRegions = regions
}
if len(c.AMIUsers) > 0 && len(c.AMIKmsKeyId) == 0 && c.AMIEncryptBootVolume {
errs = append(errs, fmt.Errorf("Cannot share AMI with encrypted boot volume unless kms_key_id is provided"))
if len(c.AMIUsers) > 0 && c.AMIEncryptBootVolume {
errs = append(errs, fmt.Errorf("Cannot share AMI with encrypted boot volume"))
}
if len(errs) > 0 {

View File

@ -66,11 +66,11 @@ func TestAMIConfigPrepare_Share_EncryptedBoot(t *testing.T) {
c.AMIKmsKeyId = ""
if err := c.Prepare(nil); err == nil {
t.Fatal("shouldn't be able to share ami with encrypted boot volume unless kms_key_id is provided")
t.Fatal("shouldn't be able to share ami with encrypted boot volume")
}
c.AMIKmsKeyId = "89c3fb9a-de87-4f2a-aedc-fddc5138193c"
if err := c.Prepare(nil); err != nil {
t.Fatal("should be able to share ami with encrypted boot volume if kms_key_id is provided")
if err := c.Prepare(nil); err == nil {
t.Fatal("shouldn't be able to share ami with encrypted boot volume")
}
}

View File

@ -2,6 +2,7 @@ package ebs
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
@ -23,7 +24,7 @@ func (s *stepCreateEncryptedAMICopy) Run(state multistep.StateBag) multistep.Ste
// Encrypt boot not set, so skip step
if !config.AMIConfig.AMIEncryptBootVolume {
if kmsKeyId != "" {
ui.Say(fmt.Sprintf("Ignoring KMS Key ID: %s, encrypted=false", kmsKeyId))
log.Printf(fmt.Sprintf("Ignoring KMS Key ID: %s, encrypted=false", kmsKeyId))
}
return multistep.ActionContinue
}