Skip to content

Commit

Permalink
azurerm_shared_image - add Arm64 architecture.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergelogvinov committed Jul 13, 2022
1 parent 0ac7615 commit e87e73c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/services/compute/shared_image_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions internal/services/compute/shared_image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{})),
Expand Down Expand Up @@ -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)
Expand Down
55 changes: 55 additions & 0 deletions internal/services/compute/shared_image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/shared_image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e87e73c

Please sign in to comment.