From 5cde4ddcc6283c561cd2df283b1d76f76ef1e074 Mon Sep 17 00:00:00 2001 From: Eike Waldt Date: Mon, 20 Jan 2025 09:25:15 +0100 Subject: [PATCH] shared_image_version_resource - gofmt --- internal/services/compute/client/client.go | 2 +- .../compute/shared_image_version_resource.go | 404 +++++++++--------- .../shared_image_version_resource_test.go | 2 +- 3 files changed, 203 insertions(+), 205 deletions(-) diff --git a/internal/services/compute/client/client.go b/internal/services/compute/client/client.go index 925e1988fcd4..6a574a5c2022 100644 --- a/internal/services/compute/client/client.go +++ b/internal/services/compute/client/client.go @@ -22,10 +22,10 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages" - "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/gallerysharingupdate" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/virtualmachineruncommands" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-04-02/disks" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/availabilitysets" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/dedicatedhostgroups" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/dedicatedhosts" diff --git a/internal/services/compute/shared_image_version_resource.go b/internal/services/compute/shared_image_version_resource.go index caaf252efdde..e9520a56ca5d 100644 --- a/internal/services/compute/shared_image_version_resource.go +++ b/internal/services/compute/shared_image_version_resource.go @@ -190,62 +190,62 @@ func resourceSharedImageVersion() *pluginsdk.Resource { Default: false, }, - "uefi_settings": { - Type: pluginsdk.TypeList, - Optional: true, + "uefi_settings": { + Type: pluginsdk.TypeList, + Optional: true, ForceNew: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "signature_template_names": { - Type: pluginsdk.TypeList, - Required: true, - Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString}, - // not supported yet - // ValidateFunc: validation.StringInSlice(galleryimageversions.PossibleValuesForUefiSignatureTemplateName(), false), - }, - "additional_signatures": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "db": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: uefiKeySchema(), - }, - "dbx": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: uefiKeySchema(), - }, - "kek": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: uefiKeySchema(), - }, - "pk": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: uefiKeySchema(), - }, - }, - }, - }, - }, - }, - }, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "signature_template_names": { + Type: pluginsdk.TypeList, + Required: true, + Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString}, + // not supported yet + // ValidateFunc: validation.StringInSlice(galleryimageversions.PossibleValuesForUefiSignatureTemplateName(), false), + }, + "additional_signatures": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "db": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: uefiKeySchema(), + }, + "dbx": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: uefiKeySchema(), + }, + "kek": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: uefiKeySchema(), + }, + "pk": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: uefiKeySchema(), + }, + }, + }, + }, + }, + }, + }, "tags": commonschema.Tags(), }, - CustomizeDiff: pluginsdk.CustomDiffWithAll( - pluginsdk.ForceNewIfChange("end_of_life_date", func(ctx context.Context, old, new, meta interface{}) bool { - return old.(string) != "" && new.(string) == "" - }), - ), + CustomizeDiff: pluginsdk.CustomDiffWithAll( + pluginsdk.ForceNewIfChange("end_of_life_date", func(ctx context.Context, old, new, meta interface{}) bool { + return old.(string) != "" && new.(string) == "" + }), + ), } } @@ -285,9 +285,9 @@ func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{ AllowDeletionOfReplicatedLocations: utils.Bool(d.Get("deletion_of_replicated_locations_enabled").(bool)), }, StorageProfile: galleryimageversions.GalleryImageVersionStorageProfile{}, - SecurityProfile: &galleryimageversions.ImageVersionSecurityProfile{ - UefiSettings: expandUefiSettings(d), - }, + SecurityProfile: &galleryimageversions.ImageVersionSecurityProfile{ + UefiSettings: expandUefiSettings(d), + }, }, Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } @@ -381,11 +381,11 @@ func resourceSharedImageVersionUpdate(d *pluginsdk.ResourceData, meta interface{ payload.Properties.PublishingProfile.ExcludeFromLatest = pointer.To(d.Get("exclude_from_latest").(bool)) } - if d.HasChange("uefi_settings") { - payload.Properties.SecurityProfile = &galleryimageversions.ImageVersionSecurityProfile{ - UefiSettings: expandUefiSettings(d), - } - } + if d.HasChange("uefi_settings") { + payload.Properties.SecurityProfile = &galleryimageversions.ImageVersionSecurityProfile{ + UefiSettings: expandUefiSettings(d), + } + } if d.HasChange("tags") { payload.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) @@ -474,16 +474,16 @@ func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{}) d.Set("deletion_of_replicated_locations_enabled", pointer.From(safetyProfile.AllowDeletionOfReplicatedLocations)) } - if securityProfile := props.SecurityProfile; securityProfile != nil { - if uefiSettings := securityProfile.UefiSettings; uefiSettings != nil { - d.Set("uefi_settings", []interface{}{ - map[string]interface{}{ - "signature_template_names": uefiSettings.SignatureTemplateNames, - "additional_signatures": flattenAdditionalSignatures(uefiSettings.AdditionalSignatures), - }, - }) - } - } + if securityProfile := props.SecurityProfile; securityProfile != nil { + if uefiSettings := securityProfile.UefiSettings; uefiSettings != nil { + d.Set("uefi_settings", []interface{}{ + map[string]interface{}{ + "signature_template_names": uefiSettings.SignatureTemplateNames, + "additional_signatures": flattenAdditionalSignatures(uefiSettings.AdditionalSignatures), + }, + }) + } + } } return tags.FlattenAndSet(d, model.Tags) } @@ -580,176 +580,174 @@ func expandSharedImageVersionTargetRegions(d *pluginsdk.ResourceData) (*[]galler } func uefiKeySchema() *pluginsdk.Resource { - possibleKeyTypes := galleryimageversions.PossibleValuesForUefiKeyType() - - validKeyTypes := make([]string, len(possibleKeyTypes)) - for i, keyType := range possibleKeyTypes { - validKeyTypes[i] = string(keyType) - } - - return &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "certificate_data": { - Type: pluginsdk.TypeString, - Required: true, - }, - "key_type": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(galleryimageversions.PossibleValuesForUefiKeyType(), false), - }, - }, - } + possibleKeyTypes := galleryimageversions.PossibleValuesForUefiKeyType() + + validKeyTypes := make([]string, len(possibleKeyTypes)) + for i, keyType := range possibleKeyTypes { + validKeyTypes[i] = string(keyType) + } + + return &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "certificate_data": { + Type: pluginsdk.TypeString, + Required: true, + }, + "key_type": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(galleryimageversions.PossibleValuesForUefiKeyType(), false), + }, + }, + } } func expandUefiSettings(d *pluginsdk.ResourceData) *galleryimageversions.GalleryImageVersionUefiSettings { - if uefiSettings, ok := d.GetOk("uefi_settings"); ok { - settings := uefiSettings.([]interface{}) - if len(settings) == 0 { - return nil - } - - us := settings[0].(map[string]interface{}) - return &galleryimageversions.GalleryImageVersionUefiSettings{ - SignatureTemplateNames: expandStringList(us["signature_template_names"].([]interface{})), - AdditionalSignatures: expandAdditionalSignatures(us["additional_signatures"]), - } - } - return nil + if uefiSettings, ok := d.GetOk("uefi_settings"); ok { + settings := uefiSettings.([]interface{}) + if len(settings) == 0 { + return nil + } + + us := settings[0].(map[string]interface{}) + return &galleryimageversions.GalleryImageVersionUefiSettings{ + SignatureTemplateNames: expandStringList(us["signature_template_names"].([]interface{})), + AdditionalSignatures: expandAdditionalSignatures(us["additional_signatures"]), + } + } + return nil } func expandAdditionalSignatures(input interface{}) *galleryimageversions.UefiKeySignatures { - if input == nil { - return nil - } - - data := input.([]interface{})[0].(map[string]interface{}) - return &galleryimageversions.UefiKeySignatures{ - Db: expandUefiKeyList(data["db"]), - Dbx: expandUefiKeyList(data["dbx"]), - Kek: expandUefiKeyList(data["kek"]), - Pk: expandSingleUefiKey(data["pk"]), - } + if input == nil { + return nil + } + + data := input.([]interface{})[0].(map[string]interface{}) + return &galleryimageversions.UefiKeySignatures{ + Db: expandUefiKeyList(data["db"]), + Dbx: expandUefiKeyList(data["dbx"]), + Kek: expandUefiKeyList(data["kek"]), + Pk: expandSingleUefiKey(data["pk"]), + } } func expandUefiKeyList(input interface{}) *[]galleryimageversions.UefiKey { - if input == nil { - return nil - } - - keys := input.([]interface{}) - result := make([]galleryimageversions.UefiKey, len(keys)) - for i, v := range keys { - result[i] = expandUefiKey(v.(map[string]interface{})) // Correctly returns a value, not a pointer - } - return &result + if input == nil { + return nil + } + + keys := input.([]interface{}) + result := make([]galleryimageversions.UefiKey, len(keys)) + for i, v := range keys { + result[i] = expandUefiKey(v.(map[string]interface{})) // Correctly returns a value, not a pointer + } + return &result } func expandSingleUefiKey(input interface{}) *galleryimageversions.UefiKey { - if input == nil { - return nil - } - - keys := input.([]interface{}) - if len(keys) == 0 { - return nil - } - - data := keys[0].(map[string]interface{}) - return &galleryimageversions.UefiKey{ - Type: pointer.To(galleryimageversions.UefiKeyType(data["key_type"].(string))), - Value: &[]string{data["certificate_data"].(string)}, - } + if input == nil { + return nil + } + + keys := input.([]interface{}) + if len(keys) == 0 { + return nil + } + + data := keys[0].(map[string]interface{}) + return &galleryimageversions.UefiKey{ + Type: pointer.To(galleryimageversions.UefiKeyType(data["key_type"].(string))), + Value: &[]string{data["certificate_data"].(string)}, + } } func expandUefiKey(data map[string]interface{}) galleryimageversions.UefiKey { - return galleryimageversions.UefiKey{ - Type: pointer.To(galleryimageversions.UefiKeyType(data["key_type"].(string))), - Value: &[]string{data["certificate_data"].(string)}, - } + return galleryimageversions.UefiKey{ + Type: pointer.To(galleryimageversions.UefiKeyType(data["key_type"].(string))), + Value: &[]string{data["certificate_data"].(string)}, + } } - - func expandStringList(input []interface{}) *[]galleryimageversions.UefiSignatureTemplateName { - result := make([]galleryimageversions.UefiSignatureTemplateName, len(input)) - for i, v := range input { - result[i] = galleryimageversions.UefiSignatureTemplateName(v.(string)) - } - return &result + result := make([]galleryimageversions.UefiSignatureTemplateName, len(input)) + for i, v := range input { + result[i] = galleryimageversions.UefiSignatureTemplateName(v.(string)) + } + return &result } func flattenUefiSettings(input *galleryimageversions.GalleryImageVersionUefiSettings) []interface{} { - if input == nil { - return []interface{}{} - } - - return []interface{}{ - map[string]interface{}{ - "signature_template_names": flattenStringList(*input.SignatureTemplateNames), - "additional_signatures": []interface{}{ - flattenAdditionalSignatures(input.AdditionalSignatures), - }, - }, - } + if input == nil { + return []interface{}{} + } + + return []interface{}{ + map[string]interface{}{ + "signature_template_names": flattenStringList(*input.SignatureTemplateNames), + "additional_signatures": []interface{}{ + flattenAdditionalSignatures(input.AdditionalSignatures), + }, + }, + } } func flattenAdditionalSignatures(input *galleryimageversions.UefiKeySignatures) map[string]interface{} { - if input == nil { - return map[string]interface{}{} - } - - return map[string]interface{}{ - "db": flattenUefiKeyList(input.Db), - "dbx": flattenUefiKeyList(input.Dbx), - "kek": flattenUefiKeyList(input.Kek), - "pk": flattenSingleUefiKey(input.Pk), - } + if input == nil { + return map[string]interface{}{} + } + + return map[string]interface{}{ + "db": flattenUefiKeyList(input.Db), + "dbx": flattenUefiKeyList(input.Dbx), + "kek": flattenUefiKeyList(input.Kek), + "pk": flattenSingleUefiKey(input.Pk), + } } func flattenSingleUefiKey(input *galleryimageversions.UefiKey) []interface{} { - if input == nil || input.Value == nil || len(*input.Value) == 0 { - return []interface{}{} - } - - return []interface{}{ - map[string]interface{}{ - "certificate_data": (*input.Value)[0], - }, - } + if input == nil || input.Value == nil || len(*input.Value) == 0 { + return []interface{}{} + } + + return []interface{}{ + map[string]interface{}{ + "certificate_data": (*input.Value)[0], + }, + } } func flattenUefiKeyList(input *[]galleryimageversions.UefiKey) []interface{} { - if input == nil { - return []interface{}{} - } - - result := make([]interface{}, len(*input)) - for i, v := range *input { - result[i] = flattenUefiKey(&v) - } - return result + if input == nil { + return []interface{}{} + } + + result := make([]interface{}, len(*input)) + for i, v := range *input { + result[i] = flattenUefiKey(&v) + } + return result } func flattenUefiKey(input *galleryimageversions.UefiKey) []interface{} { - if input == nil || input.Value == nil || len(*input.Value) == 0 { - return []interface{}{} - } - - return []interface{}{ - map[string]interface{}{ - "certificate_data": (*input.Value)[0], - "key_type": string(*input.Type), - }, - } + if input == nil || input.Value == nil || len(*input.Value) == 0 { + return []interface{}{} + } + + return []interface{}{ + map[string]interface{}{ + "certificate_data": (*input.Value)[0], + "key_type": string(*input.Type), + }, + } } func flattenStringList(input []galleryimageversions.UefiSignatureTemplateName) []interface{} { - result := make([]interface{}, len(input)) - for i, v := range input { - result[i] = string(v) - } - return result + result := make([]interface{}, len(input)) + for i, v := range input { + result[i] = string(v) + } + return result } func flattenSharedImageVersionTargetRegions(input *[]galleryimageversions.TargetRegion) []interface{} { diff --git a/internal/services/compute/shared_image_version_resource_test.go b/internal/services/compute/shared_image_version_resource_test.go index fb6e116b0756..e8f039ef0846 100644 --- a/internal/services/compute/shared_image_version_resource_test.go +++ b/internal/services/compute/shared_image_version_resource_test.go @@ -290,7 +290,7 @@ func TestAccSharedImageVersion_uefiSettings(t *testing.T) { r := SharedImageVersionResource{} keyType := "x509" - certData := "MIIDNzCCAh+gAwIBAgIRANcuAK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