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

azurerm_linux_virtual_machine azurerm_windows_virtual_machine - support for gallery_applications #18406

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions internal/services/compute/linux_virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource {
ValidateFunc: azValidate.ISO8601DurationBetween("PT15M", "PT2H"),
},

"gallery_applications": VirtualMachineGalleryApplicationsSchema(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be

Suggested change
"gallery_applications": VirtualMachineGalleryApplicationsSchema(),
"gallery_application": VirtualMachineGalleryApplicationsSchema(),


"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

"license_type": {
Expand Down Expand Up @@ -444,6 +446,9 @@ func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface
Identity: identity,
Plan: plan,
VirtualMachineProperties: &compute.VirtualMachineProperties{
ApplicationProfile: &compute.ApplicationProfile{
GalleryApplications: expandVirtualMachineGalleryApplications(d.Get("gallery_applications").([]interface{})),
},
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(size),
},
Expand Down Expand Up @@ -723,6 +728,10 @@ func resourceLinuxVirtualMachineRead(d *pluginsdk.ResourceData, meta interface{}
}
d.Set("capacity_reservation_group_id", capacityReservationGroupId)

if props.ApplicationProfile != nil && props.ApplicationProfile.GalleryApplications != nil {
d.Set("gallery_applications", flattenVirtualMachineGalleryApplications(props.ApplicationProfile.GalleryApplications))
}

licenseType := ""
if props.LicenseType != nil {
licenseType = *props.LicenseType
Expand Down Expand Up @@ -1039,6 +1048,13 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface
update.ExtensionsTimeBudget = utils.String(d.Get("extensions_time_budget").(string))
}

if d.HasChange("gallery_applications") {
shouldUpdate = true
update.ApplicationProfile = &compute.ApplicationProfile{
GalleryApplications: expandVirtualMachineGalleryApplications(d.Get("gallery_applications").([]interface{})),
}
}

if d.HasChange("max_bid_price") {
shouldUpdate = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,44 @@ func TestAccLinuxVirtualMachine_otherCustomData(t *testing.T) {
})
}

func TestAccLinuxVirtualMachine_otherGalleryApplications(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.otherGalleryApplications(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("gallery_applications.0.order").HasValue("0"),
),
},
data.ImportStep(),
{
Config: r.otherGalleryApplicationsUpdated(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.otherGalleryApplicationsRemoved(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.otherGalleryApplications(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("gallery_applications.0.order").HasValue("0"),
),
},
data.ImportStep(),
})
}

func TestAccLinuxVirtualMachine_otherEdgeZone(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}
Expand Down Expand Up @@ -1260,6 +1298,225 @@ resource "azurerm_linux_virtual_machine" "test" {
`, r.otherBootDiagnosticsTemplate(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherGalleryApplications(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_F2"
admin_username = "adminuser"
network_interface_ids = [
azurerm_network_interface.test.id,
]

admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

gallery_applications {
package_reference_id = azurerm_gallery_application_version.test.id
}
}
`, r.otherGalleryApplicationsTemplate(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherGalleryApplicationsUpdated(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_F2"
admin_username = "adminuser"
network_interface_ids = [
azurerm_network_interface.test.id,
]

admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

gallery_applications {
package_reference_id = azurerm_gallery_application_version.test.id
order = 1
}

gallery_applications {
package_reference_id = azurerm_gallery_application_version.test2.id
order = 2
configuration_reference_blob_uri = azurerm_storage_blob.test2.id
tag = "app2"
}
}
`, r.otherGalleryApplicationsTemplate(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherGalleryApplicationsRemoved(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_F2"
admin_username = "adminuser"
network_interface_ids = [
azurerm_network_interface.test.id,
]

admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
`, r.otherGalleryApplicationsTemplate(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherGalleryApplicationsTemplate(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s

resource "azurerm_storage_account" "test" {
name = "accteststr%[2]s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_container" "test" {
name = "test"
storage_account_name = azurerm_storage_account.test.name
container_access_type = "blob"
}

resource "azurerm_storage_blob" "test" {
name = "script"
storage_account_name = azurerm_storage_account.test.name
storage_container_name = azurerm_storage_container.test.name
type = "Block"
source_content = "script"
}

resource "azurerm_storage_blob" "test2" {
name = "script2"
storage_account_name = azurerm_storage_account.test.name
storage_container_name = azurerm_storage_container.test.name
type = "Block"
source_content = "script2"
}

resource "azurerm_shared_image_gallery" "test" {
name = "acctestsig%[3]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}

resource "azurerm_gallery_application" "test" {
name = "acctest-app-%[3]d"
gallery_id = azurerm_shared_image_gallery.test.id
location = azurerm_shared_image_gallery.test.location
supported_os_type = "Linux"
}

resource "azurerm_gallery_application_version" "test" {
name = "0.0.1"
gallery_application_id = azurerm_gallery_application.test.id
location = azurerm_gallery_application.test.location

source {
media_link = azurerm_storage_blob.test.id
default_configuration_link = azurerm_storage_blob.test.id
}

manage_action {
install = "[install command]"
remove = "[remove command]"
}

target_region {
name = azurerm_gallery_application.test.location
regional_replica_count = 1
storage_account_type = "Premium_LRS"
}
}

resource "azurerm_gallery_application" "test2" {
name = "acctest-app2-%[3]d"
gallery_id = azurerm_shared_image_gallery.test.id
location = azurerm_shared_image_gallery.test.location
supported_os_type = "Linux"
}


resource "azurerm_gallery_application_version" "test2" {
name = "0.0.1"
gallery_application_id = azurerm_gallery_application.test2.id
location = azurerm_gallery_application.test2.location

source {
media_link = azurerm_storage_blob.test.id
default_configuration_link = azurerm_storage_blob.test.id
}

manage_action {
install = "[install command]"
remove = "[remove command]"
}

target_region {
name = azurerm_gallery_application.test2.location
regional_replica_count = 1
storage_account_type = "Premium_LRS"
}
}
`, r.template(data), data.RandomString, data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherUserData(data acceptance.TestData, userData string) string {
return fmt.Sprintf(`
%s
Expand Down
Loading