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

azurerm_synapse_workspace - add support for azuread_authentication_only #23659

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -31,6 +31,7 @@ type Client struct {
SQLPoolWorkloadClassifierClient *synapse.SQLPoolWorkloadClassifierClient
SQLPoolWorkloadGroupClient *synapse.SQLPoolWorkloadGroupClient
WorkspaceAadAdminsClient *synapse.WorkspaceAadAdminsClient
WorkspaceAzureADOnlyAuthenticationsClient *synapse.AzureADOnlyAuthenticationsClient
WorkspaceClient *synapse.WorkspacesClient
WorkspaceExtendedBlobAuditingPoliciesClient *synapse.WorkspaceManagedSQLServerExtendedBlobAuditingPoliciesClient
WorkspaceManagedIdentitySQLControlSettingsClient *synapse.WorkspaceManagedIdentitySQLControlSettingsClient
Expand Down Expand Up @@ -91,6 +92,9 @@ func NewClient(o *common.ClientOptions) *Client {
workspaceAadAdminsClient := synapse.NewWorkspaceAadAdminsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceAadAdminsClient.Client, o.ResourceManagerAuthorizer)

workspaceAzureADOnlyAuthenticationsClient := synapse.NewAzureADOnlyAuthenticationsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&workspaceAzureADOnlyAuthenticationsClient.Client, o.ResourceManagerAuthorizer)

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

Expand Down Expand Up @@ -125,6 +129,7 @@ func NewClient(o *common.ClientOptions) *Client {
SQLPoolVulnerabilityAssessmentRuleBaselinesClient: &sqlPoolVulnerabilityAssessmentRuleBaselinesClient,
SQLPoolWorkloadClassifierClient: &sqlPoolWorkloadClassifierClient,
SQLPoolWorkloadGroupClient: &sqlPoolWorkloadGroupClient,
WorkspaceAzureADOnlyAuthenticationsClient: &workspaceAzureADOnlyAuthenticationsClient,
WorkspaceAadAdminsClient: &workspaceAadAdminsClient,
WorkspaceClient: &workspaceClient,
WorkspaceExtendedBlobAuditingPoliciesClient: &workspaceExtendedBlobAuditingPoliciesClient,
Expand Down
25 changes: 25 additions & 0 deletions internal/services/synapse/synapse_workspace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/preview/synapse/mgmt/v2.0/synapse" // nolint: staticcheck
"github.com/gofrs/uuid"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -312,6 +313,12 @@ func resourceSynapseWorkspace() *pluginsdk.Resource {
},
},

"azure_ad_only_authentication_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -358,6 +365,7 @@ func resourceSynapseWorkspaceCreate(d *pluginsdk.ResourceData, meta interface{})
ManagedResourceGroupName: utils.String(d.Get("managed_resource_group_name").(string)),
WorkspaceRepositoryConfiguration: expandWorkspaceRepositoryConfiguration(d),
Encryption: expandEncryptionDetails(d),
AzureADOnlyAuthentication: utils.Bool(d.Get("azure_ad_only_authentication_enabled").(bool)),
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}
Expand Down Expand Up @@ -519,6 +527,7 @@ func resourceSynapseWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) e
d.Set("managed_resource_group_name", props.ManagedResourceGroupName)
d.Set("connectivity_endpoints", utils.FlattenMapStringPtrString(props.ConnectivityEndpoints))
d.Set("public_network_access_enabled", resp.PublicNetworkAccess == synapse.WorkspacePublicNetworkAccessEnabled)
d.Set("azure_ad_only_authentication_enabled", props.AzureADOnlyAuthentication)
cmk := flattenEncryptionDetails(props.Encryption)
if err := d.Set("customer_managed_key", cmk); err != nil {
return fmt.Errorf("setting `customer_managed_key`: %+v", err)
Expand Down Expand Up @@ -559,6 +568,7 @@ func resourceSynapseWorkspaceUpdate(d *pluginsdk.ResourceData, meta interface{})
client := meta.(*clients.Client).Synapse.WorkspaceClient
aadAdminClient := meta.(*clients.Client).Synapse.WorkspaceAadAdminsClient
sqlAdminClient := meta.(*clients.Client).Synapse.WorkspaceSQLAadAdminsClient
azureADOnlyAuthenticationsClient := meta.(*clients.Client).Synapse.WorkspaceAzureADOnlyAuthenticationsClient
identitySQLControlClient := meta.(*clients.Client).Synapse.WorkspaceManagedIdentitySQLControlSettingsClient
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -614,6 +624,21 @@ func resourceSynapseWorkspaceUpdate(d *pluginsdk.ResourceData, meta interface{})
}
}

