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

Update MySQL to GA 2017-12-01 API #1154

Merged
merged 32 commits into from
May 22, 2018
Merged

Update MySQL to GA 2017-12-01 API #1154

merged 32 commits into from
May 22, 2018

Conversation

WodansSon
Copy link
Collaborator

@WodansSon WodansSon commented Apr 24, 2018

Upgrade the MySQL resource the adopt the GA API 2017-12-01. This PR will resolve issue #1004 .

@tombuildsstuff
Copy link
Contributor

Due to an issue with the PostGreSQL API I am going to do this in two parts. First MySQL and then PostGreSQL once the API is fixed.

👍 sounds good

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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!


// 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 {
Copy link
Contributor

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?

values := map[string]interface{}{}

values["storage_mb"] = int(*resp.StorageMB)
values["backup_retention_days"] = int(*resp.BackupRetentionDays)
Copy link
Contributor

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)
}

@@ -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)
Copy link
Contributor

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

"storage_mb": {
Type: schema.TypeInt,
"storage_profile": {
Type: schema.TypeSet,
Copy link
Contributor

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",
Copy link
Contributor

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?

Copy link
Collaborator Author

@WodansSon WodansSon Apr 24, 2018

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.

Copy link
Contributor

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`.
Copy link
Contributor

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 or PointInTimeRestore.

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"

Required: false,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Default",
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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`:
Copy link
Contributor

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)

@metacpp
Copy link
Contributor

metacpp commented May 2, 2018

@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).
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

@metacpp metacpp changed the title Updated MySQL to use new pricing tier Update MySQL to GA 2017-12-01 API May 3, 2018
@WodansSon WodansSon dismissed stale reviews from metacpp and tombuildsstuff May 4, 2018 17:37

Issues have been fixed.

@@ -42,12 +41,24 @@ func resourceArmMySqlServer() *schema.Resource {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
Copy link

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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",
Copy link
Contributor

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),
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

values["geo_redundant_backup"] = mysql.GeoRedundantBackup(resp.GeoRedundantBackup)

storageprofile := []interface{}{values}
return storageprofile
Copy link
Contributor

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 :)

@WodansSon WodansSon requested a review from katbyte May 17, 2018 04:18
@WodansSon WodansSon dismissed tombuildsstuff’s stale review May 17, 2018 04:19

Fixed Issues raised by review.

@tombuildsstuff tombuildsstuff modified the milestones: Soon, 1.6.0 May 22, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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
@tombuildsstuff
Copy link
Contributor

Pushed one minor commit to fix the spacing in the docs to match the other sub-resources - but this now LGTM and the tests pass - thanks for this!

screen shot 2018-05-22 at 16 09 18

@tombuildsstuff tombuildsstuff merged commit 7f485f0 into master May 22, 2018
@tombuildsstuff tombuildsstuff deleted the u-mysql-postgresql branch May 22, 2018 16:04
tombuildsstuff added a commit that referenced this pull request May 22, 2018
@ghost
Copy link

ghost commented Mar 31, 2020

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!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants