-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Update MySQL to GA 2017-12-01 API #1154
Conversation
👍 sounds good |
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.
hey @jeffreyCline
Thanks for opening this PR :)
I've taken a look through and left some comments inline, but this is off to a good start. If we can fix up the comments and remove the new Postgres SDK for the moment, we should be able to look into how we handle the migration path.
Thanks!
azurerm/utils/utils.go
Outdated
|
||
// IntBetween returns a SchemaValidateFunc which tests if the provided value | ||
// is of type int and is between min and max (inclusive) and is divisible by a given number | ||
func IntBetweenDivisibleBy(min, max, divisor int) schema.SchemaValidateFunc { |
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.
can we make this an Internal/private function by changing the casing to intBetweenDivisibleBy
. Also can we move this into validators.go
since it's a validation function?
azurerm/resource_arm_mysql_server.go
Outdated
values := map[string]interface{}{} | ||
|
||
values["storage_mb"] = int(*resp.StorageMB) | ||
values["backup_retention_days"] = int(*resp.BackupRetentionDays) |
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.
can we add nil-checks around both of these, e.g.
if storageMB := resp.StorageMB; storageMB != nil {
values["storage_mb"] = int(*storageMB)
}
if backupRetentionDays := resp.BackupRetentionDays; backupRetentionDays != nil {
values["backup_retention_days"] = int(*backupRetentionDays)
}
azurerm/resource_arm_mysql_server.go
Outdated
@@ -343,7 +403,19 @@ func flattenMySQLServerSku(d *schema.ResourceData, resp *mysql.Sku) []interface{ | |||
values["name"] = *resp.Name | |||
values["capacity"] = int(*resp.Capacity) | |||
values["tier"] = string(resp.Tier) | |||
values["family"] = string(*resp.Family) |
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.
can we add nil-checks around the pointer accesses here? e.g.
if capacity := resp.Capacity; capacity != nil {
values["capacity"] = *capacity
}
(same for family) this helps to prevent cases where the Azure API isn't consistent
azurerm/resource_arm_mysql_server.go
Outdated
"storage_mb": { | ||
Type: schema.TypeInt, | ||
"storage_profile": { | ||
Type: schema.TypeSet, |
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.
Since there's only one item in this List and all items are returned - we should be able to make this a List rather than a Set, which gives a better UX. Looking at the code this should be a case of changing this from schema.TypeSet
-> schema.TypeList
and the accessor in expandMySQLStorageProfile
to:
func expandMySQLStorageProfile(d *schema.ResourceData) *mysql.StorageProfile {
storageprofiles := d.Get("storage_profile").([]interface{})
storageprofile := storageprofiles[0].(map[string]interface{})
# ..
}
"MO_Gen5_2", | ||
"MO_Gen5_4", | ||
"MO_Gen5_8", | ||
"MO_Gen5_16", |
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.
given this varies per region and changes fairly often - I'm going to suggest that we remove this for the moment? Alternatively we could swap this out for a regex, seeing as they appear to follow the format (B|GP|MO)_Gen(\d+)_(\d+)
- which looks good according to https://regex-golang.appspot.com/assets/html/index.html based on a few of the examples above?
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.
Right, but there are specific configurations that are only supported by certain tiers, take Memory Optimized(MO) for example... MO tiers can only be Gen5 family with between 2 and 16 vCores, with the regex it would allow for invalid configurations which would fail when apply was ran. If that is acceptable I would be happy to switch over to the regex, however I was under the impression that it was not so I went this route and forced only valid combinations to be entered into the schema. Let me know what 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.
Reflecting on this - given the responses from the API can be ambiguous, I think this is probably the right approach here 👍
@@ -50,34 +57,16 @@ The following arguments are supported: | |||
|
|||
* `sku` - (Required) A `sku` block as defined below. | |||
|
|||
* `storage_profile` - (Required) A `storage_profile` block as defined below. | |||
|
|||
* `create_mode` - (Optional) The mode to create a new server, supported values `Default` or `PointInTimeRestore`. |
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.
The mode to create a new server, supported values
Default
orPointInTimeRestore
.
For consistency purposes can we make this "The Creation Mode of the MySQL Server, used when restoring a database backup. Possible values include Default
and PointInTimeRestore
"
azurerm/resource_arm_mysql_server.go
Outdated
Required: false, | ||
Optional: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"Default", |
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.
since this is Optional - can we add a default value for this as "Default"?
* `name` - (Optional) Specifies the SKU Name for this MySQL Server. Possible values are: `MYSQLB50`, `MYSQLB100`, `MYSQLS100`, `MYSQLS200`, `MYSQLS400` and `MYSQLS800`. | ||
* `capacity` - (Optional) Specifies the DTU's for this MySQL Server. Possible values are `50` and `100` DTU's when using a `Basic` SKU and `100`, `200`, `400` or `800` when using the `Standard` SKU. | ||
* `tier` - (Optional) Specifies the SKU Tier for this MySQL Server. Possible values are `Basic` and `Standard`. | ||
* `name` - (Required) Specifies the SKU Name for this MySQL Server. See the `name` values by `tier` and `capacity` table below for valid values. |
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.
since there's a much larger set now I'm going to suggest we remove this in favour of linking to the product page for more info - as such can we remove "See the name
values by tier
and capacity
table below for valid values."?
* `capacity` - (Optional) Specifies the DTU's for this MySQL Server. Possible values are `50` and `100` DTU's when using a `Basic` SKU and `100`, `200`, `400` or `800` when using the `Standard` SKU. | ||
* `tier` - (Optional) Specifies the SKU Tier for this MySQL Server. Possible values are `Basic` and `Standard`. | ||
* `name` - (Required) Specifies the SKU Name for this MySQL Server. See the `name` values by `tier` and `capacity` table below for valid values. | ||
* `capacity` - (Required) The scale up/out capacity, representing server's compute units. Valid values depends on the `tier` of the server. See the `name` values by `tier` and `capacity` table below for valid values. |
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.
since there's a much larger set now I'm going to suggest we remove this in favour of linking to the product page for more info - as such can we remove "See the name
values by tier
and capacity
table below for valid values."?
`Gen5` (Intel E5-2673 v4 (Broadwell) 2.3 GHz processors). | ||
|
||
|
||
Suported `name` values by `tier` and `capacity`: |
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.
(as such can we remove this and the tables below)
@jeffreyCline please revert all the new files under $azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql, this PR does not have any reference to this new package, it's only for MySQL. |
* `name` - (Optional) Specifies the SKU Name for this MySQL Server. Possible values are: `MYSQLB50`, `MYSQLB100`, `MYSQLS100`, `MYSQLS200`, `MYSQLS400` and `MYSQLS800`. | ||
* `capacity` - (Optional) Specifies the DTU's for this MySQL Server. Possible values are `50` and `100` DTU's when using a `Basic` SKU and `100`, `200`, `400` or `800` when using the `Standard` SKU. | ||
* `tier` - (Optional) Specifies the SKU Tier for this MySQL Server. Possible values are `Basic` and `Standard`. | ||
* `name` - (Required) Specifies the SKU Name for this MySQL Server. The name of the SKU, follows the `tier` + `family` + `cores` pattern (e.g. B_Gen4_1, GP_Gen5_8). For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/mysql/servers/create#sku). |
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.
What's the impact for old MySQL resource provisioned by old schema? Any migration work if upgrade to future new provider?
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.
None, it is a no op for the end user. Please see the Migration Results.
Issues have been fixed.
@@ -42,12 +41,24 @@ func resourceArmMySqlServer() *schema.Resource { | |||
Type: schema.TypeString, | |||
Required: true, | |||
ValidateFunc: validation.StringInSlice([]string{ |
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.
I still want to remove the duplications here because all the information are expressed in other fields already.
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.
Maybe in a future release, right now this is a direct import of the schema.
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.
Hey @jeffreyCline
Apologies for the delay re-reviewing this - this mostly LGTM now, if we can remove the create_mode
field for the moment (until the reset of the properties are exposed) I think we should be good to re-test this 👍
Thanks!
"MO_Gen5_2", | ||
"MO_Gen5_4", | ||
"MO_Gen5_8", | ||
"MO_Gen5_16", |
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.
Reflecting on this - given the responses from the API can be ambiguous, I think this is probably the right approach here 👍
Version: mysql.ServerVersion(version), | ||
SslEnforcement: mysql.SslEnforcementEnum(sslEnforcement), | ||
StorageProfile: storageprofile, | ||
CreateMode: mysql.CreateMode(createMode), |
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.
given we don't support the additional properties needed for importing from a Backup at this time - I think it's best we remove the schema field & default this to Default
for the moment?
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.
Removed CreateMode property and default to default.
azurerm/resource_arm_mysql_server.go
Outdated
values["geo_redundant_backup"] = mysql.GeoRedundantBackup(resp.GeoRedundantBackup) | ||
|
||
storageprofile := []interface{}{values} | ||
return storageprofile |
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.
minor / FYI for the future you can just return []interface{}{values}
directly here :)
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.
Thanks for pushing those changes - this now LGTM. I've also tested the migration path and can confirm this looks good 👍
Thanks!
Minor fixes to make the spacing consistent for sub-resources
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
Upgrade the MySQL resource the adopt the GA API 2017-12-01. This PR will resolve issue #1004 .