diff --git a/vultr/data_source_vultr_database.go b/vultr/data_source_vultr_database.go index 0af6c1af..16c4ce5b 100644 --- a/vultr/data_source_vultr_database.go +++ b/vultr/data_source_vultr_database.go @@ -145,7 +145,7 @@ func dataSourceVultrDatabase() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "redis_eviction_policy": { + "eviction_policy": { Type: schema.TypeString, Computed: true, }, @@ -212,7 +212,7 @@ func dataSourceVultrDatabaseRead(ctx context.Context, d *schema.ResourceData, me return diag.Errorf("unable to set resource database `plan` read value: %v", err) } - if databaseList[0].DatabaseEngine != "redis" { + if databaseList[0].DatabaseEngine != "redis" && databaseList[0].DatabaseEngine != "valkey" { if err := d.Set("plan_disk", databaseList[0].PlanDisk); err != nil { return diag.Errorf("unable to set resource database `plan_disk` read value: %v", err) } @@ -346,13 +346,13 @@ func dataSourceVultrDatabaseRead(ctx context.Context, d *schema.ResourceData, me } } - if databaseList[0].DatabaseEngine == "redis" { - if err := d.Set("redis_eviction_policy", databaseList[0].RedisEvictionPolicy); err != nil { - return diag.Errorf("unable to set resource database `redis_eviction_policy` read value: %v", err) + if databaseList[0].DatabaseEngine == "redis" || databaseList[0].DatabaseEngine == "valkey" { + if err := d.Set("eviction_policy", databaseList[0].EvictionPolicy); err != nil { + return diag.Errorf("unable to set resource database `eviction_policy` read value: %v", err) } } - if databaseList[0].DatabaseEngine != "redis" { + if databaseList[0].DatabaseEngine != "redis" && databaseList[0].DatabaseEngine != "valkey" { if err := d.Set("cluster_time_zone", databaseList[0].ClusterTimeZone); err != nil { return diag.Errorf("unable to set resource database `cluster_time_zone` read value: %v", err) } @@ -414,7 +414,7 @@ func flattenReplicas(db *govultr.Database) []map[string]interface{} { "mysql_require_primary_key": db.ReadReplicas[v].MySQLRequirePrimaryKey, "mysql_slow_query_log": db.ReadReplicas[v].MySQLSlowQueryLog, "mysql_long_query_time": db.ReadReplicas[v].MySQLLongQueryTime, - "redis_eviction_policy": db.ReadReplicas[v].RedisEvictionPolicy, + "eviction_policy": db.ReadReplicas[v].EvictionPolicy, "cluster_time_zone": db.ReadReplicas[v].ClusterTimeZone, } @@ -433,11 +433,11 @@ func flattenReplicas(db *govultr.Database) []map[string]interface{} { delete(r, "mysql_sql_long_query_time") } - if db.DatabaseEngine != "redis" { - delete(r, "redis_eviction_policy") + if db.DatabaseEngine != "redis" && db.DatabaseEngine != "valkey" { + delete(r, "eviction_policy") } - if db.DatabaseEngine == "redis" { + if db.DatabaseEngine == "redis" || db.DatabaseEngine == "valkey" { delete(r, "cluster_time_zone") } diff --git a/vultr/database.go b/vultr/database.go index 5c045f74..05da06b8 100644 --- a/vultr/database.go +++ b/vultr/database.go @@ -150,7 +150,7 @@ func readReplicaSchema(isReadReplica bool) map[string]*schema.Schema { Computed: true, Optional: true, }, - "redis_eviction_policy": { + "eviction_policy": { Type: schema.TypeString, Computed: true, Optional: true, @@ -169,24 +169,24 @@ func readReplicaSchema(isReadReplica bool) map[string]*schema.Schema { return s } -func redisACLSchema() map[string]*schema.Schema { +func userACLSchema() map[string]*schema.Schema { s := map[string]*schema.Schema{ - "redis_acl_categories": { + "acl_categories": { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "redis_acl_channels": { + "acl_channels": { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "redis_acl_commands": { + "acl_commands": { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "redis_acl_keys": { + "acl_keys": { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{Type: schema.TypeString}, @@ -196,13 +196,13 @@ func redisACLSchema() map[string]*schema.Schema { return s } -func flattenRedisACL(dbUser *govultr.DatabaseUser) []map[string]interface{} { +func flattenUserACL(dbUser *govultr.DatabaseUser) []map[string]interface{} { f := []map[string]interface{}{ { - "redis_acl_categories": dbUser.AccessControl.RedisACLCategories, - "redis_acl_channels": dbUser.AccessControl.RedisACLChannels, - "redis_acl_commands": dbUser.AccessControl.RedisACLCommands, - "redis_acl_keys": dbUser.AccessControl.RedisACLKeys, + "acl_categories": dbUser.AccessControl.ACLCategories, + "acl_channels": dbUser.AccessControl.ACLChannels, + "acl_commands": dbUser.AccessControl.ACLCommands, + "acl_keys": dbUser.AccessControl.ACLKeys, }, } return f diff --git a/vultr/resource_vultr_database.go b/vultr/resource_vultr_database.go index 83533947..be21b677 100644 --- a/vultr/resource_vultr_database.go +++ b/vultr/resource_vultr_database.go @@ -96,7 +96,7 @@ func resourceVultrDatabase() *schema.Resource { Computed: true, Optional: true, }, - "redis_eviction_policy": { + "eviction_policy": { Type: schema.TypeString, Optional: true, Computed: true, @@ -219,7 +219,7 @@ func resourceVultrDatabaseCreate(ctx context.Context, d *schema.ResourceData, me MySQLRequirePrimaryKey: govultr.BoolToBoolPtr(true), MySQLSlowQueryLog: govultr.BoolToBoolPtr(false), MySQLLongQueryTime: d.Get("mysql_long_query_time").(int), - RedisEvictionPolicy: d.Get("redis_eviction_policy").(string), + EvictionPolicy: d.Get("eviction_policy").(string), } if trustedIPs, trustedIPsOK := d.GetOk("trusted_ips"); trustedIPsOK { @@ -269,7 +269,7 @@ func resourceVultrDatabaseCreate(ctx context.Context, d *schema.ResourceData, me } // Default user (vultradmin) password can only be changed after creation - if password, passwordOK := d.GetOk("password"); passwordOK && d.Get("database_engine").(string) != "redis" { + if password, passwordOK := d.GetOk("password"); passwordOK && d.Get("database_engine").(string) != "redis" && d.Get("database_engine").(string) != "valkey" { //nolint:lll req3 := &govultr.DatabaseUserUpdateReq{ Password: password.(string), } @@ -304,7 +304,7 @@ func resourceVultrDatabaseRead(ctx context.Context, d *schema.ResourceData, meta return diag.Errorf("unable to set resource database `plan` read value: %v", err) } - if database.DatabaseEngine != "redis" { + if database.DatabaseEngine != "redis" && database.DatabaseEngine != "valkey" { if err := d.Set("plan_disk", database.PlanDisk); err != nil { return diag.Errorf("unable to set resource database `plan_disk` read value: %v", err) } @@ -438,13 +438,13 @@ func resourceVultrDatabaseRead(ctx context.Context, d *schema.ResourceData, meta } } - if database.DatabaseEngine == "redis" { - if err := d.Set("redis_eviction_policy", database.RedisEvictionPolicy); err != nil { - return diag.Errorf("unable to set resource database `redis_eviction_policy` read value: %v", err) + if database.DatabaseEngine == "redis" || database.DatabaseEngine == "valkey" { + if err := d.Set("eviction_policy", database.EvictionPolicy); err != nil { + return diag.Errorf("unable to set resource database `eviction_policy` read value: %v", err) } } - if database.DatabaseEngine != "redis" { + if database.DatabaseEngine != "redis" && database.DatabaseEngine != "valkey" { if err := d.Set("cluster_time_zone", database.ClusterTimeZone); err != nil { return diag.Errorf("unable to set resource database `cluster_time_zone` read value: %v", err) } @@ -557,11 +557,11 @@ func resourceVultrDatabaseUpdate(ctx context.Context, d *schema.ResourceData, me req.MySQLLongQueryTime = mysqlLongQueryTime } - if d.HasChange("redis_eviction_policy") { - log.Printf("[INFO] Updating Redis Eviction Policy") - _, newVal := d.GetChange("redis_eviction_policy") - redisEvictionPolicy := newVal.(string) - req.RedisEvictionPolicy = redisEvictionPolicy + if d.HasChange("eviction_policy") { + log.Printf("[INFO] Updating Eviction Policy") + _, newVal := d.GetChange("eviction_policy") + evictionPolicy := newVal.(string) + req.EvictionPolicy = evictionPolicy } if _, _, err := client.Database.Update(ctx, d.Id(), req); err != nil { @@ -581,7 +581,7 @@ func resourceVultrDatabaseUpdate(ctx context.Context, d *schema.ResourceData, me } // Updating the default user password requires a separate API call - if d.HasChange("password") && d.Get("database_engine").(string) != "redis" { + if d.HasChange("password") && d.Get("database_engine").(string) != "redis" && d.Get("database_engine").(string) != "valkey" { //nolint:lll _, newVal := d.GetChange("password") password := newVal.(string) reqP := &govultr.DatabaseUserUpdateReq{ diff --git a/vultr/resource_vultr_database_replica.go b/vultr/resource_vultr_database_replica.go index ed18ea92..e3de24d3 100644 --- a/vultr/resource_vultr_database_replica.go +++ b/vultr/resource_vultr_database_replica.go @@ -102,7 +102,7 @@ func resourceVultrDatabaseReplicaRead(ctx context.Context, d *schema.ResourceDat return diag.Errorf("unable to set resource database read replica `plan` read value: %v", err) } - if database.DatabaseEngine != "redis" { + if database.DatabaseEngine != "redis" && database.DatabaseEngine != "valkey" { if err := d.Set("plan_disk", database.PlanDisk); err != nil { return diag.Errorf("unable to set resource database read replica `plan_disk` read value: %v", err) } @@ -229,16 +229,16 @@ func resourceVultrDatabaseReplicaRead(ctx context.Context, d *schema.ResourceDat } } - if database.DatabaseEngine == "redis" { - if err := d.Set("redis_eviction_policy", database.RedisEvictionPolicy); err != nil { + if database.DatabaseEngine == "redis" || database.DatabaseEngine == "valkey" { + if err := d.Set("eviction_policy", database.EvictionPolicy); err != nil { return diag.Errorf( - "unable to set resource database read replica `redis_eviction_policy` read value: %v", + "unable to set resource database read replica `eviction_policy` read value: %v", err, ) } } - if database.DatabaseEngine != "redis" { + if database.DatabaseEngine != "redis" && database.DatabaseEngine != "valkey" { if err := d.Set("cluster_time_zone", database.ClusterTimeZone); err != nil { return diag.Errorf("unable to set resource database read replica `cluster_time_zone` read value: %v", err) } diff --git a/vultr/resource_vultr_database_user.go b/vultr/resource_vultr_database_user.go index e9a21dc5..6dde5e40 100644 --- a/vultr/resource_vultr_database_user.go +++ b/vultr/resource_vultr_database_user.go @@ -53,7 +53,7 @@ func resourceVultrDatabaseUser() *schema.Resource { Computed: true, MaxItems: 1, Elem: &schema.Resource{ - Schema: redisACLSchema(), + Schema: userACLSchema(), }, }, // Computed @@ -89,9 +89,9 @@ func resourceVultrDatabaseUserCreate(ctx context.Context, d *schema.ResourceData d.SetId(databaseUser.Username) - // Redis user access control can only be updated after creation + // Redis/Valkey user access control can only be updated after creation if accessControl, accessControlOK := d.GetOk("access_control"); accessControlOK { - if err := updateRedisACL(ctx, client, databaseID, d, accessControl); err != nil { + if err := updateUserACL(ctx, client, databaseID, d, accessControl); err != nil { return diag.Errorf("error updating user access control: %v", err) } } @@ -143,7 +143,7 @@ func resourceVultrDatabaseUserRead(ctx context.Context, d *schema.ResourceData, } if databaseUser.AccessControl != nil { - if err := d.Set("access_control", flattenRedisACL(databaseUser)); err != nil { + if err := d.Set("access_control", flattenUserACL(databaseUser)); err != nil { return diag.Errorf("unable to set resource database user `access_control` read value: %v", err) } } @@ -170,7 +170,7 @@ func resourceVultrDatabaseUserUpdate(ctx context.Context, d *schema.ResourceData if d.HasChange("access_control") { _, accessControl := d.GetChange("access_control") - if err := updateRedisACL(ctx, client, databaseID, d, accessControl); err != nil { + if err := updateUserACL(ctx, client, databaseID, d, accessControl); err != nil { return diag.Errorf("error updating user access control: %v", err) } } @@ -203,32 +203,32 @@ func resourceVultrDatabaseUserDelete(ctx context.Context, d *schema.ResourceData return nil } -func updateRedisACL(ctx context.Context, client *govultr.Client, databaseID string, d *schema.ResourceData, accessControl interface{}) error { //nolint:lll +func updateUserACL(ctx context.Context, client *govultr.Client, databaseID string, d *schema.ResourceData, accessControl interface{}) error { //nolint:lll // This should only loop once due to MaxItems: 1 in the resource definition for _, v := range accessControl.(*schema.Set).List() { var req = &govultr.DatabaseUserACLReq{} var aclCategories, aclChannels, aclCommands, aclKeys []string obj := v.(map[string]interface{}) - for _, r := range obj["redis_acl_categories"].(*schema.Set).List() { + for _, r := range obj["acl_categories"].(*schema.Set).List() { aclCategories = append(aclCategories, r.(string)) } - req.RedisACLCategories = &aclCategories + req.ACLCategories = &aclCategories - for _, r := range obj["redis_acl_channels"].(*schema.Set).List() { + for _, r := range obj["acl_channels"].(*schema.Set).List() { aclChannels = append(aclChannels, r.(string)) } - req.RedisACLChannels = &aclChannels + req.ACLChannels = &aclChannels - for _, r := range obj["redis_acl_commands"].(*schema.Set).List() { + for _, r := range obj["acl_commands"].(*schema.Set).List() { aclCommands = append(aclCommands, r.(string)) } - req.RedisACLCommands = &aclCommands + req.ACLCommands = &aclCommands - for _, r := range obj["redis_acl_keys"].(*schema.Set).List() { + for _, r := range obj["acl_keys"].(*schema.Set).List() { aclKeys = append(aclKeys, r.(string)) } - req.RedisACLKeys = &aclKeys + req.ACLKeys = &aclKeys log.Printf("[INFO] Updating user access control") if _, _, err := client.Database.UpdateUserACL(ctx, databaseID, d.Id(), req); err != nil { diff --git a/website/docs/d/database.html.markdown b/website/docs/d/database.html.markdown index 5569ca37..562a45e5 100644 --- a/website/docs/d/database.html.markdown +++ b/website/docs/d/database.html.markdown @@ -69,6 +69,7 @@ The following attributes are exported: * `mysql_require_primary_key` - The configuration value for whether primary keys are required on the managed database (MySQL engine types only). * `mysql_slow_query_log` - The configuration value for slow query logging on the managed database (MySQL engine types only). * `mysql_long_query_time` - The configuration value for the long query time (in seconds) on the managed database (MySQL engine types only). -* `redis_eviction_policy` - The configuration value for the data eviction policy on the managed database (Redis engine types only). +* `redis_eviction_policy` - (Deprecated: use `eviction_policy` instead) The configuration value for the data eviction policy on the managed database (Redis engine types only). +* `eviction_policy` - The configuration value for the data eviction policy on the managed database (Redis engine types only). * `cluster_time_zone` - The configured time zone for the Managed Database in TZ database format. * `read_replicas` - A list of read replicas attached to the managed database. diff --git a/website/docs/r/database.html.markdown b/website/docs/r/database.html.markdown index 68351330..627f07fc 100644 --- a/website/docs/r/database.html.markdown +++ b/website/docs/r/database.html.markdown @@ -64,7 +64,8 @@ The following arguments are supported: * `mysql_require_primary_key` - (Optional) The configuration value for whether primary keys are required on the managed database (MySQL engine types only). * `mysql_slow_query_log` - (Optional) The configuration value for slow query logging on the managed database (MySQL engine types only). * `mysql_long_query_time` - (Optional) The configuration value for the long query time (in seconds) on the managed database (MySQL engine types only). -* `redis_eviction_policy` - (Optional) The configuration value for the data eviction policy on the managed database (Redis engine types only - `noeviction`, `allkeys-lru`, `volatile-lru`, `allkeys-random`, `volatile-random`, `volatile-ttl`, `volatile-lfu`, `allkeys-lfu`). +* `redis_eviction_policy` - (Deprecated: use `eviction_policy` instead) The configuration value for the data eviction policy on the managed database (Redis engine types only). +* `eviction_policy` - (Optional) The configuration value for the data eviction policy on the managed database (Redis engine types only - `noeviction`, `allkeys-lru`, `volatile-lru`, `allkeys-random`, `volatile-random`, `volatile-ttl`, `volatile-lfu`, `allkeys-lfu`). ## Attributes Reference @@ -103,7 +104,8 @@ The following attributes are exported: * `mysql_require_primary_key` - The configuration value for whether primary keys are required on the managed database (MySQL engine types only). * `mysql_slow_query_log` - The configuration value for slow query logging on the managed database (MySQL engine types only). * `mysql_long_query_time` - The configuration value for the long query time (in seconds) on the managed database (MySQL engine types only). -* `redis_eviction_policy` - The configuration value for the data eviction policy on the managed database (Redis engine types only). +* `redis_eviction_policy` - (Deprecated: use `eviction_policy` instead) The configuration value for the data eviction policy on the managed database (Redis engine types only). +* `eviction_policy` - The configuration value for the data eviction policy on the managed database (Redis engine types only). * `cluster_time_zone` - The configured time zone for the Managed Database in TZ database format. * `read_replicas` - A list of read replicas attached to the managed database. diff --git a/website/docs/r/database_replica.html.markdown b/website/docs/r/database_replica.html.markdown index a2415833..7e71176a 100644 --- a/website/docs/r/database_replica.html.markdown +++ b/website/docs/r/database_replica.html.markdown @@ -69,5 +69,6 @@ The following attributes are exported: * `mysql_require_primary_key` - The configuration value for whether primary keys are required on the managed database read replica (MySQL engine types only). * `mysql_slow_query_log` - The configuration value for slow query logging on the managed database read replica (MySQL engine types only). * `mysql_long_query_time` - The configuration value for the long query time (in seconds) on the managed database read replica (MySQL engine types only). -* `redis_eviction_policy` - The configuration value for the data eviction policy on the managed database read replica (Redis engine types only). +* `redis_eviction_policy` - (Deprecated: use `eviction_policy` instead) The configuration value for the data eviction policy on the managed database read replica (Redis engine types only). +* `eviction_policy` - The configuration value for the data eviction policy on the managed database read replica (Redis engine types only). * `cluster_time_zone` - The configured time zone for the managed database read replica in TZ database format. diff --git a/website/docs/r/database_user.html.markdown b/website/docs/r/database_user.html.markdown index 72692df2..a463c75c 100644 --- a/website/docs/r/database_user.html.markdown +++ b/website/docs/r/database_user.html.markdown @@ -54,7 +54,11 @@ The following attributes are exported: `access_control` -* `redis_acl_categories` - List of command category rules for this managed database user (Redis engine types only). -* `redis_acl_channels` - List of publish/subscribe channel patterns for this managed database user (Redis engine types only). -* `redis_acl_commands` - List of individual command rules for this managed database user (Redis engine types only). -* `redis_acl_keys` - List of access rules for this managed database user (Redis engine types only). +* `redis_acl_categories` - (Deprecated: use `acl_categories` instead) List of command category rules for this managed database user (Redis engine types only). +* `redis_acl_channels` - (Deprecated: use `acl_channels` instead) List of publish/subscribe channel patterns for this managed database user (Redis engine types only). +* `redis_acl_commands` - (Deprecated: use `acl_commands` instead) List of individual command rules for this managed database user (Redis engine types only). +* `redis_acl_keys` - (Deprecated: use `acl_keys` instead) List of access rules for this managed database user (Redis engine types only). +* `acl_categories` - List of command category rules for this managed database user (Redis engine types only). +* `acl_channels` - List of publish/subscribe channel patterns for this managed database user (Redis engine types only). +* `acl_commands` - List of individual command rules for this managed database user (Redis engine types only). +* `acl_keys` - List of access rules for this managed database user (Redis engine types only).