Skip to content
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

synapse_workspace supports sql_aad_admin #13659

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/services/synapse/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Client struct {
WorkspaceExtendedBlobAuditingPoliciesClient *synapse.WorkspaceManagedSQLServerExtendedBlobAuditingPoliciesClient
WorkspaceManagedIdentitySQLControlSettingsClient *synapse.WorkspaceManagedIdentitySQLControlSettingsClient
WorkspaceSecurityAlertPolicyClient *synapse.WorkspaceManagedSQLServerSecurityAlertPolicyClient
WorkspaceSQLAadAdminsClient *synapse.WorkspaceSQLAadAdminsClient
WorkspaceVulnerabilityAssessmentsClient *synapse.WorkspaceManagedSQLServerVulnerabilityAssessmentsClient

synapseAuthorizer autorest.Authorizer
Expand Down Expand Up @@ -87,6 +88,9 @@ func NewClient(o *common.ClientOptions) *Client {
workspaceSecurityAlertPolicyClient := synapse.NewWorkspaceManagedSQLServerSecurityAlertPolicyClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceSecurityAlertPolicyClient.Client, o.ResourceManagerAuthorizer)

workspaceSQLAadAdminsClient := synapse.NewWorkspaceSQLAadAdminsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceSQLAadAdminsClient.Client, o.ResourceManagerAuthorizer)

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

Expand All @@ -108,6 +112,7 @@ func NewClient(o *common.ClientOptions) *Client {
WorkspaceExtendedBlobAuditingPoliciesClient: &workspaceExtendedBlobAuditingPoliciesClient,
WorkspaceManagedIdentitySQLControlSettingsClient: &workspaceManagedIdentitySQLControlSettingsClient,
WorkspaceSecurityAlertPolicyClient: &workspaceSecurityAlertPolicyClient,
WorkspaceSQLAadAdminsClient: &workspaceSQLAadAdminsClient,
WorkspaceVulnerabilityAssessmentsClient: &workspaceVulnerabilityAssessmentsClient,

synapseAuthorizer: o.SynapseAuthorizer,
Expand Down
75 changes: 75 additions & 0 deletions internal/services/synapse/synapse_workspace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ func resourceSynapseWorkspace() *pluginsdk.Resource {
},
},

"sql_aad_admin": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
ConfigMode: pluginsdk.SchemaConfigModeAttr,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"login": {
Type: pluginsdk.TypeString,
Required: true,
},

"object_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.IsUUID,
},

"tenant_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.IsUUID,
},
},
},
},

"connectivity_endpoints": {
Type: pluginsdk.TypeMap,
Computed: true,
Expand Down Expand Up @@ -265,6 +293,7 @@ func resourceSynapseWorkspace() *pluginsdk.Resource {
func resourceSynapseWorkspaceCreate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Synapse.WorkspaceClient
aadAdminClient := meta.(*clients.Client).Synapse.WorkspaceAadAdminsClient
sqlAdminClient := meta.(*clients.Client).Synapse.WorkspaceSQLAadAdminsClient
identitySQLControlClient := meta.(*clients.Client).Synapse.WorkspaceManagedIdentitySQLControlSettingsClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -333,6 +362,18 @@ func resourceSynapseWorkspaceCreate(d *pluginsdk.ResourceData, meta interface{})
}
}

sqlAdmin := expandArmWorkspaceAadAdmin(d.Get("sql_aad_admin").([]interface{}))
if sqlAdmin != nil {
workspaceSqlAdminsCreateOrUpdateFuture, err := sqlAdminClient.CreateOrUpdate(ctx, resourceGroup, name, *aadAdmin)
if err != nil {
return fmt.Errorf("updating Synapse Workspace %q Sql Admin (Resource Group %q): %+v", name, resourceGroup, err)
}

if err = workspaceSqlAdminsCreateOrUpdateFuture.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting on updating for Synapse Workspace %q Sql Admin (Resource Group %q): %+v", name, resourceGroup, err)
}
}

