Skip to content

Add support for enabling nested virtualization for the ebs builder - #679

Merged
hariom-hashicorp merged 3 commits into
hashicorp:mainfrom
wagnerm:wagnerm/ebs-builder-nested-virt
Aug 25, 2026
Merged

Add support for enabling nested virtualization for the ebs builder#679
hariom-hashicorp merged 3 commits into
hashicorp:mainfrom
wagnerm:wagnerm/ebs-builder-nested-virt

Conversation

@wagnerm

@wagnerm wagnerm commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description

This enables the ebs builder to launch an instances with NestedVirtualization enabled.

This updates the aws-sdk v2 code paths, and updates the ec2 sdk dependency to v1.307.0 which includes the new NestedVirtualization field. The NestedVirtualization was originally added in v1.288.0, but the most recent version seems best if we have to upgrade anyways. I'm happy to split this into another PR if you'd like, or downgrade to v1.288.0.

There appear to be legacy v1 SDK code paths in builder/common/ that use the deprecated v1 SDK, which does not support the NestedVirtualization field. So these will raise an error when that option is used instead. I don't totally understand why this code paths still exist using the v1 SDK, but let me know if something needs to be changed.

Resolved Issues

Closes #655

Rollback Plan

If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

No

This enable the ebs builder to launch an instances with
NestedVirtualization enabled.

This updates the aws-sdk v2 code paths, and updates the ec2 sdk dependency to
v1.307.0 which includes the new NestedVirtualization field. The
NestedVirtualization was originally added in v1.288.0, but the most
recent version seems best.

There appear to be legacy v1 SDK code paths in builder/common/ that use
the deprecated v1 SDK, which does not support the NestedVirtualization field.
So these will raise an error when that option is used instead.
@wagnerm
wagnerm requested a review from a team as a code owner June 11, 2026 15:48
@rtco

rtco commented Jun 30, 2026

Copy link
Copy Markdown

+1, we need this!

@santhonisz

Copy link
Copy Markdown

+1

@VladRassokhin

Copy link
Copy Markdown

+1, we've to use our own fork with a similar commit until this one is merged.

@hariom-hashicorp

Copy link
Copy Markdown
Contributor

Hi @wagnerm! I tested it successfully on C7i and on C8i instances.

One suggestion: Consider adding config-time validation (similar to EnableNitroEnclave in common/run_config.go) so users get immediate feedback during packer validate instead of waiting for AWS runtime errors.

Note: I also reviewed the AWS documentation referenced in the current comments and found that nested virtualization is supported on both 7th and 8th generation Intel instance families. Based on that, the validation below covers the supported families from the documentation, including C7i, M7i, R7i, I7i, C8i, M8i, R8i, and X8i.

Suggested validation code for common/run_config.go Prepare() and for legacy builder in builder/common/run_config.go :

if c.EnableNestedVirtualization {
    if !c.SupportsNestedVirtualization() {
        errs = append(errs, fmt.Errorf(
            "Error: Nested virtualization requires 7th or 8th generation Intel instance types (C7i, M7i, R7i, I7i, C8i, M8i, R8i, X8i families), got: %s. "+
            "See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/amazon-ec2-nested-virtualization.html",
            c.InstanceType))
    }
}
func (c *RunConfig) SupportsNestedVirtualization() bool {
    instanceType := strings.ToLower(c.InstanceType)
    parts := strings.Split(instanceType, ".")
    if len(parts) < 2 {
        return false
    }
    
    family := parts[0]
    supportedPrefixes := []string{"c7i", "m7i", "r7i", "i7i", "c8i", "m8i", "r8i", "x8i"} 
    for _, prefix := range supportedPrefixes {
        if strings.HasPrefix(family, prefix) {
            return true
        }
    }
    return false
}

…ed virtualization

According to the documents they support 16 instance families.
@wagnerm

wagnerm commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@hariom-hashicorp thank you for the suggestion. I took your suggestion and modified it a little bit because the prefix matching would have allowed instance types, such as c7id, but those instance types are not supported according to the documents. So I went with an exact list of supported instances families.

@hariom-hashicorp

Copy link
Copy Markdown
Contributor

The CI check is failing because the generated documentation needs to be updated. Can you run make generate locally and commit the changes? This will update the auto-generated docs for the new enable_nested_virtualization field.

The following files need to be committed after running make generate:

  • .web-docs/components/builder/*/README.md
  • docs-partials/*/RunConfig-not-required.mdx

@hariom-hashicorp hariom-hashicorp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hariom-hashicorp
hariom-hashicorp merged commit da1fbd7 into hashicorp:main Aug 25, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting CPU options for nested virtualization

5 participants