-
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_redis_cache
- Fix the issue about data persistence could not be switched
#20286
Conversation
return nil, fmt.Errorf("The rdb_storage_connection_string property must be set when rdb_backup_enabled is true") | ||
// the "output.RdbBackupEnabled" should be set value when the rdb_backup_enabled is set to false in config since not setting false means it could not be disabled using patch to update the Redis Cache. | ||
// d.GetOk cannot identify if user sets the property that is bool type and `rdb_backup_enabled` is set as `false`. So it has to identify it using `d.GetRawConfig()` | ||
if v := d.GetRawConfig().AsValueMap()["redis_configuration"].AsValueSlice(); len(v) > 0 && !v[0].AsValueMap()["rdb_backup_enabled"].IsNull() { |
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.
rather than using GetRawConfig
- we should update this to use d.GetOkExists
- since this approach can be nil/crash at multiple points along this expression
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.
@tombuildsstuff thanks for your time to review this PR. If we use if v, ok := d.GetOkExists("redis_configuration.0.rdb_backup_enabled"); ok{
instead of GetRawConfig
, the vaule of ok is true when the rdb_backup_enabled
is removed in tf config. But the GetRawConfig
is null (meaning false) in this case.
Using GetOkExists
means that if user specifies rdb_backup_enabled
as true in creating a resource, and then removes rdb_backup_enabled
in tf config to update the resource, the rdb_backup_enabled
would be set to false. In fact, the behavior of API in this case, the rdb_backup_enabled
should remain true. That's why I use GetRawConfig
ranther than GetOkExists
. BTW, if rdb_backup_enabled is not specified, API return nil.
So I assume that the GetRawConfig
could not be replaced by GetOkExists
. Please feel free let me know your feedback on this case.
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.
@sinbai if you are going to do this you must be checking each conversion for a nil/crash. right now if anything changes/something unexpected happens this code will panic
output.AdditionalProperties["aof-backup-enabled"] = utils.String(strconv.FormatBool(v)) | ||
// the "output.AdditionalProperties["aof-backup-enabled"]" should be set value when the aof_backup_enabled is set to false in config since not setting false means it could not be disabled using patch to update the Redis Cache. | ||
// d.GetOk cannot identify if user sets the property that is bool type and `aof_backup_enabled` is set as `false`. So it has to identify it using `d.GetRawConfig()` | ||
if v := d.GetRawConfig().AsValueMap()["redis_configuration"].AsValueSlice(); len(v) > 0 && !v[0].AsValueMap()["aof_backup_enabled"].IsNull() { |
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.
(same here)
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.
Same answer as above.
@@ -143,6 +143,7 @@ func TestAccRedisCache_BackupDisabled(t *testing.T) { | |||
Check: acceptance.ComposeTestCheckFunc( | |||
check.That(data.ResourceName).ExistsInAzure(r), | |||
), | |||
ExpectNonEmptyPlan: true, |
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.
doing this would signify there's a bug to fix?
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.
Yes, there is a bug. I have added a comment to it.
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.
hi @sinbai
Thanks for this PR.
I've taken a look through and left some comments inline, unfortunately we need to take a different approach to what's used here, namely rather than leaning on GetRawConfig
(which can return nil, so will crash in the current context), we can instead use GetOkExists
to achieve the same thing in a safer manner.
Thanks!
aof_storage_connection_string_0 = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.primary_access_key}" | ||
aof_storage_connection_string_1 = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.secondary_access_key}" |
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.
there's primary_
and secondary_
connection strings available on the storage account resource?
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.
This shouldn't be the primary
and secondary
connection strings for the same storage account. This should be 2 separate storage accounts.
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.
@tombuildsstuff , @mclacore , thanks for your feedback. I have updated the test. Could you take another look?
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.
@sinbai LGTM 👍
rdb_backup_enabled = true | ||
rdb_backup_frequency = 60 | ||
rdb_backup_max_snapshot_count = 1 | ||
rdb_storage_connection_string = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.primary_access_key}" |
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.
(same here)
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.
Fixed.
return nil, fmt.Errorf("The rdb_storage_connection_string property must be set when rdb_backup_enabled is true") | ||
// the "output.RdbBackupEnabled" should be set value when the rdb_backup_enabled is set to false in config since not setting false means it could not be disabled using patch to update the Redis Cache. | ||
// d.GetOk cannot identify if user sets the property that is bool type and `rdb_backup_enabled` is set as `false`. So it has to identify it using `d.GetRawConfig()` | ||
if v := d.GetRawConfig().AsValueMap()["redis_configuration"].AsValueSlice(); len(v) > 0 && !v[0].AsValueMap()["rdb_backup_enabled"].IsNull() { |
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.
@sinbai if you are going to do this you must be checking each conversion for a nil/crash. right now if anything changes/something unexpected happens this code will panic
@katbyte thanks for your feedback. Code has been updated. Could you please take another look? |
@sinbai - could we fix the merge conflicts? |
88e461f
to
f9f073f
Compare
Sure, fixed. |
@sinbai - after discussing internally i was informed that GetRawConfig will not be directly available when we switch to framework. We think GetOkExists should be fine as there is a default, so we can just use the default? |
@katbyte As I replied above , |
@sinbai - the problem with us using get raw is that in the future when we move to framework, as i understand it, it won't be supported. so you will be introducing a future breaking change/behaviour we will not be able to mimic. I'm not sure why you cannot just use GetOkExist? it sounds like the property should be defaulting to true to match the API behaviour? and that would be a breaking change that we can ship for 4.0? |
27b63fe
to
73cdd78
Compare
Hi @katbyte The reason I previously thought that using Using But for now, I think that |
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 @sinbai - i think that is fine as the default should already have been false.
LGTM 🌵
This functionality has been released in v3.54.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
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. |
The
rdb_backup_enabled
oraof_backup_enabled
is set to false in config when updating resourceazurerm_redis_cache
, they should be explicitly set value in terraform code so that data persistence could be switched.Fix #20228 .
Test Results:
PASS: TestAccRedisCache_BackupEnabledDisabled (2173.38s)
PASS: TestAccRedisCache_AOFBackupEnabledDisabled (2631.76s)