Skip to content

Commit

Permalink
azurerm_mssql_managed_instance_failover_group - fixed issue when tr…
Browse files Browse the repository at this point in the history
…ying to create a failover group with a managed instance from a different subscription (#24646)
  • Loading branch information
mbfrahry authored Jan 25, 2024
1 parent b8247ae commit de8e7d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions internal/services/mssqlmanagedinstance/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Client struct {
ManagedInstanceEncryptionProtectorClient *sql.ManagedInstanceEncryptionProtectorsClient
ManagedInstanceFailoverGroupsClient *sql.InstanceFailoverGroupsClient
ManagedInstanceKeysClient *sql.ManagedInstanceKeysClient

options *common.ClientOptions
}

func NewClient(o *common.ClientOptions) *Client {
Expand Down Expand Up @@ -69,5 +71,14 @@ func NewClient(o *common.ClientOptions) *Client {
ManagedInstancesShortTermRetentionPoliciesClient: &managedInstancesShortTermRetentionPoliciesClient,
ManagedInstanceVulnerabilityAssessmentsClient: &managedInstanceVulnerabilityAssessmentsClient,
ManagedInstancesClient: &managedInstancesClient,

options: o,
}
}

func (c Client) ManagedInstancesClientForSubscription(subscriptionID string) *sql.ManagedInstancesClient {
// TODO: this method can be removed once this is moved to using `hashicorp/go-azure-sdk`
managedInstancesClient := sql.NewManagedInstancesClientWithBaseURI(c.options.ResourceManagerEndpoint, subscriptionID)
c.options.ConfigureClient(&managedInstancesClient.Client, c.options.ResourceManagerAuthorizer)
return &managedInstancesClient
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Create() sdk.ResourceFunc {
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.MSSQLManagedInstance.ManagedInstanceFailoverGroupsClient
instancesClient := metadata.Client.MSSQLManagedInstance.ManagedInstancesClient

var model MsSqlManagedInstanceFailoverGroupModel
if err := metadata.Decode(&model); err != nil {
Expand All @@ -165,6 +164,7 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Create() sdk.ResourceFunc {
return err
}

instancesClient := metadata.Client.MSSQLManagedInstance.ManagedInstancesClientForSubscription(partnerId.SubscriptionId)
partner, err := instancesClient.Get(ctx, partnerId.ResourceGroup, partnerId.Name, "")
if err != nil || partner.Location == nil || *partner.Location == "" {
return fmt.Errorf("checking for existence and region of Partner of %q: %+v", id, err)
Expand Down Expand Up @@ -235,7 +235,6 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Update() sdk.ResourceFunc {
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.MSSQLManagedInstance.ManagedInstanceFailoverGroupsClient
instancesClient := metadata.Client.MSSQLManagedInstance.ManagedInstancesClient

id, err := parse.InstanceFailoverGroupID(metadata.ResourceData.Id())
if err != nil {
Expand All @@ -258,6 +257,7 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Update() sdk.ResourceFunc {
return err
}

instancesClient := metadata.Client.MSSQLManagedInstance.ManagedInstancesClientForSubscription(partnerId.SubscriptionId)
partner, err := instancesClient.Get(ctx, partnerId.ResourceGroup, partnerId.Name, "")
if err != nil || partner.Location == nil || *partner.Location == "" {
return fmt.Errorf("checking for existence and region of Partner of %q: %+v", id, err)
Expand Down

0 comments on commit de8e7d4

Please sign in to comment.