Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bad0b71
feat: adding in support for query performance factors on affected res…
burythehammer Mar 19, 2025
a626de8
fix: missing schema for pro sub creation plan
burythehammer Mar 24, 2025
b55c2d8
Update TestAccDataSourceRedisCloudProDatabase_basic config with RediS…
trentrosenbaum Mar 25, 2025
13a88a5
Updates datasource_rediscloud_pro_database_test to use a QPF of 2x
trentrosenbaum Mar 25, 2025
e4d3eec
Reverts AA subs to not use query_performance_factor as not supported
trentrosenbaum Mar 25, 2025
2511465
Reverts AA DB to not use query_performance_factor as not supported
trentrosenbaum Mar 25, 2025
141de6f
initial updates for the query_performance_factor
trentrosenbaum Mar 25, 2025
28ad59c
Updates pro sub and DB with QPF CustomDiff validation
trentrosenbaum Mar 27, 2025
3208bb9
New QPF based test
trentrosenbaum Apr 1, 2025
4c8c2dc
expands qpf test
trentrosenbaum Apr 1, 2025
ad66022
Reverts the resource_rediscloud_pro_database_test to focus on non qpf…
trentrosenbaum Apr 3, 2025
1302048
Updates datasource and resources to handle QPF
trentrosenbaum Apr 3, 2025
ddf2459
Updates to use rediscloud-go-api v0.23.0
trentrosenbaum Apr 3, 2025
f723df5
Introduces pro subscription test covering QPF
trentrosenbaum Apr 4, 2025
fde6675
Updates to pro sub and db for tests
trentrosenbaum Apr 4, 2025
350da73
Reducing the TEST_PARALLELISM from 6 to 2 to locate test failure
trentrosenbaum Apr 8, 2025
7c1eac6
set TEST_PARALLELISM to 1
trentrosenbaum Apr 8, 2025
79bd458
Updates to check that the QPF is within 2x to 16x range
trentrosenbaum Apr 9, 2025
7de8e74
Udpates to validate QPF range value
trentrosenbaum Apr 9, 2025
ef2c0f1
Refined the QPF range to be 2x - 8x to match swagger api response
trentrosenbaum Apr 9, 2025
694367e
Restores the TEST_PARALLELISM to a value of 6
trentrosenbaum Apr 29, 2025
99d584a
test: renaming qpf tests so that smoke tests can pick out qpf
burythehammer May 15, 2025
5b65d5d
chore: changing pr workflow to include qpf tests
burythehammer May 15, 2025
2bd68a6
fix: regex for qpf workflow is wrong
burythehammer May 15, 2025
3c69143
fix: nil check on query performance factor
burythehammer May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/terraform_provider_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ jobs:
go-version-file: go.mod
- run: EXECUTE_TESTS=true make testacc TESTARGS='-run="TestAccResourceRedisCloud(PrivateServiceConnect_CRUDI|AclRule_CRUDI)"'

# TODO: remove this after release
# qpf = query performance factor
go_test_smoke_qpf:
name: go test smoke qpf
needs: [ go_build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version-file: go.mod
- run: EXECUTE_TESTS=true make testacc TESTARGS='-run="TestAccResourceRedisCloudProDatabase_qpf.*"'

tfproviderlint:
name: tfproviderlint
needs: [go_build]
Expand Down
9 changes: 9 additions & 0 deletions provider/datasource_rediscloud_pro_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func dataSourceRedisCloudProDatabase() *schema.Resource {
Type: schema.TypeFloat,
Computed: true,
},
"query_performance_factor": {
Description: "Query performance factor for this specific database",
Type: schema.TypeString,
Computed: true,
},
"support_oss_cluster_api": {
Description: "Supports the Redis open-source (OSS) Cluster API",
Type: schema.TypeBool,
Expand Down Expand Up @@ -476,6 +481,10 @@ func dataSourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.Resource
return diag.FromErr(err)
}

if err := d.Set("query_performance_factor", redis.String(*db.QueryPerformanceFactor)); err != nil {
return diag.FromErr(err)
}

return diags
}

Expand Down
10 changes: 10 additions & 0 deletions provider/datasource_rediscloud_pro_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestAccDataSourceRedisCloudProDatabase_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(dataSourceById, "public_endpoint"),
resource.TestCheckResourceAttrSet(dataSourceById, "private_endpoint"),
resource.TestCheckResourceAttr(dataSourceById, "enable_default_user", "true"),
resource.TestCheckResourceAttr(dataSourceById, "query_performance_factor", "2x"),

