-
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_extended_auditing_policy
and…
… `azurerm_synapse_workspace_extended_auditing_policy` (#12952)
- Loading branch information
1 parent
68614fb
commit 7f7aad2
Showing
17 changed files
with
2,366 additions
and
20 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
81 changes: 81 additions & 0 deletions
81
internal/services/synapse/parse/sql_pool_extended_auditing_policy.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,81 @@ | ||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure" | ||
) | ||
|
||
type SqlPoolExtendedAuditingPolicyId struct { | ||
SubscriptionId string | ||
ResourceGroup string | ||
WorkspaceName string | ||
SqlPoolName string | ||
ExtendedAuditingSettingName string | ||
} | ||
|
||
func NewSqlPoolExtendedAuditingPolicyID(subscriptionId, resourceGroup, workspaceName, sqlPoolName, extendedAuditingSettingName string) SqlPoolExtendedAuditingPolicyId { | ||
return SqlPoolExtendedAuditingPolicyId{ | ||
SubscriptionId: subscriptionId, | ||
ResourceGroup: resourceGroup, | ||
WorkspaceName: workspaceName, | ||
SqlPoolName: sqlPoolName, | ||
ExtendedAuditingSettingName: extendedAuditingSettingName, | ||
} | ||
} | ||
|
||
func (id SqlPoolExtendedAuditingPolicyId) String() string { | ||
segments := []string{ | ||
fmt.Sprintf("Extended Auditing Setting Name %q", id.ExtendedAuditingSettingName), | ||
fmt.Sprintf("Sql Pool Name %q", id.SqlPoolName), | ||
fmt.Sprintf("Workspace Name %q", id.WorkspaceName), | ||
fmt.Sprintf("Resource Group %q", id.ResourceGroup), | ||
} | ||
segmentsStr := strings.Join(segments, " / ") | ||
return fmt.Sprintf("%s: (%s)", "Sql Pool Extended Auditing Policy", segmentsStr) | ||
} | ||
|
||
func (id SqlPoolExtendedAuditingPolicyId) ID() string { | ||
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/extendedAuditingSettings/%s" | ||
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, id.SqlPoolName, id.ExtendedAuditingSettingName) | ||
} | ||
|
||
// SqlPoolExtendedAuditingPolicyID parses a SqlPoolExtendedAuditingPolicy ID into an SqlPoolExtendedAuditingPolicyId struct | ||
func SqlPoolExtendedAuditingPolicyID(input string) (*SqlPoolExtendedAuditingPolicyId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resourceId := SqlPoolExtendedAuditingPolicyId{ | ||
SubscriptionId: id.SubscriptionID, | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if resourceId.SubscriptionId == "" { | ||
return nil, fmt.Errorf("ID was missing the 'subscriptions' element") | ||
} | ||
|
||
if resourceId.ResourceGroup == "" { | ||
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") | ||
} | ||
|
||
if resourceId.WorkspaceName, err = id.PopSegment("workspaces"); err != nil { | ||
return nil, err | ||
} | ||
if resourceId.SqlPoolName, err = id.PopSegment("sqlPools"); err != nil { | ||
return nil, err | ||
} | ||
if resourceId.ExtendedAuditingSettingName, err = id.PopSegment("extendedAuditingSettings"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &resourceId, nil | ||
} |
144 changes: 144 additions & 0 deletions
144
internal/services/synapse/parse/sql_pool_extended_auditing_policy_test.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,144 @@ | ||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/resourceid" | ||
) | ||
|
||
var _ resourceid.Formatter = SqlPoolExtendedAuditingPolicyId{} | ||
|
||
func TestSqlPoolExtendedAuditingPolicyIDFormatter(t *testing.T) { | ||
actual := NewSqlPoolExtendedAuditingPolicyID("12345678-1234-9876-4563-123456789012", "resGroup1", "workspace1", "sqlPool1", "default").ID() | ||
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/sqlPools/sqlPool1/extendedAuditingSettings/default" | ||
if actual != expected { | ||
t.Fatalf("Expected %q but got %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestSqlPoolExtendedAuditingPolicyID(t *testing.T) { | ||
testData := []struct { | ||
Input string | ||
Error bool | ||
Expected *SqlPoolExtendedAuditingPolicyId | ||
}{ | ||
|
||
{ | ||
// empty | ||
Input: "", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing SubscriptionId | ||
Input: "/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for SubscriptionId | ||
Input: "/subscriptions/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing WorkspaceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for WorkspaceName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing SqlPoolName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for SqlPoolName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/sqlPools/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing ExtendedAuditingSettingName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/sqlPools/sqlPool1/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for ExtendedAuditingSettingName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/sqlPools/sqlPool1/extendedAuditingSettings/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// valid | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Synapse/workspaces/workspace1/sqlPools/sqlPool1/extendedAuditingSettings/default", | ||
Expected: &SqlPoolExtendedAuditingPolicyId{ | ||
SubscriptionId: "12345678-1234-9876-4563-123456789012", | ||
ResourceGroup: "resGroup1", | ||
WorkspaceName: "workspace1", | ||
SqlPoolName: "sqlPool1", | ||
ExtendedAuditingSettingName: "default", | ||
}, | ||
}, | ||
|
||
{ | ||
// upper-cased | ||
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.SYNAPSE/WORKSPACES/WORKSPACE1/SQLPOOLS/SQLPOOL1/EXTENDEDAUDITINGSETTINGS/DEFAULT", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Input) | ||
|
||
actual, err := SqlPoolExtendedAuditingPolicyID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expect a value but got an error: %s", err) | ||
} | ||
if v.Error { | ||
t.Fatal("Expect an error but didn't get one") | ||
} | ||
|
||
if actual.SubscriptionId != v.Expected.SubscriptionId { | ||
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) | ||
} | ||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
if actual.WorkspaceName != v.Expected.WorkspaceName { | ||
t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) | ||
} | ||
if actual.SqlPoolName != v.Expected.SqlPoolName { | ||
t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) | ||
} | ||
if actual.ExtendedAuditingSettingName != v.Expected.ExtendedAuditingSettingName { | ||
t.Fatalf("Expected %q but got %q for ExtendedAuditingSettingName", v.Expected.ExtendedAuditingSettingName, actual.ExtendedAuditingSettingName) | ||
} | ||
} | ||
} |
Oops, something went wrong.