Skip to content

Commit

Permalink
More nil check and boolean prop flipping on redis_cache_resource.go
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrytan committed Aug 19, 2024
1 parent b384de3 commit a68b456
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ func resourceRedisCache() *pluginsdk.Resource {
// Entra (AD) auth has to be set to disable access keys auth
// https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-azure-active-directory-for-authentication

accessKeysAuthenticationDisabled := !(diff.Get("access_keys_authentication_enabled").(bool))
accessKeysAuthenticationEnabled := diff.Get("access_keys_authentication_enabled").(bool)
activeDirectoryAuthenticationEnabled := diff.Get("redis_configuration.0.active_directory_authentication_enabled").(bool)

log.Printf("[DEBUG] CustomizeDiff: access_keys_authentication_enabled: %v, active_directory_authentication_enabled: %v", accessKeysAuthenticationDisabled, activeDirectoryAuthenticationEnabled)
log.Printf("[DEBUG] CustomizeDiff: access_keys_authentication_enabled: %v, active_directory_authentication_enabled: %v", accessKeysAuthenticationEnabled, activeDirectoryAuthenticationEnabled)

if accessKeysAuthenticationDisabled && !activeDirectoryAuthenticationEnabled {
if !accessKeysAuthenticationEnabled && !activeDirectoryAuthenticationEnabled {
return fmt.Errorf("`active_directory_authentication_enabled` must be enabled in order to disable `access_keys_authentication_enabled`")
}

Expand Down Expand Up @@ -860,7 +860,11 @@ func resourceRedisCacheRead(d *pluginsdk.ResourceData, meta interface{}) error {
d.Set("primary_access_key", keysResp.Model.PrimaryKey)
d.Set("secondary_access_key", keysResp.Model.SecondaryKey)

d.Set("access_keys_authentication_enabled", !(*props.DisableAccessKeyAuthentication))
accessKeyAuthEnabled := true
if props.DisableAccessKeyAuthentication != nil {
accessKeyAuthEnabled = !(*props.DisableAccessKeyAuthentication)
}
d.Set("access_keys_authentication_enabled", accessKeyAuthEnabled)

if err := tags.FlattenAndSet(d, model.Tags); err != nil {
return fmt.Errorf("setting `tags`: %+v", err)
Expand Down

0 comments on commit a68b456

Please sign in to comment.