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

resource_arm_sql_database: switch dependency from riviera to azure-sdk-for-go #191

Closed
wants to merge 2 commits into from
Closed

resource_arm_sql_database: switch dependency from riviera to azure-sdk-for-go #191

wants to merge 2 commits into from

Conversation

sebastus
Copy link
Contributor

No description provided.

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 @sebastus

Thanks for this PR - apologies for the delayed review on this, I'd started reviewed it but not hit submit :(

I've taken a look through and left some comments but this is off to a good start :)

Thanks!

Default: "Default",
Type: schema.TypeString,
Optional: true,
Default: "Default",
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 use the enum in the SDK for this? i.e. string(sql.Default)

Type: schema.TypeString,
Optional: true,
Default: "Default",
ValidateFunc: validateArmSqlDatabaseCreateMode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to remove this in favour of an in-line validation function:

ValidateFunc: validation.StringInSlice([]string{
  string(sql.Copy),
  string(sql.RestoreLongTermRetentionBackup),
  string(sql.Default),
  string(sql.NonReadableSecondary),
  string(sql.OnlineSecondary),
  string(sql.PointInTimeRestore),
  string(sql.Recovery),
  string(sql.Restore),
  string(sql.RestoreLongTermRetentionBackup),
}, true)

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 a reference to the DiffSuppressFunc which will ignore differences in case here:

DiffSuppressFunc: ignoreCaseDiffSuppressFunc,

if v, ok := d.GetOk("collation"); ok {
command.Collation = azure.String(v.(string))
}
edition := sql.DatabaseEdition(d.Get("edition").(string))
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 field is optional, I think we want to optionally assign it to props below? i.e.

if v, ok := d.GetOk("edition"); ok {
  props.Edition = sql.DatabaseEdition(v.(string))
}

requestedServiceObjectiveNameString := d.Get("requested_service_objective_name").(string)
var requestedServiceObjectiveName sql.ServiceObjectiveName

if requestedServiceObjectiveIDString != "" && requestedServiceObjectiveNameString == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use the conflicts_with option in the Schema to handle this for us automatically, i.e.:

"requested_service_objective_id": {
    Type:     schema.TypeString,
    Optional: true,
    Computed: true,
    ConflictsWith: []string{ "requested_service_objective_name" },
},
 
"requested_service_objective_name": {
    Type:     schema.TypeString,
    Optional: true,
    Computed: true,
    ConflictsWith: []string{ "requested_service_objective_id" },
},

and then just have if statements for each field, and assign the value directly to props as needed, rather than checking the state of both:

if v, ok := d.Get("requested_service_objective_id").(string); ok {
  rsoid, err := uuid.FromString(v.(string))
   if err != nil {
     return err
  }
  props.RequestedServiceObjectiveID  = &rsoid
}

if v, ok := d.Get("requested_service_objective_name").(string); ok {
  props.RequestedServiceObjectiveID  = sql.ServiceObjectiveName(v.(string))
}

createResponse, err := createRequest.Execute()
if err != nil {
return fmt.Errorf("Error creating SQL Database: %s", err)
if requestedServiceObjectiveNameString == "ElasticPool" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an enum/constant we can use for this?

databaseName := id.Path["databases"]

result, error := sqlDatabasesClient.Delete(resGroup, serverName, databaseName)
if result.Response.StatusCode != http.StatusOK {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -257,3 +287,20 @@ func validateArmSqlDatabaseEdition(v interface{}, k string) (ws []string, errors
}
return
}

func validateArmSqlDatabaseCreateMode(v interface{}, k string) (ws []string, errors []error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(if we switch to using the validation.StringInStrings and the enum's/constants above - I think we can remove this?)

if !readResponse.IsSuccessful() {
return fmt.Errorf("Bad: GetDatabase: %s", readResponse.Error)

if resp.StatusCode == http.StatusNotFound {
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 update this to be within the err statement above, as 404 should be being returned as an error

if err != nil {
return fmt.Errorf("Bad: GetDatabase: %s", err)
return nil
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 update this to return the error, and add a check for if 404 { return nil } - given a 404 is an error type?


for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_sql_database" {
if rs.Type != "azurerm_sql_database_record" {
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 change this back to azurerm_sql_database, given that's the resource name?

@tombuildsstuff
Copy link
Contributor

Hey @sebastus

I've been working on a similar task which requires the Riviera SDK to be removed - as such I've rolled your PR's (#191 #190 and #178) into a new PR - which also removes the bulk of the Riviera SDK; I hope you don't mind (and we really appreciate your efforts here) - and this is visible in #289.

As such I'm going to close this PR for the moment in favour of #289.

Thanks!

@ghost
Copy link

ghost commented Apr 1, 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 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 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.

3 participants