Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added trusted_launch_supported feature to azurerm_shared_image resource #23781

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions internal/services/compute/shared_image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,32 @@ func resourceSharedImage() *pluginsdk.Resource {
ForceNew: true,
},

"trusted_launch_supported": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"trusted_launch_enabled", "confidential_vm_supported", "confidential_vm_enabled"},
},

"trusted_launch_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"confidential_vm_supported", "confidential_vm_enabled"},
ConflictsWith: []string{"trusted_launch_supported", "confidential_vm_supported", "confidential_vm_enabled"},
},

"confidential_vm_supported": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"trusted_launch_enabled", "confidential_vm_enabled"},
ConflictsWith: []string{"trusted_launch_supported", "trusted_launch_enabled", "confidential_vm_enabled"},
},

"confidential_vm_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"trusted_launch_enabled", "confidential_vm_supported"},
ConflictsWith: []string{"trusted_launch_supported", "trusted_launch_enabled", "confidential_vm_supported"},
},

"accelerated_network_support_enabled": {
Expand Down Expand Up @@ -430,6 +437,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error
return fmt.Errorf("setting `purchase_plan`: %+v", err)
}

trustedLaunchSupported := false
trustedLaunchEnabled := false
cvmEnabled := false
cvmSupported := false
Expand All @@ -441,6 +449,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error
}

if strings.EqualFold(*feature.Name, "SecurityType") {
trustedLaunchSupported = strings.EqualFold(*feature.Value, "TrustedLaunchSupported")
trustedLaunchEnabled = strings.EqualFold(*feature.Value, "TrustedLaunch")
cvmSupported = strings.EqualFold(*feature.Value, "ConfidentialVmSupported")
cvmEnabled = strings.EqualFold(*feature.Value, "ConfidentialVm")
Expand All @@ -453,6 +462,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error
}
d.Set("confidential_vm_supported", cvmSupported)
d.Set("confidential_vm_enabled", cvmEnabled)
d.Set("trusted_launch_supported", trustedLaunchSupported)
d.Set("trusted_launch_enabled", trustedLaunchEnabled)
d.Set("accelerated_network_support_enabled", acceleratedNetworkSupportEnabled)
}
Expand Down Expand Up @@ -664,6 +674,13 @@ func expandSharedImageFeatures(d *pluginsdk.ResourceData) *[]compute.GalleryImag
})
}

if tvmSupported := d.Get("trusted_launch_supported").(bool); tvmSupported {
features = append(features, compute.GalleryImageFeature{
Name: utils.String("SecurityType"),
Value: utils.String("TrustedLaunchSupported"),
})
}

if tvmEnabled := d.Get("trusted_launch_enabled").(bool); tvmEnabled {
features = append(features, compute.GalleryImageFeature{
Name: utils.String("SecurityType"),
Expand Down
49 changes: 49 additions & 0 deletions internal/services/compute/shared_image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ func TestAccSharedImage_withTrustedLaunchEnabled(t *testing.T) {
})
}

func TestAccSharedImage_withTrustedLaunchSupported(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_shared_image", "test")
r := SharedImageResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withTrustedLaunchSupported(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccSharedImage_withConfidentialVM(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_shared_image", "test")
r := SharedImageResource{}
Expand Down Expand Up @@ -602,6 +616,41 @@ resource "azurerm_shared_image" "test" {
`, data.RandomInteger, data.Locations.Primary)
}

func (SharedImageResource) withTrustedLaunchSupported(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_shared_image_gallery" "test" {
name = "acctestsig%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}

resource "azurerm_shared_image" "test" {
name = "acctestimg%d"
gallery_name = azurerm_shared_image_gallery.test.name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
os_type = "Linux"
hyper_v_generation = "V2"
trusted_launch_supported = true

identifier {
publisher = "AccTesPublisher%d"
offer = "AccTesOffer%d"
sku = "AccTesSku%d"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (SharedImageResource) withTrustedLaunchEnabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/shared_image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ The following arguments are supported:

* `release_note_uri` - (Optional) The URI containing the Release Notes associated with this Shared Image.

* `trusted_launch_supported` - (Optional) Specifies if supports creation of both Trusted Launch virtual machines and Gen2 virtual machines with standard security created from the Shared Image. Changing this forces a new resource to be created.

* `trusted_launch_enabled` - (Optional) Specifies if Trusted Launch has to be enabled for the Virtual Machine created from the Shared Image. Changing this forces a new resource to be created.

* `confidential_vm_supported` - (Optional) Specifies if supports creation of both Confidential virtual machines and Gen2 virtual machines with standard security from a compatible Gen2 OS disk VHD or Gen2 Managed image. Changing this forces a new resource to be created.

* `confidential_vm_enabled` - (Optional) Specifies if Confidential Virtual Machines enabled. It will enable all the features of trusted, with higher confidentiality features for isolate machines or encrypted data. Available for Gen2 machines. Changing this forces a new resource to be created.

-> **Note:**: Only one of `trusted_launch_enabled`, `confidential_vm_supported` and `confidential_vm_enabled` could only be specified.
-> **Note:**: Only one of `trusted_launch_supported`, `trusted_launch_enabled`, `confidential_vm_supported` and `confidential_vm_enabled` can be specified.

* `accelerated_network_support_enabled` - (Optional) Specifies if the Shared Image supports Accelerated Network. Changing this forces a new resource to be created.

Expand Down
Loading