-
Notifications
You must be signed in to change notification settings - Fork 132
Rdb: Allow RDB instance upgrade to HA without replacing the resource #518
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
Changes from all commits
3c72261
5128fb6
f5bf723
1b6696f
07ff615
0422c04
5a8aea5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package scaleway | |
|
||
import ( | ||
"io/ioutil" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1" | ||
|
@@ -39,7 +40,6 @@ func resourceScalewayRdbInstanceBeta() *schema.Resource { | |
"is_ha_cluster": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
ForceNew: true, | ||
Default: false, | ||
Description: "Enable or disable high availability for the database instance", | ||
}, | ||
|
@@ -52,11 +52,13 @@ func resourceScalewayRdbInstanceBeta() *schema.Resource { | |
"user_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imho we should add a separate user resource, and if db creation with no user is not on the table, we should at least handle the update here, not a new resource There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that splitting the user to a separate resource makes more sens in TF. This would imply allowing the creation of the database without any user in the API or silently deleting it in the TF create There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am planning on adding a separate user resource in an upcoming PR. I am concerned about allowing user changes in the instance resource as it could potentially conflict with definition in the user resource. For example in this template definition (after adding a user object):
We don’t want to have a confusion on which password is used, so I want to set the expectation that the password in the user definition "always win", which is only possible if we don’t allow updates on the instance resource. As such the user password is always updated to the user object definition after the instance is created. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the PR to add a specific resource for database users #520 |
||
Description: "Identifier for the first user of the database instance", | ||
}, | ||
"password": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Sensitive: true, | ||
Description: "Password for the first user of the database instance", | ||
}, | ||
"tags": { | ||
|
@@ -234,13 +236,26 @@ func resourceScalewayRdbInstanceBetaUpdate(d *schema.ResourceData, m interface{} | |
if err != nil { | ||
return err | ||
} | ||
|
||
upgradeInstanceRequests := []rdb.UpgradeInstanceRequest(nil) | ||
if d.HasChange("node_type") { | ||
_, err = rdbAPI.UpgradeInstance(&rdb.UpgradeInstanceRequest{ | ||
Region: region, | ||
InstanceID: ID, | ||
NodeType: scw.StringPtr(d.Get("node_type").(string)), | ||
}) | ||
upgradeInstanceRequests = append(upgradeInstanceRequests, | ||
rdb.UpgradeInstanceRequest{ | ||
Region: region, | ||
InstanceID: ID, | ||
NodeType: scw.StringPtr(d.Get("node_type").(string)), | ||
}) | ||
} | ||
|
||
if d.HasChange("is_ha_cluster") { | ||
upgradeInstanceRequests = append(upgradeInstanceRequests, | ||
rdb.UpgradeInstanceRequest{ | ||
Region: region, | ||
InstanceID: ID, | ||
EnableHa: scw.BoolPtr(d.Get("is_ha_cluster").(bool)), | ||
}) | ||
} | ||
for _, request := range upgradeInstanceRequests { | ||
_, err = rdbAPI.UpgradeInstance(&request) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -253,7 +268,26 @@ func resourceScalewayRdbInstanceBetaUpdate(d *schema.ResourceData, m interface{} | |
if err != nil { | ||
return err | ||
} | ||
|
||
// Wait for the instance to settle after upgrading | ||
time.Sleep(30 * time.Second) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What issue did you encounter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an issue on RDB side. I will remove this when it is resolved. |
||
|
||
} | ||
|
||
if d.HasChange("password") { | ||
req := &rdb.UpdateUserRequest{ | ||
Region: region, | ||
InstanceID: ID, | ||
Name: d.Get("user_name").(string), | ||
Password: scw.StringPtr(d.Get("password").(string)), | ||
} | ||
|
||
_, err = rdbAPI.UpdateUser(req) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return resourceScalewayRdbInstanceBetaRead(d, m) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is out of this MR but when reading it this field name seems strange, IMHO
enable_ha_cluster
would make more sense don't you think ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make more sense indeed. is_ha_cluster is what is being used currently in the CreateInstance API.
So I am balancing using a better name vs keeping the attribute name in sync with the API and dealing with renaming an attribute without breaking compatibility.
I am more inclined to keep it as is for now, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it makes more sense to write
enable_ha_cluster = true
in the HCL:is_ha_cluster
is the read only name of the property through the API, whereasenable_ha_cluster
is an actionnable attribute in the terraform config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I'll update this in a separate PR.