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

Switching kusto RP from track1 sdk to pandora sdk #20563

Merged
merged 3 commits into from
Feb 24, 2023
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
41 changes: 24 additions & 17 deletions internal/services/kusto/client/client.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/kusto/mgmt/2022-02-01/kusto" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/attacheddatabaseconfigurations"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusterprincipalassignments"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/databaseprincipalassignments"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/databases"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/dataconnections"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/managedprivateendpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/scripts" // nolint: staticcheck
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
AttachedDatabaseConfigurationsClient *kusto.AttachedDatabaseConfigurationsClient
ClustersClient *kusto.ClustersClient
ClusterManagedPrivateEndpointClient *kusto.ManagedPrivateEndpointsClient
ClusterPrincipalAssignmentsClient *kusto.ClusterPrincipalAssignmentsClient
DatabasesClient *kusto.DatabasesClient
DataConnectionsClient *kusto.DataConnectionsClient
DatabasePrincipalAssignmentsClient *kusto.DatabasePrincipalAssignmentsClient
ScriptsClient *kusto.ScriptsClient
AttachedDatabaseConfigurationsClient *attacheddatabaseconfigurations.AttachedDatabaseConfigurationsClient
ClustersClient *clusters.ClustersClient
ClusterManagedPrivateEndpointClient *managedprivateendpoints.ManagedPrivateEndpointsClient
ClusterPrincipalAssignmentsClient *clusterprincipalassignments.ClusterPrincipalAssignmentsClient
DatabasesClient *databases.DatabasesClient
DataConnectionsClient *dataconnections.DataConnectionsClient
DatabasePrincipalAssignmentsClient *databaseprincipalassignments.DatabasePrincipalAssignmentsClient
ScriptsClient *scripts.ScriptsClient
}

func NewClient(o *common.ClientOptions) *Client {
ClustersClient := kusto.NewClustersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
ClustersClient := clusters.NewClustersClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&ClustersClient.Client, o.ResourceManagerAuthorizer)

ClusterManagedPrivateEndpointClient := kusto.NewManagedPrivateEndpointsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
ClusterManagedPrivateEndpointClient := managedprivateendpoints.NewManagedPrivateEndpointsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&ClusterManagedPrivateEndpointClient.Client, o.ResourceManagerAuthorizer)

ClusterPrincipalAssignmentsClient := kusto.NewClusterPrincipalAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
ClusterPrincipalAssignmentsClient := clusterprincipalassignments.NewClusterPrincipalAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&ClusterPrincipalAssignmentsClient.Client, o.ResourceManagerAuthorizer)

DatabasesClient := kusto.NewDatabasesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
DatabasesClient := databases.NewDatabasesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&DatabasesClient.Client, o.ResourceManagerAuthorizer)

DatabasePrincipalAssignmentsClient := kusto.NewDatabasePrincipalAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
DatabasePrincipalAssignmentsClient := databaseprincipalassignments.NewDatabasePrincipalAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&DatabasePrincipalAssignmentsClient.Client, o.ResourceManagerAuthorizer)

DataConnectionsClient := kusto.NewDataConnectionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
DataConnectionsClient := dataconnections.NewDataConnectionsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&DataConnectionsClient.Client, o.ResourceManagerAuthorizer)

AttachedDatabaseConfigurationsClient := kusto.NewAttachedDatabaseConfigurationsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
AttachedDatabaseConfigurationsClient := attacheddatabaseconfigurations.NewAttachedDatabaseConfigurationsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&AttachedDatabaseConfigurationsClient.Client, o.ResourceManagerAuthorizer)

