From 8d132e3b185218c10fd5e0a82040dec34e3d862d Mon Sep 17 00:00:00 2001 From: Serge Logvinov Date: Mon, 27 Jun 2022 20:14:18 +0300 Subject: [PATCH] `azurerm_shared_image` - add Arm64 architecture. --- .../compute/shared_image_data_source.go | 6 ++++ .../compute/shared_image_data_source_test.go | 2 +- .../services/compute/shared_image_resource.go | 13 ++++++++ .../compute/shared_image_resource_test.go | 33 +++++++++++++++---- website/docs/r/shared_image.html.markdown | 2 ++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/internal/services/compute/shared_image_data_source.go b/internal/services/compute/shared_image_data_source.go index 2dbf49fe82010..c211c418f2910 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_data_source_test.go b/internal/services/compute/shared_image_data_source_test.go index 22c40d86f130c..2a66b584b84c0 100644 --- a/internal/services/compute/shared_image_data_source_test.go +++ b/internal/services/compute/shared_image_data_source_test.go @@ -60,7 +60,7 @@ data "azurerm_shared_image" "test" { gallery_name = azurerm_shared_image.test.gallery_name resource_group_name = azurerm_shared_image.test.resource_group_name } -`, SharedImageResource{}.basic(data, hyperVGen)) +`, SharedImageResource{}.basic(data, "", hyperVGen)) } func (SharedImageDataSource) complete(data acceptance.TestData, hyperVGen string) string { diff --git a/internal/services/compute/shared_image_resource.go b/internal/services/compute/shared_image_resource.go index 208012aa8519a..255acbbbe1e53 100644 --- a/internal/services/compute/shared_image_resource.go +++ b/internal/services/compute/shared_image_resource.go @@ -58,6 +58,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, @@ -220,6 +231,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{})), @@ -284,6 +296,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error 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_test.go b/internal/services/compute/shared_image_resource_test.go index 472d67828dceb..50f01b88dd33e 100644 --- a/internal/services/compute/shared_image_resource_test.go +++ b/internal/services/compute/shared_image_resource_test.go @@ -20,7 +20,7 @@ func TestAccSharedImage_basic(t *testing.T) { r := SharedImageResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, ""), + Config: r.basic(data, "", ""), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("description").HasValue(""), @@ -35,7 +35,7 @@ func TestAccSharedImage_basic_hyperVGeneration_V2(t *testing.T) { r := SharedImageResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, "V2"), + Config: r.basic(data, "", "V2"), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("description").HasValue(""), @@ -46,13 +46,29 @@ 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.basic(data, "Arm64", "V2"), + 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{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, ""), + Config: r.basic(data, "", ""), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("description").HasValue(""), @@ -180,12 +196,16 @@ func (t SharedImageResource) Exists(ctx context.Context, clients *clients.Client return utils.Bool(resp.ID != nil), nil } -func (SharedImageResource) basic(data acceptance.TestData, hyperVGen string) string { +func (SharedImageResource) basic(data acceptance.TestData, arch, hyperVGen string) string { return fmt.Sprintf(` provider "azurerm" { features {} } +variable "architecture" { + default = "%s" +} + variable "hyper_v_generation" { default = "%s" } @@ -206,6 +226,7 @@ resource "azurerm_shared_image" "test" { 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 = var.hyper_v_generation != "" ? var.hyper_v_generation : null @@ -215,7 +236,7 @@ resource "azurerm_shared_image" "test" { sku = "AccTesSku%d" } } -`, hyperVGen, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, arch, hyperVGen, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func (SharedImageResource) specialized(data acceptance.TestData, hyperVGen string) string { @@ -274,7 +295,7 @@ resource "azurerm_shared_image" "import" { sku = "AccTesSku%d" } } -`, r.basic(data, ""), data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, r.basic(data, "", ""), data.RandomInteger, data.RandomInteger, data.RandomInteger) } func (SharedImageResource) complete(data acceptance.TestData, hyperVGen string) string { diff --git a/website/docs/r/shared_image.html.markdown b/website/docs/r/shared_image.html.markdown index 4cdd180593f92..5a1ca4b0ba638 100644 --- a/website/docs/r/shared_image.html.markdown +++ b/website/docs/r/shared_image.html.markdown @@ -74,6 +74,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. * `privacy_statement_uri` - (Optional) The URI containing the Privacy Statement associated with this Shared Image. Changing this forces a new resource to be created.