diff --git a/internal/services/compute/shared_image_data_source.go b/internal/services/compute/shared_image_data_source.go index 2dbf49fe8201..c211c418f291 100644 --- a/internal/services/compute/shared_image_data_source.go +++ b/internal/services/compute/shared_image_data_source.go @@ -41,6 +41,11 @@ func dataSourceSharedImage() *pluginsdk.Resource { "resource_group_name": commonschema.ResourceGroupNameForDataSource(), + "architecture": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "os_type": { Type: pluginsdk.TypeString, Computed: true, @@ -131,6 +136,7 @@ func dataSourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) erro d.Set("description", props.Description) d.Set("eula", props.Eula) d.Set("os_type", string(props.OsType)) + d.Set("architecture", string(props.Architecture)) d.Set("specialized", props.OsState == compute.OperatingSystemStateTypesSpecialized) d.Set("hyper_v_generation", string(props.HyperVGeneration)) d.Set("privacy_statement_uri", props.PrivacyStatementURI) diff --git a/internal/services/compute/shared_image_resource.go b/internal/services/compute/shared_image_resource.go index 8f2372db0361..22e56657bfbe 100644 --- a/internal/services/compute/shared_image_resource.go +++ b/internal/services/compute/shared_image_resource.go @@ -60,6 +60,17 @@ func resourceSharedImage() *pluginsdk.Resource { "resource_group_name": azure.SchemaResourceGroupName(), + "architecture": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(compute.ArchitectureTypesX64), + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(compute.ArchitectureTypesX64), + string(compute.ArchitectureTypesArm64), + }, false), + }, + "os_type": { Type: pluginsdk.TypeString, Required: true, @@ -277,6 +288,7 @@ func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{} Identifier: expandGalleryImageIdentifier(d), PrivacyStatementURI: utils.String(d.Get("privacy_statement_uri").(string)), ReleaseNoteURI: utils.String(d.Get("release_note_uri").(string)), + Architecture: compute.Architecture(d.Get("architecture").(string)), OsType: compute.OperatingSystemTypes(d.Get("os_type").(string)), HyperVGeneration: compute.HyperVGeneration(d.Get("hyper_v_generation").(string)), PurchasePlan: expandGalleryImagePurchasePlan(d.Get("purchase_plan").([]interface{})), @@ -392,6 +404,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error d.Set("min_recommended_memory_in_gb", minRecommendedMemoryInGB) d.Set("os_type", string(props.OsType)) + d.Set("architecture", string(props.Architecture)) d.Set("specialized", props.OsState == compute.OperatingSystemStateTypesSpecialized) d.Set("hyper_v_generation", string(props.HyperVGeneration)) d.Set("privacy_statement_uri", props.PrivacyStatementURI) diff --git a/internal/services/compute/shared_image_resource_test.go b/internal/services/compute/shared_image_resource_test.go index 02baa96a135f..28c4cc910c11 100644 --- a/internal/services/compute/shared_image_resource_test.go +++ b/internal/services/compute/shared_image_resource_test.go @@ -47,6 +47,22 @@ func TestAccSharedImage_basic_hyperVGeneration_V2(t *testing.T) { }) } +func TestAccSharedImage_basic_Arm(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") + r := SharedImageResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basicWithArch(data, "Arm64"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("description").HasValue(""), + check.That(data.ResourceName).Key("architecture").HasValue("Arm64"), + ), + }, + data.ImportStep(), + }) +} + func TestAccSharedImage_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") r := SharedImageResource{} @@ -343,6 +359,45 @@ resource "azurerm_shared_image" "test" { `, hyperVGen, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } +func (SharedImageResource) basicWithArch(data acceptance.TestData, arch string) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +variable "architecture" { + default = "%s" +} + +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 + architecture = var.architecture != "" ? var.architecture : null + os_type = "Linux" + hyper_v_generation = "V2" + + identifier { + publisher = "AccTesPublisher%d" + offer = "AccTesOffer%d" + sku = "AccTesSku%d" + } +} +`, arch, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + func (SharedImageResource) specialized(data acceptance.TestData, hyperVGen string) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/shared_image.html.markdown b/website/docs/r/shared_image.html.markdown index 34d9c610ee60..31d89a5affa9 100644 --- a/website/docs/r/shared_image.html.markdown +++ b/website/docs/r/shared_image.html.markdown @@ -78,6 +78,8 @@ The following arguments are supported: !> **Note:** It's recommended to Generalize images where possible - Specialized Images reuse the same UUID internally within each Virtual Machine, which can have unintended side-effects. +* `architecture` - (Optional) CPU architecture supported by an OS. Possible values are `x64` and `Arm64`. Defaults to `x64`. Changing this forces a new resource to be created. + * `hyper_v_generation` - (Optional) The generation of HyperV that the Virtual Machine used to create the Shared Image is based on. Possible values are `V1` and `V2`. Defaults to `V1`. Changing this forces a new resource to be created. * `max_recommended_vcpu_count` - (Optional) Maximum count of vCPUs recommended for the Image.