Skip to content

Commit

Permalink
Merge branch 'main' into asaha/LBAAS-2685
Browse files Browse the repository at this point in the history
  • Loading branch information
asaha2 authored Sep 18, 2023
2 parents 73adf13 + 54006ec commit e5229a9
Show file tree
Hide file tree
Showing 17 changed files with 869 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Checkout PR
uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/acceptance-test-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Checkout
uses: actions/checkout@v2
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Import GPG key
id: import_gpg
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
# Runs `go vet` and unit tests.
strategy:
matrix:
go-version: [1.19.x, 1.20.x]
go-version: [1.20.x, 1.21.x]

runs-on: ubuntu-latest
steps:
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# 2.30.0

FEATURES:

- **New Resource:** `digitalocean_spaces_bucket_cors_configuration` (#1021) - @danaelhe

IMPROVEMENTS:

- `provider`: Enable retries for requests that fail with a 429 or 500-level error by default (#1016). - @danaelhe

BUG FIXES:

- `digitalocean_database_user`: Prevent creating multiple users for the same cluster in parallel (#1027). - @andrewsomething
- `digitalocean_database_user`: Remove unneeded GET request post-create (#1028). - @andrewsomething

MISC:

- `docs`: Make it clear that volume name has to start with a letter (#1024). - @ahasna
- `docs`: Update Postgres version in example (#1014). - @danaelhe
- `provider`: Bump Go version to v1.21.0 (#1025). - @andrewsomething
- `provider`: Update godo to v1.102.1 (#1020). - @danaelhe
- `provider`: Update godo dependency to v1.102.0 (#1018). - @danaelhe
- `provider`: Update godo dependency to v1.101.0 (#1017.) - @danaelhe

# 2.29.0

FEATURES:
Expand Down
38 changes: 30 additions & 8 deletions digitalocean/database/resource_database_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (

"github.com/digitalocean/godo"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/config"
"github.com/digitalocean/terraform-provider-digitalocean/internal/mutexkv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

var mutexKV = mutexkv.NewMutexKV()

func ResourceDigitalOceanDatabaseUser() *schema.Resource {
return &schema.Resource{
CreateContext: resourceDigitalOceanDatabaseUserCreate,
Expand Down Expand Up @@ -78,6 +81,11 @@ func resourceDigitalOceanDatabaseUserCreate(ctx context.Context, d *schema.Resou
}
}

// Prevent parallel creation of users for same cluster.
key := fmt.Sprintf("digitalocean_database_cluster/%s/users", clusterID)
mutexKV.Lock(key)
defer mutexKV.Unlock(key)

log.Printf("[DEBUG] Database User create configuration: %#v", opts)
user, _, err := client.Databases.CreateUser(context.Background(), clusterID, opts)
if err != nil {
Expand All @@ -87,11 +95,9 @@ func resourceDigitalOceanDatabaseUserCreate(ctx context.Context, d *schema.Resou
d.SetId(makeDatabaseUserID(clusterID, user.Name))
log.Printf("[INFO] Database User Name: %s", user.Name)

// MongoDB clusters only return the password in response to the initial POST.
// So we need to set it here before any subsequent GETs.
d.Set("password", user.Password)
setDatabaseUserAttributes(d, user)

return resourceDigitalOceanDatabaseUserRead(ctx, d, meta)
return nil
}

func resourceDigitalOceanDatabaseUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand All @@ -112,17 +118,28 @@ func resourceDigitalOceanDatabaseUserRead(ctx context.Context, d *schema.Resourc
return diag.Errorf("Error retrieving Database User: %s", err)
}

d.Set("role", user.Role)
// This will be blank for MongoDB clusters. Don't overwrite the password set on create.
setDatabaseUserAttributes(d, user)

return nil
}

func setDatabaseUserAttributes(d *schema.ResourceData, user *godo.DatabaseUser) {
// Default to "normal" when not set.
if user.Role == "" {
d.Set("role", "normal")
} else {
d.Set("role", user.Role)
}

// This will be blank when GETing MongoDB clusters post-create.
// Don't overwrite the password set on create.
if user.Password != "" {
d.Set("password", user.Password)
}

if user.MySQLSettings != nil {
d.Set("mysql_auth_plugin", user.MySQLSettings.AuthPlugin)
}

return nil
}

func resourceDigitalOceanDatabaseUserUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down Expand Up @@ -155,6 +172,11 @@ func resourceDigitalOceanDatabaseUserDelete(ctx context.Context, d *schema.Resou
clusterID := d.Get("cluster_id").(string)
name := d.Get("name").(string)

// Prevent parallel deletion of users for same cluster.
key := fmt.Sprintf("digitalocean_database_cluster/%s/users", clusterID)
mutexKV.Lock(key)
defer mutexKV.Unlock(key)

log.Printf("[INFO] Deleting Database User: %s", d.Id())
_, err := client.Databases.DeleteUser(context.Background(), clusterID, name)
if err != nil {
Expand Down
75 changes: 75 additions & 0 deletions digitalocean/database/resource_database_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,46 @@ func TestAccDigitalOceanDatabaseUser_MongoDB(t *testing.T) {
})
}

func TestAccDigitalOceanDatabaseUser_MongoDBMultiUser(t *testing.T) {
databaseClusterName := acceptance.RandomTestName()
users := []string{"foo", "bar", "baz", "one", "two"}
config := fmt.Sprintf(testAccCheckDigitalOceanDatabaseUserConfigMongoMultiUser,
databaseClusterName,
users[0], users[0],
users[1], users[1],
users[2], users[2],
users[3], users[3],
users[4], users[4],
)
userResourceNames := make(map[string]string, len(users))
for _, u := range users {
userResourceNames[u] = fmt.Sprintf("digitalocean_database_user.%s", u)
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanDatabaseUserDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
userResourceNames[users[0]], "name", users[0]),
resource.TestCheckResourceAttr(
userResourceNames[users[1]], "name", users[1]),
resource.TestCheckResourceAttr(
userResourceNames[users[2]], "name", users[2]),
resource.TestCheckResourceAttr(
userResourceNames[users[3]], "name", users[3]),
resource.TestCheckResourceAttr(
userResourceNames[users[4]], "name", users[4]),
),
},
},
})
}

func TestAccDigitalOceanDatabaseUser_MySQLAuth(t *testing.T) {
var databaseUser godo.DatabaseUser
databaseClusterName := acceptance.RandomTestName()
Expand Down Expand Up @@ -270,6 +310,41 @@ resource "digitalocean_database_user" "foobar_user" {
name = "%s"
}`

const testAccCheckDigitalOceanDatabaseUserConfigMongoMultiUser = `
resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "mongodb"
version = "4"
size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
}
resource "digitalocean_database_user" "%s" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
}
resource "digitalocean_database_user" "%s" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
}
resource "digitalocean_database_user" "%s" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
}
resource "digitalocean_database_user" "%s" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
}
resource "digitalocean_database_user" "%s" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
}`

const testAccCheckDigitalOceanDatabaseUserConfigMySQLAuth = `
resource "digitalocean_database_cluster" "foobar" {
name = "%s"
Expand Down
1 change: 1 addition & 0 deletions digitalocean/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func Provider() *schema.Provider {
"digitalocean_reserved_ip": reservedip.ResourceDigitalOceanReservedIP(),
"digitalocean_reserved_ip_assignment": reservedip.ResourceDigitalOceanReservedIPAssignment(),
"digitalocean_spaces_bucket": spaces.ResourceDigitalOceanBucket(),
"digitalocean_spaces_bucket_cors_configuration": spaces.ResourceDigitalOceanBucketCorsConfiguration(),
"digitalocean_spaces_bucket_object": spaces.ResourceDigitalOceanSpacesBucketObject(),
"digitalocean_spaces_bucket_policy": spaces.ResourceDigitalOceanSpacesBucketPolicy(),
"digitalocean_ssh_key": sshkey.ResourceDigitalOceanSSHKey(),
Expand Down
1 change: 1 addition & 0 deletions digitalocean/spaces/resource_spaces_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func ResourceDigitalOceanBucket() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Description: "A container holding a list of elements describing allowed methods for a specific origin.",
Deprecated: "Terraform will only perform drift detection if a configuration value is provided. Use the resource `digitalocean_spaces_bucket_cors_configuration` instead.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allowed_methods": {
Expand Down
Loading

0 comments on commit e5229a9

Please sign in to comment.