Skip to content

Commit

Permalink
azurerm_gallery_application_version - Support config_file_name, `…
Browse files Browse the repository at this point in the history
…package_file_name` and `target_region.exclude_from_latest` (#23816)

* add code

* fix lint

* resolve comments 1120
  • Loading branch information
ms-zhenhua authored Nov 20, 2023
1 parent ed9565a commit 53fef37
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 4 deletions.
67 changes: 64 additions & 3 deletions internal/services/compute/gallery_application_version_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ type GalleryApplicationVersionModel struct {
Name string `tfschema:"name"`
GalleryApplicationId string `tfschema:"gallery_application_id"`
Location string `tfschema:"location"`
ConfigFile string `tfschema:"config_file"`
EnableHealthCheck bool `tfschema:"enable_health_check"`
EndOfLifeDate string `tfschema:"end_of_life_date"`
ExcludeFromLatest bool `tfschema:"exclude_from_latest"`
ManageAction []ManageAction `tfschema:"manage_action"`
PackageFile string `tfschema:"package_file"`
Source []Source `tfschema:"source"`
TargetRegion []TargetRegion `tfschema:"target_region"`
Tags map[string]string `tfschema:"tags"`
Expand All @@ -56,6 +58,7 @@ type ManageAction struct {
type TargetRegion struct {
Name string `tfschema:"name"`
RegionalReplicaCount int `tfschema:"regional_replica_count"`
ExcludeFromLatest bool `tfschema:"exclude_from_latest"`
StorageAccountType string `tfschema:"storage_account_type"`
}

Expand All @@ -77,6 +80,13 @@ func (r GalleryApplicationVersionResource) Arguments() map[string]*pluginsdk.Sch

"location": commonschema.Location(),

"config_file": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"enable_health_check": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -126,6 +136,13 @@ func (r GalleryApplicationVersionResource) Arguments() map[string]*pluginsdk.Sch
},
},

"package_file": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"source": {
Type: pluginsdk.TypeList,
Required: true,
Expand Down Expand Up @@ -164,6 +181,12 @@ func (r GalleryApplicationVersionResource) Arguments() map[string]*pluginsdk.Sch
ValidateFunc: validation.IntBetween(1, 10),
},

"exclude_from_latest": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"storage_account_type": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -236,11 +259,27 @@ func (r GalleryApplicationVersionResource) Create() sdk.ResourceFunc {
Tags: pointer.To(state.Tags),
}

if state.ConfigFile != "" {
if payload.Properties.PublishingProfile.Settings == nil {
payload.Properties.PublishingProfile.Settings = &galleryapplicationversions.UserArtifactSettings{}
}

payload.Properties.PublishingProfile.Settings.ConfigFileName = &state.ConfigFile
}

if state.EndOfLifeDate != "" {
endOfLifeDate, _ := time.Parse(time.RFC3339, state.EndOfLifeDate)
payload.Properties.PublishingProfile.SetEndOfLifeDateAsTime(endOfLifeDate)
}

if state.PackageFile != "" {
if payload.Properties.PublishingProfile.Settings == nil {
payload.Properties.PublishingProfile.Settings = &galleryapplicationversions.UserArtifactSettings{}
}

payload.Properties.PublishingProfile.Settings.PackageFileName = &state.PackageFile
}

if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}
Expand Down Expand Up @@ -301,6 +340,13 @@ func (r GalleryApplicationVersionResource) Read() sdk.ResourceFunc {
}
state.ExcludeFromLatest = excludeFromLatest

state.ConfigFile = ""
state.PackageFile = ""
if props.PublishingProfile.Settings != nil {
state.ConfigFile = pointer.From(props.PublishingProfile.Settings.ConfigFileName)
state.PackageFile = pointer.From(props.PublishingProfile.Settings.PackageFileName)
}

