@@ -199,11 +199,12 @@ func resourceSharedImageVersion() *pluginsdk.Resource {
199199 Elem : & pluginsdk.Resource {
200200 Schema : map [string ]* pluginsdk.Schema {
201201 "signature_template_names" : {
202- Type : pluginsdk .TypeList ,
202+ Type : pluginsdk .TypeSet ,
203203 Required : true ,
204- Elem : & pluginsdk.Schema {Type : pluginsdk .TypeString },
205- // not supported yet
206- // ValidateFunc: validation.StringInSlice(galleryimageversions.PossibleValuesForUefiSignatureTemplateName(), false),
204+ Elem : & pluginsdk.Schema {
205+ Type : pluginsdk .TypeString ,
206+ ValidateFunc : validation .StringInSlice (galleryimageversions .PossibleValuesForUefiSignatureTemplateName (), false ),
207+ },
207208 },
208209 "additional_signatures" : {
209210 Type : pluginsdk .TypeList ,
@@ -285,10 +286,8 @@ func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{
285286 SafetyProfile : & galleryimageversions.GalleryImageVersionSafetyProfile {
286287 AllowDeletionOfReplicatedLocations : utils .Bool (d .Get ("deletion_of_replicated_locations_enabled" ).(bool )),
287288 },
288- StorageProfile : galleryimageversions.GalleryImageVersionStorageProfile {},
289- SecurityProfile : & galleryimageversions.ImageVersionSecurityProfile {
290- UefiSettings : expandUefiSettings (d ),
291- },
289+ StorageProfile : galleryimageversions.GalleryImageVersionStorageProfile {},
290+ SecurityProfile : & galleryimageversions.ImageVersionSecurityProfile {},
292291 },
293292 Tags : tags .Expand (d .Get ("tags" ).(map [string ]interface {})),
294293 }
@@ -330,6 +329,10 @@ func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{
330329 }
331330 }
332331
332+ if v , ok := d .GetOk ("uefi_settings" ); ok {
333+ version .Properties .SecurityProfile .UefiSettings = expandUefiSettings (v .([]interface {}))
334+ }
335+
333336 if err := client .CreateOrUpdateThenPoll (ctx , id , version ); err != nil {
334337 return fmt .Errorf ("creating %s: %+v" , id , err )
335338 }
@@ -389,12 +392,6 @@ func resourceSharedImageVersionUpdate(d *pluginsdk.ResourceData, meta interface{
389392 payload .Properties .PublishingProfile .ExcludeFromLatest = pointer .To (d .Get ("exclude_from_latest" ).(bool ))
390393 }
391394
392- if d .HasChange ("uefi_settings" ) {
393- payload .Properties .SecurityProfile = & galleryimageversions.ImageVersionSecurityProfile {
394- UefiSettings : expandUefiSettings (d ),
395- }
396- }
397-
398395 if d .HasChange ("tags" ) {
399396 payload .Tags = tags .Expand (d .Get ("tags" ).(map [string ]interface {}))
400397 }
@@ -498,9 +495,7 @@ func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{})
498495 }
499496
500497 if securityProfile := props .SecurityProfile ; securityProfile != nil {
501- if uefiSettings := securityProfile .UefiSettings ; uefiSettings != nil {
502- d .Set ("uefi_settings" , flattenUefiSettings (uefiSettings ))
503- }
498+ d .Set ("uefi_settings" , flattenUefiSettings (securityProfile .UefiSettings ))
504499 }
505500 }
506501 return tags .FlattenAndSet (d , model .Tags )
@@ -598,20 +593,16 @@ func expandSharedImageVersionTargetRegions(d *pluginsdk.ResourceData) (*[]galler
598593}
599594
600595func uefiKeySchema () * pluginsdk.Resource {
601- possibleKeyTypes := galleryimageversions .PossibleValuesForUefiKeyType ()
602-
603- validKeyTypes := make ([]string , len (possibleKeyTypes ))
604- for i , keyType := range possibleKeyTypes {
605- validKeyTypes [i ] = keyType
606- }
607-
608596 return & pluginsdk.Resource {
609597 Schema : map [string ]* pluginsdk.Schema {
610- "certificate_data " : {
611- Type : pluginsdk .TypeString ,
598+ "certificate_base64 " : {
599+ Type : pluginsdk .TypeList ,
612600 Required : true ,
601+ Elem : & pluginsdk.Schema {
602+ Type : pluginsdk .TypeString ,
603+ },
613604 },
614- "key_type " : {
605+ "type " : {
615606 Type : pluginsdk .TypeString ,
616607 Required : true ,
617608 ValidateFunc : validation .StringInSlice (galleryimageversions .PossibleValuesForUefiKeyType (), false ),
@@ -620,144 +611,169 @@ func uefiKeySchema() *pluginsdk.Resource {
620611 }
621612}
622613
623- func expandUefiSettings (d * pluginsdk.ResourceData ) * galleryimageversions.GalleryImageVersionUefiSettings {
624- if uefiSettings , ok := d .GetOk ("uefi_settings" ); ok {
625- settings := uefiSettings .([]interface {})
626- if len (settings ) == 0 {
627- return nil
628- }
629-
630- us := settings [0 ].(map [string ]interface {})
631- return & galleryimageversions.GalleryImageVersionUefiSettings {
632- SignatureTemplateNames : expandStringList (us ["signature_template_names" ].([]interface {})),
633- AdditionalSignatures : expandAdditionalSignatures (us ["additional_signatures" ]),
634- }
614+ func expandUefiSettings (input []interface {}) * galleryimageversions.GalleryImageVersionUefiSettings {
615+ if len (input ) == 0 || input [0 ] == nil {
616+ return nil
635617 }
636- return nil
637- }
638618
639- func expandAdditionalSignatures (input interface {}) * galleryimageversions.UefiKeySignatures {
640- if input == nil {
641- return nil
619+ v := input [0 ].(map [string ]interface {})
620+ result := & galleryimageversions.GalleryImageVersionUefiSettings {}
621+
622+ if templateNamesSet , ok := v ["signature_template_names" ].(* pluginsdk.Set ); ok {
623+ result .SignatureTemplateNames = expandSignatureTemplateNames (templateNamesSet .List ())
642624 }
643625
644- data := input .([]interface {})[0 ].(map [string ]interface {})
645- return & galleryimageversions.UefiKeySignatures {
646- Db : expandUefiKeyList (data ["db" ]),
647- Dbx : expandUefiKeyList (data ["dbx" ]),
648- Kek : expandUefiKeyList (data ["kek" ]),
649- Pk : expandSingleUefiKey (data ["pk" ]),
626+ if additionalSignatures , ok := v ["additional_signatures" ].([]interface {}); ok {
627+ result .AdditionalSignatures = expandAdditionalSignatures (additionalSignatures )
650628 }
629+
630+ return result
651631}
652632
653- func expandUefiKeyList (input interface {}) * []galleryimageversions.UefiKey {
654- if input == nil {
633+ func expandSignatureTemplateNames (input [] interface {}) * []galleryimageversions.UefiSignatureTemplateName {
634+ if len ( input ) == 0 {
655635 return nil
656636 }
657637
658- keys := input .([]interface {})
659- result := make ([]galleryimageversions.UefiKey , len (keys ))
660- for i , v := range keys {
661- result [i ] = expandUefiKey (v .(map [string ]interface {})) // Correctly returns a value, not a pointer
638+ result := make ([]galleryimageversions.UefiSignatureTemplateName , 0 )
639+ for _ , v := range input {
640+ result = append (result , galleryimageversions .UefiSignatureTemplateName (v .(string )))
662641 }
663642 return & result
664643}
665644
666- func expandSingleUefiKey (input interface {}) * galleryimageversions.UefiKey {
667- if input == nil {
645+ func expandAdditionalSignatures (input [] interface {}) * galleryimageversions.UefiKeySignatures {
646+ if len ( input ) == 0 || input [ 0 ] == nil {
668647 return nil
669648 }
670649
671- keys := input .([]interface {})
672- if len (keys ) == 0 {
673- return nil
650+ v := input [0 ].(map [string ]interface {})
651+ result := & galleryimageversions.UefiKeySignatures {}
652+
653+ if db , ok := v ["db" ].([]interface {}); ok {
654+ result .Db = expandUefiKeyList (db )
674655 }
675656
676- data := keys [0 ].(map [string ]interface {})
677- return & galleryimageversions.UefiKey {
678- Type : pointer .To (galleryimageversions .UefiKeyType (data ["key_type" ].(string ))),
679- Value : & []string {data ["certificate_data" ].(string )},
657+ if dbx , ok := v ["dbx" ].([]interface {}); ok {
658+ result .Dbx = expandUefiKeyList (dbx )
659+ }
660+
661+ if kek , ok := v ["kek" ].([]interface {}); ok {
662+ result .Kek = expandUefiKeyList (kek )
680663 }
681- }
682664
683- func expandUefiKey (data map [string ]interface {}) galleryimageversions.UefiKey {
684- return galleryimageversions.UefiKey {
685- Type : pointer .To (galleryimageversions .UefiKeyType (data ["key_type" ].(string ))),
686- Value : & []string {data ["certificate_data" ].(string )},
665+ if pk , ok := v ["pk" ].([]interface {}); ok {
666+ result .Pk = expandUefiKey (pk )
687667 }
668+
669+ return result
688670}
689671
690- func expandStringList (input []interface {}) * []galleryimageversions.UefiSignatureTemplateName {
691- result := make ([]galleryimageversions.UefiSignatureTemplateName , len (input ))
692- for i , v := range input {
693- result [i ] = galleryimageversions .UefiSignatureTemplateName (v .(string ))
672+ func expandUefiKeyList (input []interface {}) * []galleryimageversions.UefiKey {
673+ if len (input ) == 0 {
674+ return nil
675+ }
676+
677+ result := make ([]galleryimageversions.UefiKey , 0 )
678+ for _ , v := range input {
679+ if item := expandUefiKey ([]interface {}{v }); item != nil {
680+ result = append (result , * item )
681+ }
694682 }
695683 return & result
696684}
697685
698- func flattenUefiSettings (input * galleryimageversions. GalleryImageVersionUefiSettings ) []interface {} {
699- if input == nil {
700- return [] interface {}{}
686+ func expandUefiKey (input []interface {}) * galleryimageversions. UefiKey {
687+ if len ( input ) == 0 || input [ 0 ] == nil {
688+ return nil
701689 }
702690
703- return []interface {}{
704- map [string ]interface {}{
705- "signature_template_names" : * input .SignatureTemplateNames ,
706- "additional_signatures" : []interface {}{
707- flattenAdditionalSignatures (input .AdditionalSignatures ),
708- },
709- },
691+ data , ok := input [0 ].(map [string ]interface {})
692+ if ! ok {
693+ return nil
710694 }
711- }
712695
713- func flattenAdditionalSignatures (input * galleryimageversions.UefiKeySignatures ) map [string ]interface {} {
714- if input == nil {
715- return map [string ]interface {}{}
696+ certData := make ([]string , 0 )
697+ if certList , ok := data ["certificate_base64" ].([]interface {}); ok {
698+ for _ , item := range certList {
699+ if str , ok := item .(string ); ok {
700+ certData = append (certData , str )
701+ }
702+ }
716703 }
717704
718- return map [string ]interface {}{
719- "db" : flattenUefiKeyList (input .Db ),
720- "dbx" : flattenUefiKeyList (input .Dbx ),
721- "kek" : flattenUefiKeyList (input .Kek ),
722- "pk" : flattenSingleUefiKey (input .Pk ),
705+ typeStr , ok := data ["type" ].(string )
706+ if ! ok {
707+ return nil
708+ }
709+
710+ return & galleryimageversions.UefiKey {
711+ Type : pointer .To (galleryimageversions .UefiKeyType (typeStr )),
712+ Value : & certData ,
723713 }
724714}
725715
726- func flattenSingleUefiKey (input * galleryimageversions.UefiKey ) []interface {} {
727- if input == nil || input .Value == nil || len (* input .Value ) == 0 {
728- return []interface {}{}
716+ func flattenUefiSettings (input * galleryimageversions.GalleryImageVersionUefiSettings ) []interface {} {
717+ results := make ([]interface {}, 0 )
718+
719+ if input == nil {
720+ return results
729721 }
730722
731- return []interface {}{
732- map [string ]interface {}{
733- "certificate_data" : (* input .Value )[0 ],
734- },
723+ results = append (results , map [string ]interface {}{
724+ "signature_template_names" : pointer .From (input .SignatureTemplateNames ),
725+ "additional_signatures" : flattenAdditionalSignatures (input .AdditionalSignatures ),
726+ })
727+
728+ return results
729+ }
730+
731+ func flattenAdditionalSignatures (input * galleryimageversions.UefiKeySignatures ) []interface {} {
732+ results := make ([]interface {}, 0 )
733+
734+ if input == nil {
735+ return results
735736 }
737+
738+ result := make (map [string ]interface {})
739+ result ["db" ] = flattenUefiKeyList (input .Db )
740+ result ["dbx" ] = flattenUefiKeyList (input .Dbx )
741+ result ["kek" ] = flattenUefiKeyList (input .Kek )
742+ result ["pk" ] = flattenUefiKey (input .Pk )
743+
744+ return append (results , result )
736745}
737746
738747func flattenUefiKeyList (input * []galleryimageversions.UefiKey ) []interface {} {
748+ results := make ([]interface {}, 0 )
739749 if input == nil {
740- return [] interface {}{}
750+ return results
741751 }
742752
743- result := make ([]interface {}, len (* input ))
744- for i , v := range * input {
745- result [i ] = flattenUefiKey (& v )
753+ for _ , v := range * input {
754+ if item := flattenUefiKey (& v ); len (item ) > 0 {
755+ results = append (results , item [0 ])
756+ }
746757 }
747- return result
758+
759+ return results
748760}
749761
750762func flattenUefiKey (input * galleryimageversions.UefiKey ) []interface {} {
751- if input == nil || input .Value == nil || len (* input .Value ) == 0 {
752- return []interface {}{}
763+ results := make ([]interface {}, 0 )
764+ if input == nil {
765+ return results
753766 }
754767
755- return []interface {}{
756- map [string ]interface {}{
757- "certificate_data" : (* input .Value )[0 ],
758- "key_type" : string (* input .Type ),
759- },
768+ result := make (map [string ]interface {})
769+ if input .Value != nil && len (* input .Value ) > 0 {
770+ result ["certificate_base64" ] = (* input .Value )[0 ]
760771 }
772+ if input .Type != nil {
773+ result ["type" ] = pointer .From (input .Type )
774+ }
775+
776+ return append (results , result )
761777}
762778
763779func flattenSharedImageVersionTargetRegions (input * []galleryimageversions.TargetRegion ) []interface {} {
0 commit comments