-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9d878b2
Merge remote-tracking branch 'upstream/master'
hbuckle e552a59
add database_import property
hbuckle e18d160
add option to import database from bacpac
hbuckle 3c6cdc2
Merge remote-tracking branch 'upstream/master' into sqldbimport
1ba3169
PR tweaks
hbuckle e3b9a4e
rename database_import to import
hbuckle a933a98
Merge remote-tracking branch 'upstream/master' into sqldbimport
hbuckle a4159d0
add acc test
hbuckle 06301da
Merge remote-tracking branch 'upstream/master' into sqldbimport
hbuckle 4c7ae1b
Handling case-insensitivity
tombuildsstuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,61 @@ 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), | ||
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | ||
}, | ||
"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{ | ||
"ADPassword", | ||
"SQL", | ||
}, true), | ||
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | ||
}, | ||
"operation_mode": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "Import", | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"Import", | ||
}, true), | ||
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"source_database_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -238,6 +294,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 +433,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)), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)