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

databases: Support upgrading the database version #918

Merged
merged 1 commit into from
Jan 25, 2023
Merged
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
9 changes: 8 additions & 1 deletion digitalocean/resource_digitalocean_database_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func resourceDigitalOceanDatabaseCluster() *schema.Resource {
// CustomizeDiffFunc is used to provide users with a better hint in the error message.
// Required: true,
Optional: true,
ForceNew: true,
// When Redis clusters are forced to upgrade, this prevents attempting
// to recreate clusters specifying the previous version in their config.
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
Expand Down Expand Up @@ -393,6 +392,14 @@ func resourceDigitalOceanDatabaseClusterUpdate(ctx context.Context, d *schema.Re
}
}

if d.HasChange("version") {
upgradeVersionReq := &godo.UpgradeVersionRequest{Version: d.Get("version").(string)}
_, err := client.Databases.UpgradeMajorVersion(context.Background(), d.Id(), upgradeVersionReq)
if err != nil {
return diag.Errorf("Error upgrading version for database cluster: %s", err)
}
}

if d.HasChange("tags") {
err := setTags(client, d, godo.DatabaseResourceType)
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions digitalocean/resource_digitalocean_database_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,43 @@ func TestAccDigitalOceanDatabaseCluster_MongoDBPassword(t *testing.T) {
})
}

func TestAccDigitalOceanDatabaseCluster_Upgrade(t *testing.T) {
var database godo.Database
databaseName := randomTestName()
previousPGVersion := "13"
latestPGVersion := "14"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanDatabaseClusterDestroy,
Steps: []resource.TestStep{
{
// TODO: Hardcoding the versions here is not ideal.
// We will need to determine a better way to fetch the last and latest versions dynamically.
Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseClusterConfigCustomVersion, databaseName, "pg", previousPGVersion),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDatabaseClusterExists(
"digitalocean_database_cluster.foobar", &database),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "name", databaseName),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "engine", "pg"),
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "version", previousPGVersion),
),
},
{
Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseClusterConfigCustomVersion, databaseName, "pg", latestPGVersion),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"digitalocean_database_cluster.foobar", "version", latestPGVersion),
),
},
},
})
}

func testAccCheckDigitalOceanDatabaseClusterDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*CombinedConfig).godoClient()

Expand Down Expand Up @@ -712,3 +749,13 @@ resource "digitalocean_database_cluster" "foobar" {
region = "nyc3"
node_count = 1
}`

const testAccCheckDigitalOceanDatabaseClusterConfigCustomVersion = `
resource "digitalocean_database_cluster" "foobar" {
name = "%s"
engine = "%s"
version = "%s"
size = "db-s-1vcpu-1gb"
region = "nyc3"
node_count = 1
}`
3 changes: 2 additions & 1 deletion docs/resources/database_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ The following arguments are supported:
* `size` - (Required) Database Droplet size associated with the cluster (ex. `db-s-1vcpu-1gb`). See here for a [list of valid size slugs](https://docs.digitalocean.com/reference/api/api-reference/#tag/Databases).
* `region` - (Required) DigitalOcean region where the cluster will reside.
* `node_count` - (Required) Number of nodes that will be included in the cluster.
* `version` - (Required) Engine version used by the cluster (ex. `11` for PostgreSQL 11).
* `version` - (Required) Engine version used by the cluster (ex. `14` for PostgreSQL 14).
When this value is changed, a call to the [Upgrade major Version for a Database](https://docs.digitalocean.com/reference/api/api-reference/#operation/databases_update_major_version) API operation is made with the new version.
* `tags` - (Optional) A list of tag names to be applied to the database cluster.
* `private_network_uuid` - (Optional) The ID of the VPC where the database cluster will be located.
* `eviction_policy` - (Optional) A string specifying the eviction policy for a Redis cluster. Valid values are: `noeviction`, `allkeys_lru`, `allkeys_random`, `volatile_lru`, `volatile_random`, or `volatile_ttl`.
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.92.0
github.com/digitalocean/godo v1.95.0
github.com/hashicorp/awspolicyequivalence v1.5.0
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/go-version v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,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.92.0 h1:eK9DgdLcjozZbywjh/9k2NF++ttbcidASOoCGRu48yQ=
github.com/digitalocean/godo v1.92.0/go.mod h1:NRpFznZFvhHjBoqZAaOD3khVzsJ3EibzKqFL4R60dmA=
github.com/digitalocean/godo v1.95.0 h1:S48/byPKui7RHZc1wYEPfRvkcEvToADNb5I3guu95xg=
github.com/digitalocean/godo v1.95.0/go.mod h1:NRpFznZFvhHjBoqZAaOD3khVzsJ3EibzKqFL4R60dmA=
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/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
15 changes: 14 additions & 1 deletion vendor/github.com/digitalocean/godo/CHANGELOG.md

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

104 changes: 83 additions & 21 deletions vendor/github.com/digitalocean/godo/databases.go

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

6 changes: 5 additions & 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.

Loading