-
Notifications
You must be signed in to change notification settings - Fork 5k
azurerm_shared_image_version - support for new block uefi_settings
#28076
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
3a648d0
e1f9fc0
190c298
3c1cf81
d1c7667
988dfae
317a68f
c8e6b74
9da880a
670cedc
2524c4f
3b5fda2
dfa88b1
c6f1351
c542784
b9e1c85
bf5582d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,6 +191,55 @@ func resourceSharedImageVersion() *pluginsdk.Resource { | |
| Default: false, | ||
| }, | ||
|
|
||
| "uefi_settings": { | ||
| Type: pluginsdk.TypeList, | ||
| Optional: true, | ||
| ForceNew: true, | ||
|
yeoldegrove marked this conversation as resolved.
|
||
| MaxItems: 1, | ||
| Elem: &pluginsdk.Resource{ | ||
| Schema: map[string]*pluginsdk.Schema{ | ||
| "signature_template_names": { | ||
| Type: pluginsdk.TypeSet, | ||
| Required: true, | ||
| Elem: &pluginsdk.Schema{ | ||
| Type: pluginsdk.TypeString, | ||
| 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(), | ||
| }, | ||
|
yeoldegrove marked this conversation as resolved.
|
||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| "tags": commonschema.Tags(), | ||
| }, | ||
|
|
||
|
|
@@ -237,7 +286,8 @@ func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{ | |
| SafetyProfile: &galleryimageversions.GalleryImageVersionSafetyProfile{ | ||
| AllowDeletionOfReplicatedLocations: utils.Bool(d.Get("deletion_of_replicated_locations_enabled").(bool)), | ||
| }, | ||
| StorageProfile: galleryimageversions.GalleryImageVersionStorageProfile{}, | ||
| StorageProfile: galleryimageversions.GalleryImageVersionStorageProfile{}, | ||
| SecurityProfile: &galleryimageversions.ImageVersionSecurityProfile{}, | ||
| }, | ||
| Tags: tags.Expand(d.Get("tags").(map[string]interface{})), | ||
| } | ||
|
|
@@ -279,6 +329,10 @@ func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{ | |
| } | ||
| } | ||
|
|
||
| if v, ok := d.GetOk("uefi_settings"); ok { | ||
| version.Properties.SecurityProfile.UefiSettings = expandUefiSettings(v.([]interface{})) | ||
| } | ||
|
|
||
| if err := client.CreateOrUpdateThenPoll(ctx, id, version); err != nil { | ||
| return fmt.Errorf("creating %s: %+v", id, err) | ||
| } | ||
|
|
@@ -439,6 +493,10 @@ func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{}) | |
| if safetyProfile := props.SafetyProfile; safetyProfile != nil { | ||
| d.Set("deletion_of_replicated_locations_enabled", pointer.From(safetyProfile.AllowDeletionOfReplicatedLocations)) | ||
| } | ||
|
|
||
| if securityProfile := props.SecurityProfile; securityProfile != nil { | ||
| d.Set("uefi_settings", flattenUefiSettings(securityProfile.UefiSettings)) | ||
| } | ||
|
yeoldegrove marked this conversation as resolved.
|
||
| } | ||
| return tags.FlattenAndSet(d, model.Tags) | ||
| } | ||
|
|
@@ -534,6 +592,190 @@ func expandSharedImageVersionTargetRegions(d *pluginsdk.ResourceData) (*[]galler | |
| return &results, nil | ||
| } | ||
|
|
||
| func uefiKeySchema() *pluginsdk.Resource { | ||
| return &pluginsdk.Resource{ | ||
| Schema: map[string]*pluginsdk.Schema{ | ||
| "certificate_base64": { | ||
| Type: pluginsdk.TypeList, | ||
| Required: true, | ||
| Elem: &pluginsdk.Schema{ | ||
| Type: pluginsdk.TypeString, | ||
| }, | ||
| }, | ||
| "type": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ValidateFunc: validation.StringInSlice(galleryimageversions.PossibleValuesForUefiKeyType(), false), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
yeoldegrove marked this conversation as resolved.
Outdated
|
||
|
|
||
| func expandUefiSettings(input []interface{}) *galleryimageversions.GalleryImageVersionUefiSettings { | ||
| if len(input) == 0 || input[0] == nil { | ||
| return nil | ||
| } | ||
|
|
||
| v := input[0].(map[string]interface{}) | ||
| result := &galleryimageversions.GalleryImageVersionUefiSettings{} | ||
|
|
||
| if templateNamesSet, ok := v["signature_template_names"].(*pluginsdk.Set); ok { | ||
| result.SignatureTemplateNames = expandSignatureTemplateNames(templateNamesSet.List()) | ||
| } | ||
|
|
||
| if additionalSignatures, ok := v["additional_signatures"].([]interface{}); ok { | ||
| result.AdditionalSignatures = expandAdditionalSignatures(additionalSignatures) | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func expandSignatureTemplateNames(input []interface{}) *[]galleryimageversions.UefiSignatureTemplateName { | ||
| if len(input) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| result := make([]galleryimageversions.UefiSignatureTemplateName, 0) | ||
| for _, v := range input { | ||
| result = append(result, galleryimageversions.UefiSignatureTemplateName(v.(string))) | ||
| } | ||
| return &result | ||
| } | ||
|
|
||
| func expandAdditionalSignatures(input []interface{}) *galleryimageversions.UefiKeySignatures { | ||
| if len(input) == 0 || input[0] == nil { | ||
| return nil | ||
| } | ||
|
|
||
| v := input[0].(map[string]interface{}) | ||
| result := &galleryimageversions.UefiKeySignatures{} | ||
|
|
||
| if db, ok := v["db"].([]interface{}); ok { | ||
| result.Db = expandUefiKeyList(db) | ||
| } | ||
|
|
||
| if dbx, ok := v["dbx"].([]interface{}); ok { | ||
| result.Dbx = expandUefiKeyList(dbx) | ||
| } | ||
|
|
||
| if kek, ok := v["kek"].([]interface{}); ok { | ||
| result.Kek = expandUefiKeyList(kek) | ||
| } | ||
|
|
||
| if pk, ok := v["pk"].([]interface{}); ok { | ||
| result.Pk = expandUefiKey(pk) | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func expandUefiKeyList(input []interface{}) *[]galleryimageversions.UefiKey { | ||
| if len(input) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| result := make([]galleryimageversions.UefiKey, 0) | ||
| for _, v := range input { | ||
| if item := expandUefiKey([]interface{}{v}); item != nil { | ||
| result = append(result, *item) | ||
| } | ||
| } | ||
| return &result | ||
| } | ||
|
|
||
| func expandUefiKey(input []interface{}) *galleryimageversions.UefiKey { | ||
| if len(input) == 0 || input[0] == nil { | ||
| return nil | ||
| } | ||
|
|
||
| data, ok := input[0].(map[string]interface{}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the schema currently allows for more than 1 of each uefikey to be specified, if it is not possible to have more than 1 we should update the schema to specify
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Cannot remember why I did only return the first item. |
||
| if !ok { | ||
| return nil | ||
| } | ||
|
yeoldegrove marked this conversation as resolved.
Outdated
|
||
|
|
||
| certData := make([]string, 0) | ||
| if certList, ok := data["certificate_base64"].([]interface{}); ok { | ||
| for _, item := range certList { | ||
| if str, ok := item.(string); ok { | ||
| certData = append(certData, str) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| typeStr, ok := data["type"].(string) | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
yeoldegrove marked this conversation as resolved.
Outdated
|
||
|
|
||
| return &galleryimageversions.UefiKey{ | ||
| Type: pointer.To(galleryimageversions.UefiKeyType(typeStr)), | ||
| Value: &certData, | ||
| } | ||
| } | ||
|
|
||
| func flattenUefiSettings(input *galleryimageversions.GalleryImageVersionUefiSettings) []interface{} { | ||
|
yeoldegrove marked this conversation as resolved.
Outdated
|
||
| results := make([]interface{}, 0) | ||
|
|
||
| if input == nil { | ||
| return results | ||
| } | ||
|
|
||
| results = append(results, map[string]interface{}{ | ||
| "signature_template_names": pointer.From(input.SignatureTemplateNames), | ||
| "additional_signatures": flattenAdditionalSignatures(input.AdditionalSignatures), | ||
| }) | ||
|
|
||
| return results | ||
| } | ||
|
|
||
| func flattenAdditionalSignatures(input *galleryimageversions.UefiKeySignatures) []interface{} { | ||
| results := make([]interface{}, 0) | ||
|
|
||
| if input == nil { | ||
| return results | ||
| } | ||
|
|
||
| result := make(map[string]interface{}) | ||
| result["db"] = flattenUefiKeyList(input.Db) | ||
| result["dbx"] = flattenUefiKeyList(input.Dbx) | ||
| result["kek"] = flattenUefiKeyList(input.Kek) | ||
| result["pk"] = flattenUefiKey(input.Pk) | ||
|
|
||
| return append(results, result) | ||
| } | ||
|
|
||
| func flattenUefiKeyList(input *[]galleryimageversions.UefiKey) []interface{} { | ||
| results := make([]interface{}, 0) | ||
| if input == nil { | ||
| return results | ||
| } | ||
|
|
||
| for _, v := range *input { | ||
| if item := flattenUefiKey(&v); len(item) > 0 { | ||
| results = append(results, item[0]) | ||
| } | ||
| } | ||
|
|
||
| return results | ||
| } | ||
|
|
||
| func flattenUefiKey(input *galleryimageversions.UefiKey) []interface{} { | ||
|
yeoldegrove marked this conversation as resolved.
|
||
| results := make([]interface{}, 0) | ||
| if input == nil { | ||
| return results | ||
| } | ||
|
|
||
| result := make(map[string]interface{}) | ||
| if input.Value != nil && len(*input.Value) > 0 { | ||
| result["certificate_base64"] = (*input.Value)[0] | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible for there to be more than 1 certificate? If so, we should set them all here. If there can only be 1, we should consider making this property a string rather than a list
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Cannot remember why I did only return the first item. |
||
| if input.Type != nil { | ||
| result["type"] = pointer.From(input.Type) | ||
| } | ||
|
yeoldegrove marked this conversation as resolved.
Outdated
|
||
|
|
||
| return append(results, result) | ||
| } | ||
|
|
||
| func flattenSharedImageVersionTargetRegions(input *[]galleryimageversions.TargetRegion) []interface{} { | ||
| results := make([]interface{}, 0) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.