@@ -48,12 +48,17 @@ type Config struct {
4848 OuArns []string `mapstructure:"ami_ou_arns"`
4949 Encrypt bool `mapstructure:"ami_encrypt"`
5050 KMSKey string `mapstructure:"ami_kms_key"`
51- LicenseType string `mapstructure:"license_type"`
52- RoleName string `mapstructure:"role_name"`
53- Format string `mapstructure:"format"`
54- Architecture string `mapstructure:"architecture"`
55- BootMode string `mapstructure:"boot_mode"`
56- Platform string `mapstructure:"platform"`
51+ // Enforce version of the Instance Metadata Service on the built AMI.
52+ // Valid options are unset (legacy) and `v2.0`. See the documentation on
53+ // [IMDS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html)
54+ // for more information. Defaults to legacy.
55+ AMIIMDSSupport string `mapstructure:"imds_support" required:"false"`
56+ LicenseType string `mapstructure:"license_type"`
57+ RoleName string `mapstructure:"role_name"`
58+ Format string `mapstructure:"format"`
59+ Architecture string `mapstructure:"architecture"`
60+ BootMode string `mapstructure:"boot_mode"`
61+ Platform string `mapstructure:"platform"`
5762
5863 ctx interpolate.Context
5964}
@@ -163,6 +168,13 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
163168 errs , fmt .Errorf ("invalid boot mode '%s' for 'arm64' architecture" , p .config .BootMode ))
164169 }
165170
171+ if p .config .AMIIMDSSupport != "" && p .config .AMIIMDSSupport != ec2 .ImdsSupportValuesV20 {
172+ errs = packersdk .MultiErrorAppend (errs ,
173+ fmt .Errorf (`The only valid imds_support values are %q or the empty string` ,
174+ ec2 .ImdsSupportValuesV20 ),
175+ )
176+ }
177+
166178 // Anything which flagged return back up the stack
167179 if len (errs .Errors ) > 0 {
168180 return errs
@@ -511,6 +523,13 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa
511523 }
512524 }
513525
526+ if p .config .AMIIMDSSupport != "" {
527+ options ["ami imds support" ] = & ec2.ModifyImageAttributeInput {
528+ ImdsSupport : & ec2.AttributeValue {Value : & p .config .AMIIMDSSupport },
529+ }
530+
531+ }
532+
514533 if len (options ) > 0 {
515534 for name , input := range options {
516535 ui .Message (fmt .Sprintf ("Modifying: %s" , name ))
0 commit comments