-
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 resource
azurerm_synapse_sql_pool
(#8095)
the third resource of #7406 it needs to take a long time to run test for PointInTime restore (8h according to the doc) and recovery (1 day), so I don't add test case for these two create mode. I have tested it offline and there is no problem
- Loading branch information
Showing
14 changed files
with
1,149 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type SqlDatabaseId struct { | ||
ResourceGroup string | ||
ServerName string | ||
Name string | ||
} | ||
|
||
func NewSqlDatabaseID(resourceGroup, serverName, name string) SqlDatabaseId { | ||
return SqlDatabaseId{ | ||
ResourceGroup: resourceGroup, | ||
ServerName: serverName, | ||
Name: name, | ||
} | ||
} | ||
|
||
func (id SqlDatabaseId) ID(subscriptionId string) string { | ||
return fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s", subscriptionId, id.ResourceGroup, id.ServerName, id.Name) | ||
} | ||
|
||
func SqlDatabaseID(input string) (*SqlDatabaseId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Synapse Sql Pool ID %q: %+v", input, err) | ||
} | ||
|
||
sqlDatabaseId := SqlDatabaseId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
if sqlDatabaseId.ServerName, err = id.PopSegment("servers"); err != nil { | ||
return nil, err | ||
} | ||
if sqlDatabaseId.Name, err = id.PopSegment("databases"); err != nil { | ||
return nil, err | ||
} | ||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &sqlDatabaseId, nil | ||
} |
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,88 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/resourceid" | ||
) | ||
|
||
var _ resourceid.Formatter = SqlDatabaseId{} | ||
|
||
func TestSqlDatabaseId(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *SqlDatabaseId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing servers Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Sql Servers ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing databases Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1/databases", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Sql Database ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1/databases/db1", | ||
Expected: &SqlDatabaseId{ | ||
Name: "db1", | ||
ServerName: "server1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1/Databases/db1", | ||
Expected: nil, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := SqlDatabaseID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/sql/parse" | ||
) | ||
|
||
func SqlDatabaseID(i interface{}, k string) (warnings []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
if _, err := parse.SqlDatabaseID(v); err != nil { | ||
errors = append(errors, fmt.Errorf("can not parse %q as a Sql Database resource id: %v", k, err)) | ||
return | ||
} | ||
|
||
return warnings, errors | ||
} |
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
37 changes: 37 additions & 0 deletions
37
azurerm/internal/services/synapse/parse/synapse_sql_pool.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,37 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type SynapseSqlPoolId struct { | ||
Workspace *SynapseWorkspaceId | ||
Name string | ||
} | ||
|
||
func SynapseSqlPoolID(input string) (*SynapseSqlPoolId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Synapse Sql Pool ID %q: %+v", input, err) | ||
} | ||
|
||
synapseSqlPool := SynapseSqlPoolId{ | ||
Workspace: &SynapseWorkspaceId{ | ||
SubscriptionID: id.SubscriptionID, | ||
ResourceGroup: id.ResourceGroup, | ||
}, | ||
} | ||
if synapseSqlPool.Workspace.Name, err = id.PopSegment("workspaces"); err != nil { | ||
return nil, err | ||
} | ||
if synapseSqlPool.Name, err = id.PopSegment("sqlPools"); err != nil { | ||
return nil, err | ||
} | ||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &synapseSqlPool, nil | ||
} |
Oops, something went wrong.