-
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
Changes from 9 commits
9d878b2
e552a59
e18d160
3c6cdc2
1ba3169
e3b9a4e
a933a98
a4159d0
06301da
4c7ae1b
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ package azurerm | |
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/sql/mgmt/2015-05-01-preview/sql" | ||
|
@@ -57,6 +58,56 @@ func resourceArmSqlDatabase() *schema.Resource { | |
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | ||
}, | ||
|
||
"import": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"storage_uri": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"storage_key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Sensitive: true, | ||
}, | ||
"storage_key_type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"StorageAccessKey", "SharedAccessKey", | ||
}, true), | ||
}, | ||
"administrator_login": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"administrator_login_password": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Sensitive: true, | ||
}, | ||
"authentication_type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"SQL", "ADPassword", | ||
}, true), | ||
}, | ||
"operation_mode": { | ||
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. @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 commentThe 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 :) |
||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "Import", | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"Import", | ||
}, 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. (same here) |
||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"source_database_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -238,6 +289,27 @@ func resourceArmSqlDatabaseCreateUpdate(d *schema.ResourceData, meta interface{} | |
return err | ||
} | ||
|
||
if _, ok := d.GetOk("import"); ok { | ||
if !strings.EqualFold(createMode, "default") { | ||
return fmt.Errorf("import can only be used when create_mode is Default") | ||
} | ||
importParameters := expandAzureRmSqlDatabaseImport(d) | ||
importFuture, err := client.CreateImportOperation(ctx, resourceGroup, serverName, name, importParameters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// 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 commentThe 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 |
||
|
||
err = importFuture.WaitForCompletion(ctx, client.Client) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
resp, err := client.Get(ctx, resourceGroup, serverName, name, "") | ||
if err != nil { | ||
return err | ||
|
@@ -356,3 +428,21 @@ func flattenEncryptionStatus(encryption *[]sql.TransparentDataEncryption) string | |
|
||
return "" | ||
} | ||
|
||
func expandAzureRmSqlDatabaseImport(d *schema.ResourceData) sql.ImportExtensionRequest { | ||
v := d.Get("import") | ||
dbimportRefs := v.([]interface{}) | ||
dbimportRef := dbimportRefs[0].(map[string]interface{}) | ||
return sql.ImportExtensionRequest{ | ||
Name: utils.String("terraform"), | ||
ImportExtensionProperties: &sql.ImportExtensionProperties{ | ||
StorageKeyType: sql.StorageKeyType(dbimportRef["storage_key_type"].(string)), | ||
StorageKey: utils.String(dbimportRef["storage_key"].(string)), | ||
StorageURI: utils.String(dbimportRef["storage_uri"].(string)), | ||
AdministratorLogin: utils.String(dbimportRef["administrator_login"].(string)), | ||
AdministratorLoginPassword: utils.String(dbimportRef["administrator_login_password"].(string)), | ||
AuthenticationType: sql.AuthenticationType(dbimportRef["authentication_type"].(string)), | ||
OperationMode: utils.String(dbimportRef["operation_mode"].(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.
this
true
represents the strings being case-insensitive; as such can we also addDiffSuppressFunc: ignoreCaseDiffSuppressFunc
here to handle the casing being different?