Skip to content

Commit

Permalink
Database Users: Update settings independent of other user settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinshenker committed Dec 8, 2023
1 parent 7dde232 commit aba6239
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 14 deletions.
12 changes: 10 additions & 2 deletions digitalocean/database/resource_database_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ func userACLSchema() *schema.Resource {
"topic": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},
"permission": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"admin",
"consume",
Expand Down Expand Up @@ -211,6 +209,16 @@ func resourceDigitalOceanDatabaseUserUpdate(ctx context.Context, d *schema.Resou
return diag.Errorf("Error updating mysql_auth_plugin for DatabaseUser: %s", err)
}
}
if d.HasChange("settings") {
updateReq := &godo.DatabaseUpdateUserRequest{}
if v, ok := d.GetOk("settings"); ok {
updateReq.Settings = expandUserSettings(v.([]interface{}))
}
_, _, err := client.Databases.UpdateUser(context.Background(), d.Get("cluster_id").(string), d.Get("name").(string), updateReq)
if err != nil {
return diag.Errorf("Error updating settings for DatabaseUser: %s", err)
}
}

return resourceDigitalOceanDatabaseUserRead(ctx, d, meta)
}
Expand Down
41 changes: 40 additions & 1 deletion digitalocean/database/resource_database_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ func TestAccDigitalOceanDatabaseUser_KafkaACLs(t *testing.T) {
var databaseUser godo.DatabaseUser
databaseClusterName := acceptance.RandomTestName()
databaseUserName := acceptance.RandomTestName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
Expand Down Expand Up @@ -224,6 +223,25 @@ func TestAccDigitalOceanDatabaseUser_KafkaACLs(t *testing.T) {
"digitalocean_database_user.foobar_user", "settings.0.acl.3.permission", "consume"),
),
},
{
Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseUserConfigKafkaACLUpdate, databaseClusterName, databaseUserName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDatabaseUserExists("digitalocean_database_user.foobar_user", &databaseUser),
testAccCheckDigitalOceanDatabaseUserAttributes(&databaseUser, databaseUserName),
resource.TestCheckResourceAttr(
"digitalocean_database_user.foobar_user", "name", databaseUserName),
resource.TestCheckResourceAttrSet(
"digitalocean_database_user.foobar_user", "role"),
resource.TestCheckResourceAttrSet(
"digitalocean_database_user.foobar_user", "password"),
resource.TestCheckResourceAttrSet(
"digitalocean_database_user.foobar_user", "settings.0.acl.0.id"),
resource.TestCheckResourceAttr(
"digitalocean_database_user.foobar_user", "settings.0.acl.0.topic", "topic-1"),
resource.TestCheckResourceAttr(
"digitalocean_database_user.foobar_user", "settings.0.acl.0.permission", "produceconsume"),
),
},
},
})
}
Expand Down Expand Up @@ -445,6 +463,27 @@ resource "digitalocean_database_user" "foobar_user" {
}
}`

const testAccCheckDigitalOceanDatabaseUserConfigKafkaACLUpdate = `
resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "kafka"
version = "3.5"
size = "db-s-2vcpu-2gb"
region = "nyc1"
node_count = 3
}
resource "digitalocean_database_user" "foobar_user" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
settings {
acl {
topic = "topic-1"
permission = "produceconsume"
}
}
}`

const testAccCheckDigitalOceanDatabaseUserConfigMySQLAuthUpdate = `
resource "digitalocean_database_cluster" "foobar" {
name = "%s"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/digitalocean/terraform-provider-digitalocean

require (
github.com/aws/aws-sdk-go v1.42.18
github.com/digitalocean/godo v1.105.1
github.com/digitalocean/godo v1.107.0
github.com/hashicorp/awspolicyequivalence v1.5.0
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.105.0 h1:bUfWVsyQCYZ7OQLK+p2EBFYWD5BoOgpyq/PMSQHEeMg=
github.com/digitalocean/godo v1.105.0/go.mod h1:R6EmmWI8CT1+fCtjWY9UCB+L5uufuZH13wk3YhxycCs=
github.com/digitalocean/godo v1.105.1 h1:3FjFDurw7po27Y0uHhdR+EvwNil06KCeu1Nx/0jZbmI=
github.com/digitalocean/godo v1.105.1/go.mod h1:R6EmmWI8CT1+fCtjWY9UCB+L5uufuZH13wk3YhxycCs=
github.com/digitalocean/godo v1.107.0 h1:P72IbmGFQvKOvyjVLyT59bmHxilA4E5hWi40rF4zNQc=
github.com/digitalocean/godo v1.107.0/go.mod h1:R6EmmWI8CT1+fCtjWY9UCB+L5uufuZH13wk3YhxycCs=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions vendor/github.com/digitalocean/godo/apps.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/digitalocean/godo/apps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions vendor/github.com/digitalocean/godo/apps_accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion vendor/github.com/digitalocean/godo/databases.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/digitalocean/godo/godo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ github.com/aws/aws-sdk-go/service/sts/stsiface
# github.com/davecgh/go-spew v1.1.1
## explicit
github.com/davecgh/go-spew/spew
# github.com/digitalocean/godo v1.105.1
# github.com/digitalocean/godo v1.107.0
## explicit; go 1.20
github.com/digitalocean/godo
github.com/digitalocean/godo/metrics
Expand Down

0 comments on commit aba6239

Please sign in to comment.