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 Jun 27, 2022
1 parent 3d53cda commit b2bcade
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 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
2 changes: 1 addition & 1 deletion internal/services/compute/shared_image_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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 @@ -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,
Expand Down Expand Up @@ -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{})),
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 27 additions & 6 deletions internal/services/compute/shared_image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(""),
Expand All @@ -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(""),
Expand All @@ -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(""),
Expand Down Expand Up @@ -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"
}
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
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 @@ -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.
Expand Down

0 comments on commit b2bcade

Please sign in to comment.