Skip to content

Commit

Permalink
New Resource: azurerm_synapse_sql_pool_extended_auditing_policy and…
Browse files Browse the repository at this point in the history
… `azurerm_synapse_workspace_extended_auditing_policy` (#12952)
  • Loading branch information
owenfarrell authored Sep 22, 2021
1 parent 68614fb commit 7f7aad2
Show file tree
Hide file tree
Showing 17 changed files with 2,366 additions and 20 deletions.
35 changes: 23 additions & 12 deletions internal/services/synapse/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ import (

type Client struct {
FirewallRulesClient *synapse.IPFirewallRulesClient
IntegrationRuntimesClient *synapse.IntegrationRuntimesClient
IntegrationRuntimeAuthKeysClient *synapse.IntegrationRuntimeAuthKeysClient
IntegrationRuntimesClient *synapse.IntegrationRuntimesClient
KeysClient *synapse.KeysClient
PrivateLinkHubsClient *synapse.PrivateLinkHubsClient
SparkPoolClient *synapse.BigDataPoolsClient
SqlPoolClient *synapse.SQLPoolsClient
SqlPoolExtendedBlobAuditingPoliciesClient *synapse.ExtendedSQLPoolBlobAuditingPoliciesClient
SqlPoolSecurityAlertPolicyClient *synapse.SQLPoolSecurityAlertPoliciesClient
SqlPoolTransparentDataEncryptionClient *synapse.SQLPoolTransparentDataEncryptionsClient
SqlPoolVulnerabilityAssessmentsClient *synapse.SQLPoolVulnerabilityAssessmentsClient
WorkspaceClient *synapse.WorkspacesClient
WorkspaceAadAdminsClient *synapse.WorkspaceAadAdminsClient
WorkspaceClient *synapse.WorkspacesClient
WorkspaceExtendedBlobAuditingPoliciesClient *synapse.WorkspaceManagedSQLServerExtendedBlobAuditingPoliciesClient
WorkspaceManagedIdentitySQLControlSettingsClient *synapse.WorkspaceManagedIdentitySQLControlSettingsClient
WorkspaceSecurityAlertPolicyClient *synapse.WorkspaceManagedSQLServerSecurityAlertPolicyClient
WorkspaceVulnerabilityAssessmentsClient *synapse.WorkspaceManagedSQLServerVulnerabilityAssessmentsClient
KeysClient *synapse.KeysClient

synapseAuthorizer autorest.Authorizer
}
Expand All @@ -35,11 +37,14 @@ func NewClient(o *common.ClientOptions) *Client {
firewallRuleClient := synapse.NewIPFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&firewallRuleClient.Client, o.ResourceManagerAuthorizer)

integrationRuntimeAuthKeysClient := synapse.NewIntegrationRuntimeAuthKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&integrationRuntimeAuthKeysClient.Client, o.ResourceManagerAuthorizer)

integrationRuntimesClient := synapse.NewIntegrationRuntimesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&integrationRuntimesClient.Client, o.ResourceManagerAuthorizer)

integrationRuntimeAuthKeysClient := synapse.NewIntegrationRuntimeAuthKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&integrationRuntimeAuthKeysClient.Client, o.ResourceManagerAuthorizer)
keysClient := synapse.NewKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&keysClient.Client, o.ResourceManagerAuthorizer)

privateLinkHubsClient := synapse.NewPrivateLinkHubsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&privateLinkHubsClient.Client, o.ResourceManagerAuthorizer)
Expand All @@ -51,6 +56,9 @@ func NewClient(o *common.ClientOptions) *Client {
sqlPoolClient := synapse.NewSQLPoolsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&sqlPoolClient.Client, o.ResourceManagerAuthorizer)

sqlPoolExtendedBlobAuditingPoliciesClient := synapse.NewExtendedSQLPoolBlobAuditingPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&sqlPoolExtendedBlobAuditingPoliciesClient.Client, o.ResourceManagerAuthorizer)

sqlPoolSecurityAlertPolicyClient := synapse.NewSQLPoolSecurityAlertPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&sqlPoolSecurityAlertPolicyClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -60,11 +68,14 @@ func NewClient(o *common.ClientOptions) *Client {
sqlPoolVulnerabilityAssessmentsClient := synapse.NewSQLPoolVulnerabilityAssessmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&sqlPoolVulnerabilityAssessmentsClient.Client, o.ResourceManagerAuthorizer)

workspaceAadAdminsClient := synapse.NewWorkspaceAadAdminsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceAadAdminsClient.Client, o.ResourceManagerAuthorizer)

workspaceClient := synapse.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceClient.Client, o.ResourceManagerAuthorizer)

workspaceAadAdminsClient := synapse.NewWorkspaceAadAdminsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceAadAdminsClient.Client, o.ResourceManagerAuthorizer)
workspaceExtendedBlobAuditingPoliciesClient := synapse.NewWorkspaceManagedSQLServerExtendedBlobAuditingPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceExtendedBlobAuditingPoliciesClient.Client, o.ResourceManagerAuthorizer)

workspaceManagedIdentitySQLControlSettingsClient := synapse.NewWorkspaceManagedIdentitySQLControlSettingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceManagedIdentitySQLControlSettingsClient.Client, o.ResourceManagerAuthorizer)
Expand All @@ -74,25 +85,25 @@ func NewClient(o *common.ClientOptions) *Client {

workspaceVulnerabilityAssessmentsClient := synapse.NewWorkspaceManagedSQLServerVulnerabilityAssessmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceVulnerabilityAssessmentsClient.Client, o.ResourceManagerAuthorizer)
keysClient := synapse.NewKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&keysClient.Client, o.ResourceManagerAuthorizer)

return &Client{
FirewallRulesClient: &firewallRuleClient,
IntegrationRuntimesClient: &integrationRuntimesClient,
IntegrationRuntimeAuthKeysClient: &integrationRuntimeAuthKeysClient,
IntegrationRuntimesClient: &integrationRuntimesClient,
KeysClient: &keysClient,
PrivateLinkHubsClient: &privateLinkHubsClient,
SparkPoolClient: &sparkPoolClient,
SqlPoolClient: &sqlPoolClient,
SqlPoolExtendedBlobAuditingPoliciesClient: &sqlPoolExtendedBlobAuditingPoliciesClient,
SqlPoolSecurityAlertPolicyClient: &sqlPoolSecurityAlertPolicyClient,
SqlPoolTransparentDataEncryptionClient: &sqlPoolTransparentDataEncryptionClient,
SqlPoolVulnerabilityAssessmentsClient: &sqlPoolVulnerabilityAssessmentsClient,
WorkspaceClient: &workspaceClient,
WorkspaceAadAdminsClient: &workspaceAadAdminsClient,
WorkspaceClient: &workspaceClient,
WorkspaceExtendedBlobAuditingPoliciesClient: &workspaceExtendedBlobAuditingPoliciesClient,
WorkspaceManagedIdentitySQLControlSettingsClient: &workspaceManagedIdentitySQLControlSettingsClient,
WorkspaceSecurityAlertPolicyClient: &workspaceSecurityAlertPolicyClient,
WorkspaceVulnerabilityAssessmentsClient: &workspaceVulnerabilityAssessmentsClient,
KeysClient: &keysClient,

synapseAuthorizer: o.SynapseAuthorizer,
}
Expand Down
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
}
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)
}
}
}
Loading

0 comments on commit 7f7aad2

Please sign in to comment.