diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 0da4a612..498cd49f 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -87,6 +87,8 @@ type Config struct { // } // ``` DiskEncryptionKey *CustomerEncryptionKey `mapstructure:"disk_encryption_key" required:"false"` + // Create a instance with enabling nested virtualization. + EnableNestedVirtualization bool `mapstructure:"enable_nested_virtualization" required:"false"` // Create a Shielded VM image with Secure Boot enabled. It helps ensure that // the system only runs authentic software by verifying the digital signature // of all boot components, and halting the boot process if signature verification diff --git a/builder/googlecompute/config.hcl2spec.go b/builder/googlecompute/config.hcl2spec.go index b8997274..9b3c6bf6 100644 --- a/builder/googlecompute/config.hcl2spec.go +++ b/builder/googlecompute/config.hcl2spec.go @@ -79,6 +79,7 @@ type FlatConfig struct { DiskSizeGb *int64 `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"` DiskType *string `mapstructure:"disk_type" required:"false" cty:"disk_type" hcl:"disk_type"` DiskEncryptionKey *FlatCustomerEncryptionKey `mapstructure:"disk_encryption_key" required:"false" cty:"disk_encryption_key" hcl:"disk_encryption_key"` + EnableNestedVirtualization *bool `mapstructure:"enable_nested_virtualization" required:"false" cty:"enable_nested_virtualization" hcl:"enable_nested_virtualization"` EnableSecureBoot *bool `mapstructure:"enable_secure_boot" required:"false" cty:"enable_secure_boot" hcl:"enable_secure_boot"` EnableVtpm *bool `mapstructure:"enable_vtpm" required:"false" cty:"enable_vtpm" hcl:"enable_vtpm"` EnableIntegrityMonitoring *bool `mapstructure:"enable_integrity_monitoring" required:"false" cty:"enable_integrity_monitoring" hcl:"enable_integrity_monitoring"` @@ -208,6 +209,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, "disk_type": &hcldec.AttrSpec{Name: "disk_type", Type: cty.String, Required: false}, "disk_encryption_key": &hcldec.BlockSpec{TypeName: "disk_encryption_key", Nested: hcldec.ObjectSpec((*FlatCustomerEncryptionKey)(nil).HCL2Spec())}, + "enable_nested_virtualization": &hcldec.AttrSpec{Name: "enable_nested_virtualization", Type: cty.Bool, Required: false}, "enable_secure_boot": &hcldec.AttrSpec{Name: "enable_secure_boot", Type: cty.Bool, Required: false}, "enable_vtpm": &hcldec.AttrSpec{Name: "enable_vtpm", Type: cty.Bool, Required: false}, "enable_integrity_monitoring": &hcldec.AttrSpec{Name: "enable_integrity_monitoring", Type: cty.Bool, Required: false}, diff --git a/builder/googlecompute/driver.go b/builder/googlecompute/driver.go index ad126805..55362f21 100644 --- a/builder/googlecompute/driver.go +++ b/builder/googlecompute/driver.go @@ -84,6 +84,7 @@ type InstanceConfig struct { DiskSizeGb int64 DiskType string DiskEncryptionKey *CustomerEncryptionKey + EnableNestedVirtualization bool EnableSecureBoot bool EnableVtpm bool EnableIntegrityMonitoring bool diff --git a/builder/googlecompute/driver_gce.go b/builder/googlecompute/driver_gce.go index 098d9be3..f57aa1f2 100644 --- a/builder/googlecompute/driver_gce.go +++ b/builder/googlecompute/driver_gce.go @@ -499,6 +499,9 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) { // Create the instance information instance := compute.Instance{ + AdvancedMachineFeatures: &compute.AdvancedMachineFeatures{ + EnableNestedVirtualization: c.EnableNestedVirtualization, + }, Description: c.Description, Disks: []*compute.AttachedDisk{ { diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index d90af930..da1a099b 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -182,6 +182,7 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) DiskSizeGb: c.DiskSizeGb, DiskType: c.DiskType, DiskEncryptionKey: c.DiskEncryptionKey, + EnableNestedVirtualization: c.EnableNestedVirtualization, EnableSecureBoot: c.EnableSecureBoot, EnableVtpm: c.EnableVtpm, EnableIntegrityMonitoring: c.EnableIntegrityMonitoring, diff --git a/docs-partials/builder/googlecompute/Config-not-required.mdx b/docs-partials/builder/googlecompute/Config-not-required.mdx index e7a5c13c..c95a7d08 100644 --- a/docs-partials/builder/googlecompute/Config-not-required.mdx +++ b/docs-partials/builder/googlecompute/Config-not-required.mdx @@ -55,6 +55,8 @@ } ``` +- `enable_nested_virtualization` (bool) - Create a instance with enabling nested virtualization. + - `enable_secure_boot` (bool) - Create a Shielded VM image with Secure Boot enabled. It helps ensure that the system only runs authentic software by verifying the digital signature of all boot components, and halting the boot process if signature verification