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_scale_set azurerm_windows_virtual_machine_scale_set - rename gallery_applications #19014

Merged
merged 1 commit into from
Oct 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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),
),
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
122 changes: 121 additions & 1 deletion internal/services/compute/virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,71 @@ 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": {
Type: pluginsdk.TypeString,
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
Expand All @@ -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": {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Loading