Skip to content

Commit

Permalink
Update sql/managed_instance to sql/mgmt/v5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed Nov 12, 2021
1 parent 605af2e commit 8053272
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions internal/services/sql/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2017-03-01-preview/sql"
msi "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2018-06-01-preview/sql"
mi "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v5.0/sql"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand All @@ -13,7 +14,7 @@ type Client struct {
DatabaseExtendedBlobAuditingPoliciesClient *sql.ExtendedDatabaseBlobAuditingPoliciesClient
FirewallRulesClient *sql.FirewallRulesClient
FailoverGroupsClient *sql.FailoverGroupsClient
ManagedInstancesClient *msi.ManagedInstancesClient
ManagedInstancesClient *mi.ManagedInstancesClient
ManagedDatabasesClient *msi.ManagedDatabasesClient
ServersClient *sql.ServersClient
ServerExtendedBlobAuditingPoliciesClient *sql.ExtendedServerBlobAuditingPoliciesClient
Expand Down Expand Up @@ -43,7 +44,7 @@ func NewClient(o *common.ClientOptions) *Client {
firewallRulesClient := sql.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&firewallRulesClient.Client, o.ResourceManagerAuthorizer)

managedInstancesClient := msi.NewManagedInstancesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
managedInstancesClient := mi.NewManagedInstancesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&managedInstancesClient.Client, o.ResourceManagerAuthorizer)

managedDatabasesClient := msi.NewManagedDatabasesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
Expand Down
16 changes: 4 additions & 12 deletions internal/services/sql/sql_managed_instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2018-06-01-preview/sql"
"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v5.0/sql"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
Expand Down Expand Up @@ -182,11 +183,6 @@ func resourceArmSqlMiServer() *schema.Resource {
pluginsdk.ForceNewIfChange("dns_zone_partner_id", func(ctx context.Context, old, new, _ interface{}) bool {
return old.(string) == "" && new.(string) != ""
}),

// identity.0.type can be set to SystemAssigned, but not removed or set to None in this SDK version
pluginsdk.ForceNewIfChange("identity.0.type", func(ctx context.Context, old, new, _ interface{}) bool {
return old.(string) == "SystemAssigned" && new.(string) != "SystemAssigned"
}),
),
}
}
Expand All @@ -202,7 +198,7 @@ func resourceArmSqlMiServerCreateUpdate(d *schema.ResourceData, meta interface{}
id := parse.NewManagedInstanceID(subscriptionId, resGroup, name)

if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.Name)
existing, err := client.Get(ctx, id.ResourceGroup, id.Name, "")
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("checking for presence of existing Managed Instance %q: %s", id.ID(), err)
Expand Down Expand Up @@ -273,7 +269,7 @@ func resourceArmSqlMiServerRead(d *schema.ResourceData, meta interface{}) error
return err
}

resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
resp, err := client.Get(ctx, id.ResourceGroup, id.Name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[INFO] Error reading SQL Managed Instance %q - removing from state", d.Id())
Expand Down Expand Up @@ -365,10 +361,6 @@ func expandManagedInstanceIdentity(input []interface{}) (*sql.ResourceIdentity,
return nil, err
}

if config.Type == identity.Type("None") {
return nil, nil
}

return &sql.ResourceIdentity{
Type: sql.IdentityType(config.Type),
}, nil
Expand Down
10 changes: 9 additions & 1 deletion internal/services/sql/sql_managed_instance_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func TestAccAzureRMSqlMiServer_identity(t *testing.T) {
),
},
data.ImportStep("administrator_login_password"),
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("identity.#").HasValue("0"),
),
},
data.ImportStep("administrator_login_password"),
})
}

Expand Down Expand Up @@ -150,7 +158,7 @@ func (r SqlManagedInstanceResource) Exists(ctx context.Context, client *clients.
return nil, err
}

resp, err := client.Sql.ManagedInstancesClient.Get(ctx, id.ResourceGroup, id.Name)
resp, err := client.Sql.ManagedInstancesClient.Get(ctx, id.ResourceGroup, id.Name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return utils.Bool(false), nil
Expand Down

0 comments on commit 8053272

Please sign in to comment.