resource.TestCheckResourceAttr(dataSourceByName, "name", "tf-database"),
resource.TestCheckResourceAttr(dataSourceByName, "protocol", "redis"),
Expand All @@ -59,6 +60,7 @@ func TestAccDataSourceRedisCloudProDatabase_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(dataSourceByName, "public_endpoint"),
resource.TestCheckResourceAttrSet(dataSourceByName, "private_endpoint"),
resource.TestCheckResourceAttr(dataSourceByName, "enable_default_user", "true"),
resource.TestCheckResourceAttr(dataSourceByName, "query_performance_factor", "2x"),
),
},
},
Expand Down Expand Up @@ -94,6 +96,8 @@ resource "rediscloud_subscription" "example" {
support_oss_cluster_api=true
throughput_measurement_by = "operations-per-second"
throughput_measurement_value = 1000
query_performance_factor = "2x"
modules = ["RediSearch"]
}
}
resource "rediscloud_subscription_database" "example" {
Expand All @@ -108,6 +112,12 @@ resource "rediscloud_subscription_database" "example" {
support_oss_cluster_api = true
replication = false
enable_default_user = true
query_performance_factor = "2x"
modules = [
{
name: "RediSearch"
}
]
}

data "rediscloud_database" "example-by-id" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package provider

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccResourceRedisCloudActiveActiveSubscriptionPeering_aws(t *testing.T) {
Expand Down
97 changes: 96 additions & 1 deletion provider/resource_rediscloud_pro_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -49,7 +50,7 @@ func resourceRedisCloudProDatabase() *schema.Resource {
Delete: schema.DefaultTimeout(10 * time.Minute),
},

CustomizeDiff: remoteBackupIntervalSetCorrectly("remote_backup"),
CustomizeDiff: customizeDiff(),

Schema: map[string]*schema.Schema{
"subscription_id": {
Expand Down Expand Up @@ -215,6 +216,25 @@ func resourceRedisCloudProDatabase() *schema.Resource {
},
},
},
"query_performance_factor": {
Description: "Query performance factor for this specific database",
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
v := val.(string)
matched, err := regexp.MatchString(`^([2468])x$`, v)
if err != nil {
errs = append(errs, fmt.Errorf("regex match failed: %s", err))
return
}
if !matched {
errs = append(errs, fmt.Errorf("%q must be an even value between 2x and 8x (inclusive), got: %s", key, v))
}
return
},
},
"modules": {
Description: "Modules to be provisioned in the database",
Type: schema.TypeSet,
Expand Down Expand Up @@ -341,6 +361,7 @@ func resourceRedisCloudProDatabaseCreate(ctx context.Context, d *schema.Resource
throughputMeasurementBy := d.Get("throughput_measurement_by").(string)
throughputMeasurementValue := d.Get("throughput_measurement_value").(int)
averageItemSizeInBytes := d.Get("average_item_size_in_bytes").(int)
queryPerformanceFactor := d.Get("query_performance_factor").(string)

createModules := make([]*databases.Module, 0)
modules := d.Get("modules").(*schema.Set)
Expand Down Expand Up @@ -388,6 +409,10 @@ func resourceRedisCloudProDatabaseCreate(ctx context.Context, d *schema.Resource
RemoteBackup: buildBackupPlan(d.Get("remote_backup").([]interface{}), d.Get("periodic_backup_path")),
}

if queryPerformanceFactor != "" {
createDatabase.QueryPerformanceFactor = redis.String(queryPerformanceFactor)
}

if password != "" {
createDatabase.Password = redis.String(password)
}
Expand Down Expand Up @@ -513,6 +538,10 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

if err := d.Set("query_performance_factor", redis.StringValue(db.QueryPerformanceFactor)); err != nil {
return diag.FromErr(err)
}

if err := d.Set("modules", flattenModules(db.Modules)); err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -585,6 +614,12 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

if db.QueryPerformanceFactor != nil {
if err := d.Set("query_performance_factor", redis.String(*db.QueryPerformanceFactor)); err != nil {
return diag.FromErr(err)
}
}

if err := readTags(ctx, api, subId, dbId, d); err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -681,6 +716,11 @@ func resourceRedisCloudProDatabaseUpdate(ctx context.Context, d *schema.Resource
update.SourceIP = []*string{redis.String("0.0.0.0/0")}
}

queryPerformanceFactor := d.Get("query_performance_factor").(string)
if queryPerformanceFactor != "" {
update.QueryPerformanceFactor = redis.String(queryPerformanceFactor)
}

if d.Get("password").(string) != "" {
update.Password = redis.String(d.Get("password").(string))
}
Expand Down Expand Up @@ -873,6 +913,61 @@ func skipDiffIfIntervalIs12And12HourTimeDiff(k, oldValue, newValue string, d *sc
return oldTime.Minute() == newTime.Minute() && oldTime.Add(12*time.Hour).Hour() == newTime.Hour()
}

func customizeDiff() schema.CustomizeDiffFunc {
return func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if err := validateQueryPerformanceFactor()(ctx, diff, meta); err != nil {
return err
}
if err := remoteBackupIntervalSetCorrectly("remote_backup")(ctx, diff, meta); err != nil {
return err
}
return nil
}
}

func validateQueryPerformanceFactor() schema.CustomizeDiffFunc {
return func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error {
// Check if "query_performance_factor" is set
qpf, qpfExists := diff.GetOk("query_performance_factor")

// Ensure "modules" is explicitly defined in the HCL
_, modulesExists := diff.GetOkExists("modules")

if qpfExists && qpf.(string) != "" {
if !modulesExists {
return fmt.Errorf(`"query_performance_factor" requires the "modules" key to be explicitly defined in HCL`)
}

// Retrieve modules as a slice of interfaces
rawModules := diff.Get("modules").(*schema.Set).List()

// Convert modules to []map[string]interface{}
var modules []map[string]interface{}
for _, rawModule := range rawModules {
if moduleMap, ok := rawModule.(map[string]interface{}); ok {
modules = append(modules, moduleMap)
}
}

// Check if "RediSearch" exists
if !containsDBModule(modules, "RediSearch") {
return fmt.Errorf(`"query_performance_factor" requires the "modules" list to contain "RediSearch"`)
}
}
return nil
}
}

// Helper function to check if a module exists
func containsDBModule(modules []map[string]interface{}, moduleName string) bool {
for _, module := range modules {
if name, ok := module["name"].(string); ok && name == moduleName {
return true
}
}
return false
}

func remoteBackupIntervalSetCorrectly(key string) schema.CustomizeDiffFunc {
// Validate multiple attributes - https://github.com/hashicorp/terraform-plugin-sdk/issues/233

Expand Down
Loading