-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data source
azurerm_mssql_server
and new block `restorable_drop…
…ped_databases` in `azuerrm_mssql_server` (#7917) Fix #6502 #7594 === RUN TestAccAzureRMMsSqlDatabase_createRestoreMode === PAUSE TestAccAzureRMMsSqlDatabase_createRestoreMode === CONT TestAccAzureRMMsSqlDatabase_createRestoreMode --- PASS: TestAccAzureRMMsSqlDatabase_createRestoreMode (2016.02s) Sql server listing recoverableDatabases Api has problems, thus it's excluded in the PR: Azure/azure-rest-api-specs#10162
- Loading branch information
Showing
14 changed files
with
766 additions
and
6 deletions.
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
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
126 changes: 126 additions & 0 deletions
126
azurerm/internal/services/mssql/mssql_server_data_source.go
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 |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package mssql | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceMsSqlServer() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmMsSqlServerRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"administrator_login": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"fully_qualified_domain_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"identity": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"principal_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tenant_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"restorable_dropped_database_ids": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"tags": tags.SchemaDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmMsSqlServerRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).MSSQL.ServersClient | ||
restorableDroppedDatabasesClient := meta.(*clients.Client).MSSQL.RestorableDroppedDatabasesClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("sql Server %q was not found in Resource Group %q", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("retrieving Sql Server %q (Resource Group %q): %s", name, resourceGroup, err) | ||
} | ||
|
||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("reading Ms Sql Server %q (Resource Group %q) ID is empty or nil", name, resourceGroup) | ||
} | ||
d.SetId(*resp.ID) | ||
d.Set("location", location.NormalizeNilable(resp.Location)) | ||
|
||
if props := resp.ServerProperties; props != nil { | ||
d.Set("version", props.Version) | ||
d.Set("administrator_login", props.AdministratorLogin) | ||
d.Set("fully_qualified_domain_name", props.FullyQualifiedDomainName) | ||
} | ||
|
||
if err := d.Set("identity", flattenAzureRmSqlServerIdentity(resp.Identity)); err != nil { | ||
return fmt.Errorf("setting `identity`: %+v", err) | ||
} | ||
|
||
restorableResp, err := restorableDroppedDatabasesClient.ListByServer(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("listing SQL Server %s Restorable Dropped Databases: %v", name, err) | ||
} | ||
if err := d.Set("restorable_dropped_database_ids", flattenAzureRmSqlServerRestorableDatabases(restorableResp)); err != nil { | ||
return fmt.Errorf("setting `restorable_dropped_database_ids`: %+v", err) | ||
} | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} |
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
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
Oops, something went wrong.