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

fix synapse endpoint not available issue in other cloud #9100

Merged
merged 3 commits into from
Nov 5, 2020
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
11 changes: 8 additions & 3 deletions azurerm/internal/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"strings"

"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/authentication"
"github.com/hashicorp/go-azure-helpers/sender"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
Expand Down Expand Up @@ -98,9 +100,12 @@ func Build(ctx context.Context, builder ClientBuilder) (*Client, error) {
}

// Synapse Endpoints
synapseAuth, err := builder.AuthConfig.GetAuthorizationToken(sender, oauthConfig, env.ResourceIdentifiers.Synapse)
if err != nil {
return nil, err
var synapseAuth autorest.Authorizer = nil
if env.ResourceIdentifiers.Synapse != azure.NotAvailable {
synapseAuth, err = builder.AuthConfig.GetAuthorizationToken(sender, oauthConfig, env.ResourceIdentifiers.Synapse)
if err != nil {
return nil, err
}
}

// Key Vault Endpoints
Expand Down
7 changes: 5 additions & 2 deletions azurerm/internal/services/synapse/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ func NewClient(o *common.ClientOptions) *Client {
}
}

func (client Client) AccessControlClient(workspaceName, synapseEndpointSuffix string) *accesscontrol.BaseClient {
func (client Client) AccessControlClient(workspaceName, synapseEndpointSuffix string) (*accesscontrol.BaseClient, error) {
if client.synapseAuthorizer == nil {
return nil, fmt.Errorf("synapse service is not supported in current environment")
}
endpoint := fmt.Sprintf("https://%s.%s", workspaceName, synapseEndpointSuffix)
accessControlClient := accesscontrol.New(endpoint)
accessControlClient.Client.Authorizer = client.synapseAuthorizer
return &accessControlClient
return &accessControlClient, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func resourceArmSynapseRoleAssignmentCreate(d *schema.ResourceData, meta interfa
principalID := d.Get("principal_id").(string)
roleName := d.Get("role_name").(string)

client := synapseClient.AccessControlClient(workspaceId.Name, environment.SynapseEndpointSuffix)
client, err := synapseClient.AccessControlClient(workspaceId.Name, environment.SynapseEndpointSuffix)
if err != nil {
return err
}
roleId, err := getRoleIdByName(ctx, client, roleName)
if err != nil {
return err
Expand Down Expand Up @@ -128,7 +131,10 @@ func resourceArmSynapseRoleAssignmentRead(d *schema.ResourceData, meta interface
return err
}

client := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
client, err := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
if err != nil {
return err
}
resp, err := client.GetRoleAssignmentByID(ctx, id.Id)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
Expand Down Expand Up @@ -163,7 +169,10 @@ func resourceArmSynapseRoleAssignmentDelete(d *schema.ResourceData, meta interfa
return err
}

client := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
client, err := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
if err != nil {
return nil
}
if _, err := client.DeleteRoleAssignmentByID(ctx, id.Id); err != nil {
return fmt.Errorf("deleting Synapse RoleAssignment %q (workspace %q): %+v", id, id.Workspace.Name, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ func testCheckAzureRMSynapseRoleAssignmentExists(resourceName string) resource.T
if err != nil {
return err
}
client := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
client, err := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
if err != nil {
return nil
}
if resp, err := client.GetRoleAssignmentByID(ctx, id.Id); err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("bad: Synapse role assignment %q does not exist", id.Id)
Expand Down Expand Up @@ -93,7 +96,10 @@ func testCheckAzureRMSynapseRoleAssignmentDestroy(s *terraform.State) error {
return nil
}

client := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
client, err := synapseClient.AccessControlClient(id.Workspace.Name, environment.SynapseEndpointSuffix)
if err != nil {
return err
}
resp, err := client.GetRoleAssignmentByID(ctx, id.Id)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
Expand Down