ScriptsClient := kusto.NewScriptsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
ScriptsClient := scripts.NewScriptsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&ScriptsClient.Client, o.ResourceManagerAuthorizer)
return &Client{
AttachedDatabaseConfigurationsClient: &AttachedDatabaseConfigurationsClient,
Expand Down
10 changes: 5 additions & 5 deletions internal/services/kusto/identity.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package kusto

import (
"github.com/Azure/azure-sdk-for-go/services/kusto/mgmt/2022-02-01/kusto" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusters" // nolint: staticcheck
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func expandTrustedExternalTenants(input []interface{}) *[]kusto.TrustedExternalTenant {
output := make([]kusto.TrustedExternalTenant, 0)
func expandTrustedExternalTenants(input []interface{}) *[]clusters.TrustedExternalTenant {
output := make([]clusters.TrustedExternalTenant, 0)

for _, v := range input {
output = append(output, kusto.TrustedExternalTenant{
output = append(output, clusters.TrustedExternalTenant{
Value: utils.String(v.(string)),
})
}

return &output
}

func flattenTrustedExternalTenants(input *[]kusto.TrustedExternalTenant) []interface{} {
func flattenTrustedExternalTenants(input *[]clusters.TrustedExternalTenant) []interface{} {
if input == nil {
return []interface{}{}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/kusto/mgmt/2022-02-01/kusto" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/attacheddatabaseconfigurations"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusters"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -32,7 +34,7 @@ func resourceKustoAttachedDatabaseConfiguration() *pluginsdk.Resource {
}),

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.AttachedDatabaseConfigurationID(id)
_, err := attacheddatabaseconfigurations.ParseAttachedDatabaseConfigurationID(id)
return err
}),

Expand Down Expand Up @@ -85,14 +87,10 @@ func resourceKustoAttachedDatabaseConfiguration() *pluginsdk.Resource {
},

"default_principal_modification_kind": {
Type: pluginsdk.TypeString,
Optional: true,
Default: kusto.DefaultPrincipalsModificationKindNone,
ValidateFunc: validation.StringInSlice([]string{
string(kusto.DefaultPrincipalsModificationKindNone),
string(kusto.DefaultPrincipalsModificationKindReplace),
string(kusto.DefaultPrincipalsModificationKindUnion),
}, false),
Type: pluginsdk.TypeString,
Optional: true,
Default: attacheddatabaseconfigurations.DefaultPrincipalsModificationKindNone,
ValidateFunc: validation.StringInSlice(attacheddatabaseconfigurations.PossibleValuesForDefaultPrincipalsModificationKind(), false),
},

"sharing": {
Expand Down Expand Up @@ -161,33 +159,30 @@ func resourceKustoAttachedDatabaseConfigurationCreateUpdate(d *pluginsdk.Resourc
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewAttachedDatabaseConfigurationID(subscriptionId, d.Get("resource_group_name").(string), d.Get("cluster_name").(string), d.Get("name").(string))
id := attacheddatabaseconfigurations.NewAttachedDatabaseConfigurationID(subscriptionId, d.Get("resource_group_name").(string), d.Get("cluster_name").(string), d.Get("name").(string))
if d.IsNewResource() {
resp, err := client.Get(ctx, id.ResourceGroup, id.ClusterName, id.Name)
resp, err := client.Get(ctx, id)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
if !response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("checking for presence of existing %s: %+v", id, err)
}
}

if !utils.ResponseWasNotFound(resp.Response) {
if !response.WasNotFound(resp.HttpResponse) {
return tf.ImportAsExistsError("azurerm_kusto_attached_database_configuration", id.ID())
}
}

configurationProperties := expandKustoAttachedDatabaseConfigurationProperties(d)
configurationRequest := kusto.AttachedDatabaseConfiguration{
Location: utils.String(location.Normalize(d.Get("location").(string))),
AttachedDatabaseConfigurationProperties: configurationProperties,
configurationRequest := attacheddatabaseconfigurations.AttachedDatabaseConfiguration{
Location: utils.String(location.Normalize(d.Get("location").(string))),
Properties: configurationProperties,
}

future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.ClusterName, id.Name, configurationRequest)
err := client.CreateOrUpdateThenPoll(ctx, id, configurationRequest)
if err != nil {
return fmt.Errorf("creating/updating %s: %+v", id, err)
}
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation/update of %s: %+v", id, err)
}

d.SetId(id.ID())
return resourceKustoAttachedDatabaseConfigurationRead(d, meta)
Expand All @@ -198,33 +193,39 @@ func resourceKustoAttachedDatabaseConfigurationRead(d *pluginsdk.ResourceData, m
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.AttachedDatabaseConfigurationID(d.Id())
id, err := attacheddatabaseconfigurations.ParseAttachedDatabaseConfigurationID(d.Id())
if err != nil {
return err
}

resp, err := client.Get(ctx, id.ResourceGroup, id.ClusterName, id.Name)
resp, err := client.Get(ctx, *id)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
if !response.WasNotFound(resp.HttpResponse) {
d.SetId("")
return nil
}

return fmt.Errorf("retrieving %s: %+v", id, err)
}

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.AttachedDatabaseConfigurationName)
d.Set("resource_group_name", id.ResourceGroupName)
d.Set("cluster_name", id.ClusterName)

d.Set("location", location.NormalizeNilable(resp.Location))
if model := resp.Model; model != nil {
d.Set("location", location.NormalizeNilable(model.Location))

if props := resp.AttachedDatabaseConfigurationProperties; props != nil {
d.Set("cluster_resource_id", props.ClusterResourceID)
d.Set("database_name", props.DatabaseName)
d.Set("default_principal_modification_kind", props.DefaultPrincipalsModificationKind)
d.Set("attached_database_names", props.AttachedDatabaseNames)
d.Set("sharing", flattenAttachedDatabaseConfigurationTableLevelSharingProperties(props.TableLevelSharingProperties))
if props := model.Properties; props != nil {
clusterResourceId, parseErr := clusters.ParseClusterIDInsensitively(props.ClusterResourceId)
if parseErr != nil {
return parseErr
}
d.Set("cluster_resource_id", clusterResourceId.ID())
d.Set("database_name", props.DatabaseName)
d.Set("default_principal_modification_kind", props.DefaultPrincipalsModificationKind)
d.Set("attached_database_names", props.AttachedDatabaseNames)
d.Set("sharing", flattenAttachedDatabaseConfigurationTableLevelSharingProperties(props.TableLevelSharingProperties))
}
}

return nil
Expand All @@ -235,49 +236,49 @@ func resourceKustoAttachedDatabaseConfigurationDelete(d *pluginsdk.ResourceData,
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.AttachedDatabaseConfigurationID(d.Id())
id, err := attacheddatabaseconfigurations.ParseAttachedDatabaseConfigurationID(d.Id())
if err != nil {
return err
}

future, err := client.Delete(ctx, id.ResourceGroup, id.ClusterName, id.Name)
// DELETE operation for attached configuration does not support running concurrently at cluster level
locks.ByName(id.ClusterName, "azurerm_kusto_cluster")
defer locks.UnlockByName(id.ClusterName, "azurerm_kusto_cluster")

err = client.DeleteThenPoll(ctx, *id)
if err != nil {
return fmt.Errorf("deleting %s: %+v", id, err)
}

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

return nil
}

func expandKustoAttachedDatabaseConfigurationProperties(d *pluginsdk.ResourceData) *kusto.AttachedDatabaseConfigurationProperties {
AttachedDatabaseConfigurationProperties := &kusto.AttachedDatabaseConfigurationProperties{}
func expandKustoAttachedDatabaseConfigurationProperties(d *pluginsdk.ResourceData) *attacheddatabaseconfigurations.AttachedDatabaseConfigurationProperties {
AttachedDatabaseConfigurationProperties := &attacheddatabaseconfigurations.AttachedDatabaseConfigurationProperties{}

if clusterResourceID, ok := d.GetOk("cluster_resource_id"); ok {
AttachedDatabaseConfigurationProperties.ClusterResourceID = utils.String(clusterResourceID.(string))
AttachedDatabaseConfigurationProperties.ClusterResourceId = clusterResourceID.(string)
}

if databaseName, ok := d.GetOk("database_name"); ok {
AttachedDatabaseConfigurationProperties.DatabaseName = utils.String(databaseName.(string))
AttachedDatabaseConfigurationProperties.DatabaseName = databaseName.(string)
}

if defaultPrincipalModificationKind, ok := d.GetOk("default_principal_modification_kind"); ok {
AttachedDatabaseConfigurationProperties.DefaultPrincipalsModificationKind = kusto.DefaultPrincipalsModificationKind(defaultPrincipalModificationKind.(string))
AttachedDatabaseConfigurationProperties.DefaultPrincipalsModificationKind = attacheddatabaseconfigurations.DefaultPrincipalsModificationKind(defaultPrincipalModificationKind.(string))
}

AttachedDatabaseConfigurationProperties.TableLevelSharingProperties = expandAttachedDatabaseConfigurationTableLevelSharingProperties(d.Get("sharing").([]interface{}))

return AttachedDatabaseConfigurationProperties
}

func expandAttachedDatabaseConfigurationTableLevelSharingProperties(input []interface{}) *kusto.TableLevelSharingProperties {
func expandAttachedDatabaseConfigurationTableLevelSharingProperties(input []interface{}) *attacheddatabaseconfigurations.TableLevelSharingProperties {
if len(input) == 0 {
return nil
}
v := input[0].(map[string]interface{})
return &kusto.TableLevelSharingProperties{
return &attacheddatabaseconfigurations.TableLevelSharingProperties{
TablesToInclude: utils.ExpandStringSlice(v["tables_to_include"].(*pluginsdk.Set).List()),
TablesToExclude: utils.ExpandStringSlice(v["tables_to_exclude"].(*pluginsdk.Set).List()),
ExternalTablesToInclude: utils.ExpandStringSlice(v["external_tables_to_include"].(*pluginsdk.Set).List()),
Expand All @@ -287,7 +288,7 @@ func expandAttachedDatabaseConfigurationTableLevelSharingProperties(input []inte
}
}

func flattenAttachedDatabaseConfigurationTableLevelSharingProperties(input *kusto.TableLevelSharingProperties) []interface{} {
func flattenAttachedDatabaseConfigurationTableLevelSharingProperties(input *attacheddatabaseconfigurations.TableLevelSharingProperties) []interface{} {
if input == nil {
return make([]interface{}, 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/attacheddatabaseconfigurations"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

type KustoAttachedDatabaseConfigurationResource struct{}
Expand All @@ -31,17 +30,23 @@ func TestAccKustoAttachedDatabaseConfiguration_basic(t *testing.T) {
}

func (KustoAttachedDatabaseConfigurationResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.AttachedDatabaseConfigurationID(state.ID)
id, err := attacheddatabaseconfigurations.ParseAttachedDatabaseConfigurationID(state.ID)
if err != nil {
return nil, err
}

resp, err := clients.Kusto.AttachedDatabaseConfigurationsClient.Get(ctx, id.ResourceGroup, id.ClusterName, id.Name)
resp, err := clients.Kusto.AttachedDatabaseConfigurationsClient.Get(ctx, *id)
if err != nil {
return nil, fmt.Errorf("retrieving %s: %v", id.String(), err)
}

return utils.Bool(resp.AttachedDatabaseConfigurationProperties != nil), nil
if resp.Model == nil {
return nil, fmt.Errorf("response model is empty")
}

exists := resp.Model.Properties != nil

return &exists, nil
}

func (KustoAttachedDatabaseConfigurationResource) basic(data acceptance.TestData) string {
Expand Down
Loading