sqlControlSettings := expandIdentityControlSQLSettings(d.Get("sql_identity_control_enabled").(bool))
if _, err = identitySQLControlClient.CreateOrUpdate(ctx, resourceGroup, name, *sqlControlSettings); err != nil {
return fmt.Errorf("Granting workspace identity control for SQL pool: %+v", err)
Expand All @@ -348,6 +389,7 @@ func resourceSynapseWorkspaceCreate(d *pluginsdk.ResourceData, meta interface{})
func resourceSynapseWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Synapse.WorkspaceClient
aadAdminClient := meta.(*clients.Client).Synapse.WorkspaceAadAdminsClient
sqlAdminClient := meta.(*clients.Client).Synapse.WorkspaceSQLAadAdminsClient
identitySQLControlClient := meta.(*clients.Client).Synapse.WorkspaceManagedIdentitySQLControlSettingsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand All @@ -373,6 +415,12 @@ func resourceSynapseWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) e
return fmt.Errorf("retrieving Synapse Workspace %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
}
sqlAdmin, err := sqlAdminClient.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
if !utils.ResponseWasNotFound(sqlAdmin.Response) {
return fmt.Errorf("retrieving Synapse Workspace %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
}

sqlControlSettings, err := identitySQLControlClient.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
Expand Down Expand Up @@ -417,6 +465,9 @@ func resourceSynapseWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) e
if err := d.Set("aad_admin", flattenArmWorkspaceAadAdmin(aadAdmin.AadAdminProperties)); err != nil {
return fmt.Errorf("setting `aad_admin`: %+v", err)
}
if err := d.Set("sql_aad_admin", flattenArmWorkspaceAadAdmin(sqlAdmin.AadAdminProperties)); err != nil {
return fmt.Errorf("setting `sql_aad_admin`: %+v", err)
}
if err := d.Set("sql_identity_control_enabled", flattenIdentityControlSQLSettings(sqlControlSettings)); err != nil {
return fmt.Errorf("setting `sql_identity_control_enabled`: %+v", err)
}
Expand All @@ -427,6 +478,7 @@ func resourceSynapseWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) e
func resourceSynapseWorkspaceUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Synapse.WorkspaceClient
aadAdminClient := meta.(*clients.Client).Synapse.WorkspaceAadAdminsClient
sqlAdminClient := meta.(*clients.Client).Synapse.WorkspaceSQLAadAdminsClient
identitySQLControlClient := meta.(*clients.Client).Synapse.WorkspaceManagedIdentitySQLControlSettingsClient
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -479,6 +531,29 @@ func resourceSynapseWorkspaceUpdate(d *pluginsdk.ResourceData, meta interface{})
}
}

if d.HasChange("sql_aad_admin") {
sqlAdmin := expandArmWorkspaceAadAdmin(d.Get("sql_aad_admin").([]interface{}))
if sqlAdmin != nil {
workspaceSqlAdminsCreateOrUpdateFuture, err := sqlAdminClient.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, *sqlAdmin)
if err != nil {
return fmt.Errorf("updating Synapse Workspace %q Sql Admin (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

if err = workspaceSqlAdminsCreateOrUpdateFuture.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting on updating for Synapse Workspace %q Sql Admin (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
} else {
workspaceSqlAdminsDeleteFuture, err := sqlAdminClient.Delete(ctx, id.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("setting empty Synapse Workspace %q Sql Admin (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

if err = workspaceSqlAdminsDeleteFuture.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting on setting empty Synapse Workspace %q Sql Admin (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
}
}

if d.HasChange("sql_identity_control_enabled") {
sqlControlSettings := expandIdentityControlSQLSettings(d.Get("sql_identity_control_enabled").(bool))
if _, err = identitySQLControlClient.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, *sqlControlSettings); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ resource "azurerm_synapse_workspace" "test" {
tenant_id = data.azurerm_client_config.current.tenant_id
}

sql_aad_admin {
login = "AzureAD Admin"
object_id = data.azurerm_client_config.current.object_id
tenant_id = data.azurerm_client_config.current.tenant_id
}

tags = {
ENV = "Test2"
}
Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/synapse_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ The following arguments are supported:

* `customer_managed_key` - (Optional) A `customer_managed_key` block as defined below.

* `sql_aad_admin` - (Optional) An `sql_aad_admin` block as defined below.

* `tags` - (Optional) A mapping of tags which should be assigned to the Synapse Workspace.

---
Expand All @@ -99,6 +101,16 @@ An `aad_admin` block supports the following:

---

An `sql_aad_admin` block supports the following:

* `login` - (Required) The login name of the Azure AD Administrator of this Synapse Workspace SQL.

* `object_id` - (Required) The object id of the Azure AD Administrator of this Synapse Workspace SQL.

* `tenant_id` - (Required) The tenant id of the Azure AD Administrator of this Synapse Workspace SQL.

---

An `azure_devops_repo` block supports the following:

* `account_name` - (Required) Specifies the Azure DevOps account name.
Expand Down