state.ManageAction = flattenGalleryApplicationVersionManageAction(props.PublishingProfile.ManageActions)
state.Source = flattenGalleryApplicationVersionSource(props.PublishingProfile.Source)
state.TargetRegion = flattenGalleryApplicationVersionTargetRegion(props.PublishingProfile.TargetRegions)
Expand Down Expand Up @@ -496,12 +542,19 @@ func flattenGalleryApplicationVersionSource(input galleryapplicationversions.Use
func expandGalleryApplicationVersionTargetRegion(input []TargetRegion) *[]galleryapplicationversions.TargetRegion {
results := make([]galleryapplicationversions.TargetRegion, 0)
for _, item := range input {
results = append(results, galleryapplicationversions.TargetRegion{
targetRegion := galleryapplicationversions.TargetRegion{
Name: location.Normalize(item.Name),
RegionalReplicaCount: pointer.To(int64(item.RegionalReplicaCount)),
StorageAccountType: pointer.To(galleryapplicationversions.StorageAccountType(item.StorageAccountType)),
})
}

if item.ExcludeFromLatest {
targetRegion.ExcludeFromLatest = &item.ExcludeFromLatest
}

results = append(results, targetRegion)
}

return &results
}

Expand All @@ -510,14 +563,22 @@ func flattenGalleryApplicationVersionTargetRegion(input *[]galleryapplicationver

for _, item := range *input {
obj := TargetRegion{
Name: location.Normalize(item.Name),
Name: location.Normalize(item.Name),
ExcludeFromLatest: false,
}

if item.ExcludeFromLatest != nil {
obj.ExcludeFromLatest = *item.ExcludeFromLatest
}

if item.RegionalReplicaCount != nil {
obj.RegionalReplicaCount = int(*item.RegionalReplicaCount)
}

if item.StorageAccountType != nil {
obj.StorageAccountType = string(*item.StorageAccountType)
}

results = append(results, obj)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ func TestAccGalleryApplicationVersion_update(t *testing.T) {
},
data.ImportStep(),
{
Config: r.complete(data),
Config: r.update(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand Down Expand Up @@ -379,9 +386,11 @@ resource "azurerm_gallery_application_version" "test" {
gallery_application_id = azurerm_gallery_application.test.id
location = azurerm_gallery_application.test.location
config_file = "config"
enable_health_check = true
end_of_life_date = "%s"
exclude_from_latest = true
package_file = "package"
manage_action {
install = "[install command]"
Expand All @@ -396,6 +405,7 @@ resource "azurerm_gallery_application_version" "test" {
target_region {
name = azurerm_gallery_application.test.location
exclude_from_latest = true
regional_replica_count = 1
storage_account_type = "Premium_LRS"
}
Expand All @@ -407,6 +417,41 @@ resource "azurerm_gallery_application_version" "test" {
`, template, time.Now().Add(time.Hour*10).Format(time.RFC3339))
}

func (r GalleryApplicationVersionResource) update(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_gallery_application_version" "test" {
name = "0.0.1"
gallery_application_id = azurerm_gallery_application.test.id
location = azurerm_gallery_application.test.location
enable_health_check = true
exclude_from_latest = true
manage_action {
install = "[install command]"
remove = "[remove command]"
}
source {
media_link = azurerm_storage_blob.test.id
}
target_region {
name = azurerm_gallery_application.test.location
exclude_from_latest = true
regional_replica_count = 1
}
tags = {
ENV = "Test"
}
}
`, template)
}

func (r GalleryApplicationVersionResource) enableHealthCheck(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/gallery_application_version.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ The following arguments are supported:

---

* `config_file` - (Optional) Specifies the name of the config file on the VM. Changing this forces a new resource to be created.

* `enable_health_check` - (Optional) Should the Gallery Application reports health. Defaults to `false`.

* `end_of_life_date` - (Optional) The end of life date in RFC3339 format of the Gallery Application Version.

* `exclude_from_latest` - (Optional) Should the Gallery Application Version be excluded from the `latest` filter? If set to `true` this Gallery Application Version won't be returned for the `latest` version. Defaults to `false`.

* `package_file` - (Optional) Specifies the name of the package file on the VM. Changing this forces a new resource to be created.

* `tags` - (Optional) A mapping of tags to assign to the Gallery Application Version.

---
Expand Down Expand Up @@ -126,6 +130,8 @@ A `target_region` block supports the following:

* `regional_replica_count` - (Required) The number of replicas of the Gallery Application Version to be created per region. Possible values are between `1` and `10`.

* `exclude_from_latest` - (Optional) Specifies whether this Gallery Application Version should be excluded from the `latest` filter. If set to `true`, this Gallery Application Version won't be returned for the `latest` version. Defaults to `false`.

* `storage_account_type` - (Optional) The storage account type for the Gallery Application Version. Possible values are `Standard_LRS`, `Premium_LRS` and `Standard_ZRS`. Defaults to `Standard_LRS`.

## Attributes Reference
Expand Down

0 comments on commit 53fef37

Please sign in to comment.