Skip to content
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

Alter AclRuleUpdate to handle rule-only change #553

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 31 additions & 2 deletions provider/rediscloud_acl_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestAccRedisCloudAclRule_CRUDI(t *testing.T) {
testRuleUpdated := testRule + " -@dangerous ~*"

testCreateTerraform := fmt.Sprintf(testRedisRule, testName, testRule)
testUpdateTerraform := fmt.Sprintf(testRedisRule, testNameUpdated, testRuleUpdated)
testUpdateRuleTerraform := fmt.Sprintf(testRedisRule, testName, testRuleUpdated)
testUpdateNameTerraform := fmt.Sprintf(testRedisRule, testNameUpdated, testRuleUpdated)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -95,7 +96,21 @@ func TestAccRedisCloudAclRule_CRUDI(t *testing.T) {
},
// Test rule update
{
Config: testUpdateTerraform,
Config: testUpdateRuleTerraform,
Check: resource.ComposeTestCheckFunc(
// Test the resource
resource.TestCheckResourceAttr("rediscloud_acl_rule.test", "name", testName),
resource.TestCheckResourceAttr("rediscloud_acl_rule.test", "rule", testRuleUpdated),
// Test the datasource
resource.TestMatchResourceAttr(
"data.rediscloud_acl_rule.test", "id", regexp.MustCompile("^\\d*$")),
resource.TestCheckResourceAttr("data.rediscloud_acl_rule.test", "name", testName),
resource.TestCheckResourceAttr("data.rediscloud_acl_rule.test", "rule", testRuleUpdated),
),
},
// Test rule only update
{
Config: testUpdateNameTerraform,
Check: resource.ComposeTestCheckFunc(
// Test the resource
resource.TestCheckResourceAttr("rediscloud_acl_rule.test", "name", testNameUpdated),
Expand All @@ -107,6 +122,20 @@ func TestAccRedisCloudAclRule_CRUDI(t *testing.T) {
resource.TestCheckResourceAttr("data.rediscloud_acl_rule.test", "rule", testRuleUpdated),
),
},
// Test full update
{
Config: testCreateTerraform,
Check: resource.ComposeTestCheckFunc(
// Test the resource
resource.TestCheckResourceAttr("rediscloud_acl_rule.test", "name", testName),
resource.TestCheckResourceAttr("rediscloud_acl_rule.test", "rule", testRule),
// Test the datasource
resource.TestMatchResourceAttr(
"data.rediscloud_acl_rule.test", "id", regexp.MustCompile("^\\d*$")),
resource.TestCheckResourceAttr("data.rediscloud_acl_rule.test", "name", testName),
resource.TestCheckResourceAttr("data.rediscloud_acl_rule.test", "rule", testRule),
),
},
// Test that that rule is imported successfully
{
Config: fmt.Sprintf(testRedisRule, testNameUpdated, testRuleUpdated),
Expand Down
28 changes: 20 additions & 8 deletions provider/resource_rediscloud_acl_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,28 @@
}

if d.HasChanges("name", "rule") {
updateRedisRuleRequest := redis_rules.CreateRedisRuleRequest{}
if !d.HasChange("name") {
updateRedisRuleRequest := redis_rules.UpdateRedisRuleRequest{}

Check failure on line 114 in provider/resource_rediscloud_acl_rule.go

View workflow job for this annotation

GitHub Actions / go build

undefined: redis_rules.UpdateRedisRuleRequest

name := d.Get("name").(string)
updateRedisRuleRequest.Name = &name
rule := d.Get("rule").(string)
updateRedisRuleRequest.RedisRule = &rule
rule := d.Get("rule").(string)
updateRedisRuleRequest.RedisRule = &rule

err = api.client.RedisRules.Update(ctx, id, updateRedisRuleRequest)
if err != nil {
return diag.FromErr(err)
err = api.client.RedisRules.UpdateRule(ctx, id, updateRedisRuleRequest)

Check failure on line 119 in provider/resource_rediscloud_acl_rule.go

View workflow job for this annotation

GitHub Actions / go build

api.client.RedisRules.UpdateRule undefined (type *redis_rules.API has no field or method UpdateRule)
if err != nil {
return diag.FromErr(err)
}
} else {
updateRedisRuleRequest := redis_rules.CreateRedisRuleRequest{}

name := d.Get("name").(string)
updateRedisRuleRequest.Name = &name
rule := d.Get("rule").(string)
updateRedisRuleRequest.RedisRule = &rule

err = api.client.RedisRules.Update(ctx, id, updateRedisRuleRequest)
if err != nil {
return diag.FromErr(err)
}
}

err = waitForAclRuleToBeActive(ctx, id, api)
Expand Down
Loading