if d.HasChange("azure_ad_only_authentication_enabled") {
future, err := azureADOnlyAuthenticationsClient.Create(ctx, id.ResourceGroup, id.Name, synapse.AzureADOnlyAuthentication{
AzureADOnlyAuthenticationProperties: &synapse.AzureADOnlyAuthenticationProperties{
AzureADOnlyAuthentication: pointer.To(d.Get("azure_ad_only_authentication_enabled").(bool)),
},
})
if err != nil {
return fmt.Errorf("updating azure_ad_only_authentication_enabled for %s: %+v", id, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for azure_ad_only_authentication_enabled to finish updating for %s: %+v", id, err)
}
}

if d.HasChange("aad_admin") {
aadAdmin := expandArmWorkspaceAadAdminInfo(d.Get("aad_admin").([]interface{}))
if aadAdmin != nil {
Expand Down
62 changes: 62 additions & 0 deletions internal/services/synapse/synapse_workspace_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@ func TestAccSynapseWorkspace_customerManagedKeyActivation(t *testing.T) {
})
}

func TestAccSynapseWorkspace_azureAdOnlyAuthentication(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_synapse_workspace", "test")
r := SynapseWorkspaceResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.azureAdOnlyAuthentication(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("managed_resource_group_name").Exists(),
),
},
data.ImportStep("sql_administrator_login_password"),
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("managed_resource_group_name").Exists(),
),
},
data.ImportStep("sql_administrator_login_password"),
{
Config: r.azureAdOnlyAuthentication(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("managed_resource_group_name").Exists(),
),
},
data.ImportStep("sql_administrator_login_password"),
})
}

func (r SynapseWorkspaceResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.WorkspaceID(state.ID)
if err != nil {
Expand Down Expand Up @@ -583,6 +615,36 @@ resource "azurerm_synapse_workspace" "test" {
`, template, data.RandomInteger, data.RandomInteger)
}

func (r SynapseWorkspaceResource) azureAdOnlyAuthentication(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s

data "azurerm_client_config" "current" {}

resource "azurerm_user_assigned_identity" "test" {
name = "acctestuaid%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}

resource "azurerm_synapse_workspace" "test" {
name = "acctestsw%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
storage_data_lake_gen2_filesystem_id = azurerm_storage_data_lake_gen2_filesystem.test.id
sql_administrator_login = "sqladminuser"
sql_administrator_login_password = "H@Sh1CoR3!"
azure_ad_only_authentication_enabled = true

identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [azurerm_user_assigned_identity.test.id]
}
}
`, template, data.RandomInteger, data.RandomInteger)
}

func (r SynapseWorkspaceResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/synapse_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ The following arguments are supported:

* `sql_administrator_login_password` - (Optional) The Password associated with the `sql_administrator_login` for the SQL administrator. If this is not provided `aad_admin` or `customer_managed_key` must be provided.

* `azure_ad_only_authentication_enabled` - (Optional) Is Azure Active Directory Authentication the only way to authenticate with resources inside this synapse Workspace. Defaults to `false`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have azuread_authentication_only in the provider elsewhere so we might want to use that?


---

* `aad_admin` - (Optional) An `aad_admin` block as defined below. Conflicts with `customer_managed_key`.
Expand Down
Loading