-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_sql_database
- support for importing from bacpac
#972
Conversation
azurerm/resource_arm_sql_database.go
Outdated
@@ -237,6 +285,27 @@ func resourceArmSqlDatabaseCreateUpdate(d *schema.ResourceData, meta interface{} | |||
return err | |||
} | |||
|
|||
if _, ok := d.GetOk("database_import"); ok { | |||
if !strings.EqualFold(createMode, "default") { | |||
return fmt.Errorf("database_import can only be used when create_mode is 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.
@hbuckle Should this error be a validation on the database_import
property instead? Otherwise, you could be running your scripts and end up with the error during a deployment instead of when generating the plan? Or possibly use ConflictsWith: ["create_mode"]
on the database_import
since the default for create_mode
is default
(and its required to be 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.
@vlouwagie ideally yes, however unfortunately the validation API's only expose a single property at this point; as such unfortunately I don't think that's feasible at this time
azurerm/resource_arm_sql_database.go
Outdated
"SQL", "ADPassword", | ||
}, true), | ||
}, | ||
"operation_mode": { |
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.
@hbuckle If there is only one value, does this need to be required?
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.
+1 - we should be able to make this Optional with a Default value instead :)
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 @hbuckle
Thanks for this PR :) apologies for the delayed review here!
I've taken a look through and left some comments in-line, but the main thing missing here is an acceptance test covering this functionality. I believe it should be possible to spin up a DB, take a backup and them import that into a new DB all via the API to create the test rather than caching a file somewhere perminantly - what do you think?
Thanks!
azurerm/resource_arm_sql_database.go
Outdated
"SQL", "ADPassword", | ||
}, true), | ||
}, | ||
"operation_mode": { |
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.
+1 - we should be able to make this Optional with a Default value instead :)
azurerm/resource_arm_sql_database.go
Outdated
@@ -57,6 +58,53 @@ func resourceArmSqlDatabase() *schema.Resource { | |||
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | |||
}, | |||
|
|||
"database_import": { |
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 think it might be worth renaming this to import
- what do you think?
azurerm/resource_arm_sql_database.go
Outdated
}, | ||
"administrator_login_password": { | ||
Type: schema.TypeString, | ||
Required: true, |
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 Sensitive: true
here?
azurerm/resource_arm_sql_database.go
Outdated
}, | ||
"storage_key": { | ||
Type: schema.TypeString, | ||
Required: true, |
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 Sensitive: true
here?
azurerm/resource_arm_sql_database.go
Outdated
@@ -237,6 +285,27 @@ func resourceArmSqlDatabaseCreateUpdate(d *schema.ResourceData, meta interface{} | |||
return err | |||
} | |||
|
|||
if _, ok := d.GetOk("database_import"); ok { | |||
if !strings.EqualFold(createMode, "default") { | |||
return fmt.Errorf("database_import can only be used when create_mode is 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.
@vlouwagie ideally yes, however unfortunately the validation API's only expose a single property at this point; as such unfortunately I don't think that's feasible at this time
// this is set in config.go, but something sets | ||
// it back to 15 minutes, which isn't long enough | ||
// for most imports | ||
client.Client.PollingDuration = 60 * time.Minute |
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.
from what I recall the 15 minute reset is pulled from the API's retry interval recommendation * the number of retries allowed - I've been meaning to investigate this further
@tombuildsstuff RE the acceptance test, using the Azure portal I created a new blank database, exported it to a bacpac in a storage account and then imported it into a second new database. However the import fails with the error "Archive file cannot be size 0" so I think we need a way to get some data into the database. Do you know a way to do this using the API ? |
@hbuckle sorry I'd missed your comment about the AdventureWorks bacpac, I guess we can place that somewhere and restore it? Let me reach out internally to see where's best to do that, but we should be able to upload it to blob storage from wherever it's hosted and then restore it as needed :) |
@tombuildsstuff Yes I think we basically just need a long lived storage account to do the restore from. Let me know if you have one available. |
Actually I have just seen the azurerm_storage_blob resource can upload a local file to storage, so I can include a bacpac in the testdata folder. I'll go down that route |
@tombuildsstuff my only concern is that requires connecting directly to the DB, which probably won't work if you are behind a corporate firewall. I can make a bacpac that is much smaller than adventureworks, only a few kb and include that? |
@hbuckle after chatting internally as long as it's a small file (e.g. a couple hundred KB) this should be fine - we were mostly concerned about large binary files :) |
@tombuildsstuff Acceptance test added
|
@tombuildsstuff anything more you need from me on this one? |
@hbuckle apologies for the delay, I've been out for a few weeks - I'm taking a look at this now :) |
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 @hbuckle
Thanks for pushing those updates - apologies on the delayed re-review of this. I've taken a look through and left a couple of minor comments in-line for which I'll push a commit to fix, but this otherwise LGTM - thanks for this!
Thanks!
azurerm/resource_arm_sql_database.go
Outdated
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"StorageAccessKey", "SharedAccessKey", | ||
}, true), |
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 true
represents the strings being case-insensitive; as such can we also add DiffSuppressFunc: ignoreCaseDiffSuppressFunc
here to handle the casing being different?
Default: "Import", | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"Import", | ||
}, true), |
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.
(same here)
azurerm_sql_database
- support for importing from bacpac
azurerm_sql_database
- support for importing from bacpac
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! |
Add ability to import a database from a bacpac (https://docs.microsoft.com/en-us/azure/sql-database/sql-database-import)
I can't see any way to add a test for this one because it needs a bacpac file in a storage account somewhere.
I've tested it using an AdventureWorks bacpac (https://s3-eu-west-1.amazonaws.com/resourcescrono/AdventureWorks2014FullForAzure.bacpac)