diff --git a/internal/services/compute/linux_virtual_machine_scale_set_other_resource_test.go b/internal/services/compute/linux_virtual_machine_scale_set_other_resource_test.go index ceb491e95c49..2e32683d6059 100644 --- a/internal/services/compute/linux_virtual_machine_scale_set_other_resource_test.go +++ b/internal/services/compute/linux_virtual_machine_scale_set_other_resource_test.go @@ -755,10 +755,10 @@ func TestAccLinuxVirtualMachineScaleSet_otherGalleryApplicationBasic(t *testing. data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.otherGalleryApplicationsBasic(data), + Config: r.otherGalleryApplicationBasic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("gallery_applications.0.order").HasValue("0"), + check.That(data.ResourceName).Key("gallery_application.0.order").HasValue("0"), ), }, data.ImportStep("admin_password"), @@ -771,7 +771,7 @@ func TestAccLinuxVirtualMachineScaleSet_otherGalleryApplicationComplete(t *testi data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.otherGalleryApplicationsComplete(data), + Config: r.otherGalleryApplicationComplete(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -3067,7 +3067,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { `, r.template(data), data.RandomInteger) } -func (r LinuxVirtualMachineScaleSetResource) otherGalleryApplicationsBasic(data acceptance.TestData) string { +func (r LinuxVirtualMachineScaleSetResource) otherGalleryApplicationBasic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -3105,14 +3105,14 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } - gallery_applications { - package_reference_id = azurerm_gallery_application_version.test.id + gallery_application { + version_id = azurerm_gallery_application_version.test.id } } -`, r.otherGalleryApplicationsTemplate(data), data.RandomInteger) +`, r.otherGalleryApplicationTemplate(data), data.RandomInteger) } -func (r LinuxVirtualMachineScaleSetResource) otherGalleryApplicationsComplete(data acceptance.TestData) string { +func (r LinuxVirtualMachineScaleSetResource) otherGalleryApplicationComplete(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -3150,17 +3150,17 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } - gallery_applications { - package_reference_id = azurerm_gallery_application_version.test.id - configuration_reference_blob_uri = azurerm_storage_blob.test2.id - order = 1 - tag = "app" + gallery_application { + version_id = azurerm_gallery_application_version.test.id + configuration_blob_uri = azurerm_storage_blob.test2.id + order = 1 + tag = "app" } } -`, r.otherGalleryApplicationsTemplate(data), data.RandomInteger) +`, r.otherGalleryApplicationTemplate(data), data.RandomInteger) } -func (r LinuxVirtualMachineScaleSetResource) otherGalleryApplicationsTemplate(data acceptance.TestData) string { +func (r LinuxVirtualMachineScaleSetResource) otherGalleryApplicationTemplate(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s diff --git a/internal/services/compute/linux_virtual_machine_scale_set_resource.go b/internal/services/compute/linux_virtual_machine_scale_set_resource.go index ebc82f7deb89..dc040263083c 100644 --- a/internal/services/compute/linux_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/linux_virtual_machine_scale_set_resource.go @@ -199,7 +199,15 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i }, } - if galleryApplications := expandVirtualMachineScaleSetGalleryApplications(d.Get("gallery_applications").([]interface{})); galleryApplications != nil { + if !features.FourPointOhBeta() { + if galleryApplications := expandVirtualMachineScaleSetGalleryApplications(d.Get("gallery_applications").([]interface{})); galleryApplications != nil { + virtualMachineProfile.ApplicationProfile = &compute.ApplicationProfile{ + GalleryApplications: galleryApplications, + } + } + } + + if galleryApplications := expandVirtualMachineScaleSetGalleryApplication(d.Get("gallery_application").([]interface{})); galleryApplications != nil { virtualMachineProfile.ApplicationProfile = &compute.ApplicationProfile{ GalleryApplications: galleryApplications, } @@ -912,7 +920,11 @@ func resourceLinuxVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta int d.Set("eviction_policy", string(profile.EvictionPolicy)) if profile.ApplicationProfile != nil && profile.ApplicationProfile.GalleryApplications != nil { - d.Set("gallery_applications", flattenVirtualMachineScaleSetGalleryApplications(profile.ApplicationProfile.GalleryApplications)) + d.Set("gallery_application", flattenVirtualMachineScaleSetGalleryApplication(profile.ApplicationProfile.GalleryApplications)) + + if !features.FourPointOhBeta() { + d.Set("gallery_applications", flattenVirtualMachineScaleSetGalleryApplications(profile.ApplicationProfile.GalleryApplications)) + } } // the service just return empty when this is not assigned when provisioned @@ -1260,7 +1272,7 @@ func resourceLinuxVirtualMachineScaleSetSchema() map[string]*pluginsdk.Schema { ValidateFunc: azValidate.ISO8601DurationBetween("PT15M", "PT2H"), }, - "gallery_applications": VirtualMachineScaleSetGalleryApplicationsSchema(), + "gallery_application": VirtualMachineScaleSetGalleryApplicationSchema(), "health_probe_id": { Type: pluginsdk.TypeString, @@ -1413,6 +1425,7 @@ func resourceLinuxVirtualMachineScaleSetSchema() map[string]*pluginsdk.Schema { } if !features.FourPointOhBeta() { + resourceSchema["gallery_applications"] = VirtualMachineScaleSetGalleryApplicationsSchema() resourceSchema["terminate_notification"] = VirtualMachineScaleSetTerminateNotificationSchema() resourceSchema["scale_in_policy"] = &schema.Schema{ diff --git a/internal/services/compute/virtual_machine_scale_set.go b/internal/services/compute/virtual_machine_scale_set.go index 5378e831bf43..e5fac6ed882c 100644 --- a/internal/services/compute/virtual_machine_scale_set.go +++ b/internal/services/compute/virtual_machine_scale_set.go @@ -178,11 +178,63 @@ func VirtualMachineScaleSetNetworkInterfaceSchema() *pluginsdk.Schema { } } -func VirtualMachineScaleSetGalleryApplicationsSchema() *pluginsdk.Schema { +func VirtualMachineScaleSetGalleryApplicationSchema() *pluginsdk.Schema { return &pluginsdk.Schema{ Type: pluginsdk.TypeList, Optional: true, MaxItems: 100, + Computed: !features.FourPointOhBeta(), + ConflictsWith: func() []string { + if !features.FourPointOhBeta() { + return []string{"gallery_applications"} + } + return []string{} + }(), + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "version_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.GalleryApplicationVersionID, + }, + + // Example: https://mystorageaccount.blob.core.windows.net/configurations/settings.config + "configuration_blob_uri": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.IsURLWithHTTPorHTTPS, + }, + + "order": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 0, + ForceNew: true, + ValidateFunc: validation.IntBetween(0, 2147483647), + }, + + // NOTE: Per the service team, "this is a pass through value that we just add to the model but don't depend on. It can be any string." + "tag": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + } +} + +func VirtualMachineScaleSetGalleryApplicationsSchema() *pluginsdk.Schema { + return &pluginsdk.Schema{ + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 100, + Computed: !features.FourPointOhBeta(), + ConflictsWith: []string{"gallery_application"}, + Deprecated: "`gallery_applications` has been renamed to `gallery_application` and will be deprecated in 4.0", Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "package_reference_id": { @@ -190,6 +242,7 @@ func VirtualMachineScaleSetGalleryApplicationsSchema() *pluginsdk.Schema { Required: true, ForceNew: true, ValidateFunc: validate.GalleryApplicationVersionID, + Deprecated: "`package_reference_id` has been renamed to `version_id` and will be deprecated in 4.0", }, // Example: https://mystorageaccount.blob.core.windows.net/configurations/settings.config @@ -198,6 +251,7 @@ func VirtualMachineScaleSetGalleryApplicationsSchema() *pluginsdk.Schema { Optional: true, ForceNew: true, ValidateFunc: validation.IsURLWithHTTPorHTTPS, + Deprecated: "`configuration_reference_blob_uri` has been renamed to `configuration_blob_uri` and will be deprecated in 4.0", }, "order": { @@ -220,6 +274,72 @@ func VirtualMachineScaleSetGalleryApplicationsSchema() *pluginsdk.Schema { } } +func expandVirtualMachineScaleSetGalleryApplication(input []interface{}) *[]compute.VMGalleryApplication { + if len(input) == 0 { + return nil + } + + out := make([]compute.VMGalleryApplication, 0) + + for _, v := range input { + packageReferenceId := v.(map[string]interface{})["version_id"].(string) + configurationReference := v.(map[string]interface{})["configuration_blob_uri"].(string) + order := v.(map[string]interface{})["order"].(int) + tag := v.(map[string]interface{})["tag"].(string) + + app := &compute.VMGalleryApplication{ + PackageReferenceID: utils.String(packageReferenceId), + ConfigurationReference: utils.String(configurationReference), + Order: utils.Int32(int32(order)), + Tags: utils.String(tag), + } + + out = append(out, *app) + } + + return &out +} + +func flattenVirtualMachineScaleSetGalleryApplication(input *[]compute.VMGalleryApplication) []interface{} { + if len(*input) == 0 { + return nil + } + + out := make([]interface{}, 0) + + for _, v := range *input { + var packageReferenceId, configurationReference, tag string + var order int + + if v.PackageReferenceID != nil { + packageReferenceId = *v.PackageReferenceID + } + + if v.ConfigurationReference != nil { + configurationReference = *v.ConfigurationReference + } + + if v.Order != nil { + order = int(*v.Order) + } + + if v.Tags != nil { + tag = *v.Tags + } + + app := map[string]interface{}{ + "version_id": packageReferenceId, + "configuration_blob_uri": configurationReference, + "order": order, + "tag": tag, + } + + out = append(out, app) + } + + return out +} + func expandVirtualMachineScaleSetGalleryApplications(input []interface{}) *[]compute.VMGalleryApplication { if len(input) == 0 { return nil diff --git a/internal/services/compute/windows_virtual_machine_scale_set_other_resource_test.go b/internal/services/compute/windows_virtual_machine_scale_set_other_resource_test.go index ea01af5025a6..8b56b13420ce 100644 --- a/internal/services/compute/windows_virtual_machine_scale_set_other_resource_test.go +++ b/internal/services/compute/windows_virtual_machine_scale_set_other_resource_test.go @@ -889,29 +889,29 @@ func TestAccWindowsVirtualMachineScaleSet_otherLicenseTypeUpdated(t *testing.T) }) } -func TestAccWindowsVirtualMachineScaleSet_otherGalleryApplicationsBasic(t *testing.T) { +func TestAccWindowsVirtualMachineScaleSet_otherGalleryApplicationBasic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") r := WindowsVirtualMachineScaleSetResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.otherGalleryApplicationsBasic(data), + Config: r.otherGalleryApplicationBasic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("gallery_applications.0.order").HasValue("0"), + check.That(data.ResourceName).Key("gallery_application.0.order").HasValue("0"), ), }, data.ImportStep("admin_password"), }) } -func TestAccWindowsVirtualMachineScaleSet_otherGalleryApplicationsComplete(t *testing.T) { +func TestAccWindowsVirtualMachineScaleSet_otherGalleryApplicationComplete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") r := WindowsVirtualMachineScaleSetResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.otherGalleryApplicationsComplete(data), + Config: r.otherGalleryApplicationComplete(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -3535,7 +3535,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, r.template(data), licenseType) } -func (r WindowsVirtualMachineScaleSetResource) otherGalleryApplicationsBasic(data acceptance.TestData) string { +func (r WindowsVirtualMachineScaleSetResource) otherGalleryApplicationBasic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -3571,14 +3571,14 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } - gallery_applications { - package_reference_id = azurerm_gallery_application_version.test.id + gallery_application { + version_id = azurerm_gallery_application_version.test.id } } -`, r.otherGalleryApplicationsTemplate(data)) +`, r.otherGalleryApplicationTemplate(data)) } -func (r WindowsVirtualMachineScaleSetResource) otherGalleryApplicationsComplete(data acceptance.TestData) string { +func (r WindowsVirtualMachineScaleSetResource) otherGalleryApplicationComplete(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -3614,17 +3614,17 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } - gallery_applications { - package_reference_id = azurerm_gallery_application_version.test.id - configuration_reference_blob_uri = azurerm_storage_blob.test2.id - order = 1 - tag = "app" + gallery_application { + version_id = azurerm_gallery_application_version.test.id + configuration_blob_uri = azurerm_storage_blob.test2.id + order = 1 + tag = "app" } } -`, r.otherGalleryApplicationsTemplate(data)) +`, r.otherGalleryApplicationTemplate(data)) } -func (r WindowsVirtualMachineScaleSetResource) otherGalleryApplicationsTemplate(data acceptance.TestData) string { +func (r WindowsVirtualMachineScaleSetResource) otherGalleryApplicationTemplate(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s diff --git a/internal/services/compute/windows_virtual_machine_scale_set_resource.go b/internal/services/compute/windows_virtual_machine_scale_set_resource.go index c1d7f9c39a17..37e93cc88812 100644 --- a/internal/services/compute/windows_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/windows_virtual_machine_scale_set_resource.go @@ -196,7 +196,15 @@ func resourceWindowsVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta }, } - if galleryApplications := expandVirtualMachineScaleSetGalleryApplications(d.Get("gallery_applications").([]interface{})); galleryApplications != nil { + if !features.FourPointOhBeta() { + if galleryApplications := expandVirtualMachineScaleSetGalleryApplications(d.Get("gallery_applications").([]interface{})); galleryApplications != nil { + virtualMachineProfile.ApplicationProfile = &compute.ApplicationProfile{ + GalleryApplications: galleryApplications, + } + } + } + + if galleryApplications := expandVirtualMachineScaleSetGalleryApplication(d.Get("gallery_application").([]interface{})); galleryApplications != nil { virtualMachineProfile.ApplicationProfile = &compute.ApplicationProfile{ GalleryApplications: galleryApplications, } @@ -945,7 +953,11 @@ func resourceWindowsVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta i d.Set("license_type", profile.LicenseType) if profile.ApplicationProfile != nil && profile.ApplicationProfile.GalleryApplications != nil { - d.Set("gallery_applications", flattenVirtualMachineScaleSetGalleryApplications(profile.ApplicationProfile.GalleryApplications)) + d.Set("gallery_application", flattenVirtualMachineScaleSetGalleryApplication(profile.ApplicationProfile.GalleryApplications)) + + if !features.FourPointOhBeta() { + d.Set("gallery_applications", flattenVirtualMachineScaleSetGalleryApplications(profile.ApplicationProfile.GalleryApplications)) + } } // the service just return empty when this is not assigned when provisioned @@ -1291,7 +1303,7 @@ func resourceWindowsVirtualMachineScaleSetSchema() map[string]*pluginsdk.Schema ValidateFunc: validate.ISO8601DurationBetween("PT15M", "PT2H"), }, - "gallery_applications": VirtualMachineScaleSetGalleryApplicationsSchema(), + "gallery_application": VirtualMachineScaleSetGalleryApplicationSchema(), "health_probe_id": { Type: pluginsdk.TypeString, @@ -1469,6 +1481,7 @@ func resourceWindowsVirtualMachineScaleSetSchema() map[string]*pluginsdk.Schema } if !features.FourPointOhBeta() { + resourceSchema["gallery_applications"] = VirtualMachineScaleSetGalleryApplicationsSchema() resourceSchema["terminate_notification"] = VirtualMachineScaleSetTerminateNotificationSchema() resourceSchema["scale_in_policy"] = &schema.Schema{ diff --git a/website/docs/r/linux_virtual_machine_scale_set.html.markdown b/website/docs/r/linux_virtual_machine_scale_set.html.markdown index de8b8a61b947..7714e135294f 100644 --- a/website/docs/r/linux_virtual_machine_scale_set.html.markdown +++ b/website/docs/r/linux_virtual_machine_scale_set.html.markdown @@ -168,7 +168,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "example" { -> **NOTE:** This can only be configured when `priority` is set to `Spot`. -* `gallery_applications` - (Optional) A `gallery_applications` block as defined below. +* `gallery_application` - (Optional) A `gallery_application` block as defined below. * `health_probe_id` - (Optional) The ID of a Load Balancer Probe which should be used to determine the health of an instance. This is Required and can only be specified when `upgrade_mode` is set to `Automatic` or `Rolling`. @@ -360,13 +360,11 @@ An `extension` block supports the following: --- -A `gallery_applications` block supports the following: +A `gallery_application` block supports the following: -* `package_reference_id` - (Required) Specifies the Gallery Application Version resource ID. Changing this forces a new resource to be created. +* `version_id` - (Required) Specifies the Gallery Application Version resource ID. Changing this forces a new resource to be created. --> **NOTE:** The `package_reference_id` should be in the form of `/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Compute/galleries/gallery1/applications/application1/versions/version1`. - -* `configuration_reference_blob_uri` - (Optional) Specifies the URI to an Azure Blob that will replace the default configuration for the package if provided. Changing this forces a new resource to be created. +* `configuration_blob_uri` - (Optional) Specifies the URI to an Azure Blob that will replace the default configuration for the package if provided. Changing this forces a new resource to be created. * `order` - (Optional) Specifies the order in which the packages have to be installed. Possible values are between `0` and `2,147,483,647`. Changing this forces a new resource to be created. diff --git a/website/docs/r/windows_virtual_machine_scale_set.html.markdown b/website/docs/r/windows_virtual_machine_scale_set.html.markdown index ca54b1b7fcff..10c015de2fc3 100644 --- a/website/docs/r/windows_virtual_machine_scale_set.html.markdown +++ b/website/docs/r/windows_virtual_machine_scale_set.html.markdown @@ -152,7 +152,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "example" { -> **NOTE:** This can only be configured when `priority` is set to `Spot`. -* `gallery_applications` - (Optional) A `gallery_applications` block as defined below. +* `gallery_application` - (Optional) A `gallery_application` block as defined below. * `health_probe_id` - (Optional) The ID of a Load Balancer Probe which should be used to determine the health of an instance. This is Required and can only be specified when `upgrade_mode` is set to `Automatic` or `Rolling`. @@ -348,13 +348,11 @@ An `extension` block supports the following: --- -A `gallery_applications` block supports the following: +A `gallery_application` block supports the following: -* `package_reference_id` - (Required) Specifies the Gallery Application Version resource ID. Changing this forces a new resource to be created. +* `version_id` - (Required) Specifies the Gallery Application Version resource ID. Changing this forces a new resource to be created. --> **NOTE:** The `package_reference_id` should be in the form of `/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Compute/galleries/gallery1/applications/application1/versions/version1`. - -* `configuration_reference_blob_uri` - (Optional) Specifies the URI to an Azure Blob that will replace the default configuration for the package if provided. Changing this forces a new resource to be created. +* `configuration_blob_uri` - (Optional) Specifies the URI to an Azure Blob that will replace the default configuration for the package if provided. Changing this forces a new resource to be created. * `order` - (Optional) Specifies the order in which the packages have to be installed. Possible values are between `0` and `2,147,483,647`. Changing this forces a new resource to be created.