-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_storage_account
- Ensure infrastructure_encryption_enabled
property is included during update
#26971
azurerm_storage_account
- Ensure infrastructure_encryption_enabled
property is included during update
#26971
Conversation
Hi all! Since it's almost been 3 weeks since opening this pull request I'm wondering if there's anything I've missed? In case there are still things required before this PR can be processed please let me know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR @baaym!
This appears to only be an issue when the CMK is updated since it overwrites the entire Encryption
model in the payload which we populate with the existing values in the update function.
I think this can be fixed with fewer lines of code and with potentially less confusion since this property is actually ForceNew
.
This is the section of the code that is overwriting and clearing RequireInfrastructureEncryption
terraform-provider-azurerm/internal/services/storage/storage_account_resource.go
Lines 1718 to 1727 in 067db3f
if d.HasChange("customer_managed_key") { | |
queueEncryptionKeyType := storageaccounts.KeyType(d.Get("queue_encryption_key_type").(string)) | |
tableEncryptionKeyType := storageaccounts.KeyType(d.Get("table_encryption_key_type").(string)) | |
encryptionRaw := d.Get("customer_managed_key").([]interface{}) | |
encryption, err := expandAccountCustomerManagedKey(ctx, keyVaultClient, id.SubscriptionId, encryptionRaw, accountTier, accountKind, *expandedIdentity, queueEncryptionKeyType, tableEncryptionKeyType) | |
if err != nil { | |
return fmt.Errorf("expanding `customer_managed_key`: %+v", err) | |
} | |
props.Encryption = encryption | |
} |
Could you add the following line below 1726 and verify locally whether that also fixes the issue for you?
props.Encryption.RequireInfrastructureEncryption = existing.Model.Properties.Encryption.RequireInfrastructureEncryption
Thanks for looking into this PR @stephybun! The suggested change is indeed much simpler, and I just verified it does the job as well. Many thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to hear that fixes your issue! I left some additional suggestions around nil checking and adding a comment for context. If you could add those in then I can kick off the tests and then this should be good to go!
props.Encryption = encryption | ||
props.Encryption.RequireInfrastructureEncryption = existing.Model.Properties.Encryption.RequireInfrastructureEncryption |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be safe I would suggest only setting this if the existing RequireInfrastructureEncryption
is not nil, also to add a comment above this with some context
props.Encryption.RequireInfrastructureEncryption = existing.Model.Properties.Encryption.RequireInfrastructureEncryption | |
// when updating CMK the existing value for `RequireInfrastructureEncryption` gets overwritten which results in an error from the API so we set this back into encryption after it's been overwritten by this update | |
if v := existing.Model.Properties.Encryption; if v != nil && v.RequireInfrastructureEncryption != nil { | |
props.Encryption.RequireInfrastructureEncryption = v.RequireInfrastructureEncryption | |
} |
When 'customer_managed_key' is updated, the AzureRM provider did not take into account the 'infrastructure_encryption_enabled' property for the Storage Account encryption settings. This change ensures that 'infrastructure_encryption_enabled' is now included in the update as well.
@stephybun I have incorporated your changes (with slight modifications due to things like GitHub UI formatting). Also this change was tested locally and works without issues. Thanks again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @baaym LGTM 🌵
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Community Note
Description
When a Storage Account's
customer_managed_key
is updated, the AzureRM provider did not take into account theinfrastructure_encryption_enabled
property for the Storage Account encryption settings. This change ensures thatinfrastructure_encryption_enabled
is now included in the update as well, with the same behavior as during resource creation.This was notably an issue with Azure's policy engine. During resource update, the
infrastructure_encryption_enabled
property wasn't included at all which most likely meant nothing would change on Azure's side. However any policies that are in place could still expect this property to be included and set totrue
(as was the case with us).PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
I'm not familiar enough with this codebase to determine how to properly add a test case for this change. I have however verified this fix through local execution.
Before the fix:
After this fix:
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_storage_account
- fix omission ofinfrastructure_encryption_enabled
property during CMK updateThis is a (please select all that apply):
Note
If this PR changes meaningfully during the course of review please update the title and description as required.