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

resource azurerm_shared_image - add architecture option. #17250

Merged
merged 1 commit into from
Aug 16, 2022
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
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