Skip to content

Commit

Permalink
Kusto - upgrade API Version from 2022-02-01 to 2022-12-29 (#21961)
Browse files Browse the repository at this point in the history
Co-authored-by: kt <kt@katbyte.me>
  • Loading branch information
liuwuliuyun and katbyte authored Jun 13, 2023
1 parent d2a3444 commit 938514c
Show file tree
Hide file tree
Showing 215 changed files with 4,873 additions and 154 deletions.
16 changes: 8 additions & 8 deletions internal/services/kusto/client/client.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package client

import (
"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/go-azure-sdk/resource-manager/kusto/2022-12-29/attacheddatabaseconfigurations"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusterprincipalassignments"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/databaseprincipalassignments"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/databases"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/dataconnections"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/managedprivateendpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/scripts" // nolint: staticcheck
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/services/kusto/identity.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kusto

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"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/go-azure-sdk/resource-manager/kusto/2022-12-29/attacheddatabaseconfigurations"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusters"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/attacheddatabaseconfigurations"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusters"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusters"
"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"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/kusto/kusto_cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/managedprivateendpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/managedprivateendpoints"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/managedprivateendpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/managedprivateendpoints"
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusterprincipalassignments"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusterprincipalassignments"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/migration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusterprincipalassignments"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusterprincipalassignments"
"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"
Expand Down
199 changes: 119 additions & 80 deletions internal/services/kusto/kusto_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-helpers/resourcemanager/zones"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-02-01/clusters"
newCluster "github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-07-07/clusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-12-29/clusters"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -76,9 +75,7 @@ func resourceKustoCluster() *pluginsdk.Resource {
"name": {
Type: pluginsdk.TypeString,
Required: true,
// using API version later than 2022-07-07 to unblock user access to latest skus.
// next PR will to API version upgrade to version 2022-12-10 and align the api version in kusto.
ValidateFunc: validation.StringInSlice(newCluster.PossibleValuesForAzureSkuName(),
ValidateFunc: validation.StringInSlice(clusters.PossibleValuesForAzureSkuName(),
false),
},

Expand Down Expand Up @@ -167,15 +164,6 @@ func resourceKustoCluster() *pluginsdk.Resource {
},
},

"language_extensions": {
Type: pluginsdk.TypeSet,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(clusters.PossibleValuesForLanguageExtensionName(), false),
},
},

"engine": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -250,8 +238,35 @@ func resourceKustoCluster() *pluginsdk.Resource {

if features.FourPointOhBeta() {
s.Schema["engine"].Default = string(clusters.EngineTypeVThree)
s.Schema["language_extensions"] = &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
ConflictsWith: []string{"language_extensions"},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(clusters.PossibleValuesForLanguageExtensionName(), false),
},
"image": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(clusters.PossibleValuesForLanguageExtensionImageName(), false),
},
},
},
}
} else {
s.Schema["engine"].Default = string(clusters.EngineTypeVTwo)
s.Schema["language_extensions"] = &pluginsdk.Schema{
Type: pluginsdk.TypeSet,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice([]string{"R", "PYTHON", "PYTHON_3.10.8"}, false),
},
}
}

return s
Expand Down Expand Up @@ -352,6 +367,15 @@ func resourceKustoClusterCreateUpdate(d *pluginsdk.ResourceData, meta interface{
}
clusterProperties.RestrictOutboundNetworkAccess = &restrictOutboundNetworkAccess

if features.FourPointOhBeta() {
if v, ok := d.GetOk("language_extensions"); ok {
extList := v.([]interface{})
clusterProperties.LanguageExtensions = expandKustoClusterLanguageExtensionList(extList)
}
} else {
clusterProperties.LanguageExtensions = expandKustoClusterLanguageExtensions(d)
}

expandedIdentity, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
Expand All @@ -377,45 +401,6 @@ func resourceKustoClusterCreateUpdate(d *pluginsdk.ResourceData, meta interface{

d.SetId(id.ID())

if v, ok := d.GetOk("language_extensions"); ok {
languageExtensions := expandKustoClusterLanguageExtensions(v.(*pluginsdk.Set).List())

currentLanguageExtensions, err := client.ListLanguageExtensions(ctx, id)
if err != nil {
return fmt.Errorf("retrieving the language extensions on %s: %+v", id, err)
}

languageExtensionsToAdd := diffLanguageExtensions(*languageExtensions.Value, *currentLanguageExtensions.Model.Value)
if len(languageExtensionsToAdd) > 0 {
languageExtensionsListToAdd := clusters.LanguageExtensionsList{
Value: &languageExtensionsToAdd,
}

resp, err := client.AddLanguageExtensions(ctx, id, languageExtensionsListToAdd)
if err != nil {
return fmt.Errorf("adding language extensions to %s: %+v", id, err)
}
if err = resp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("waiting for the addition of language extensions on %s: %+v", id, err)
}
}

languageExtensionsToRemove := diffLanguageExtensions(*currentLanguageExtensions.Model.Value, *languageExtensions.Value)
if len(languageExtensionsToRemove) > 0 {
languageExtensionsListToRemove := clusters.LanguageExtensionsList{
Value: &languageExtensionsToRemove,
}

removeLanguageExtensionsFuture, err := client.RemoveLanguageExtensions(ctx, id, languageExtensionsListToRemove)
if err != nil {
return fmt.Errorf("removing language extensions from %s: %+v", id, err)
}
if err = removeLanguageExtensionsFuture.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("waiting for the removal of language extensions from %s: %+v", id, err)
}
}
}

return resourceKustoClusterRead(d, meta)
}

Expand Down Expand Up @@ -478,12 +463,17 @@ func resourceKustoClusterRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("streaming_ingestion_enabled", props.EnableStreamingIngest)
d.Set("purge_enabled", props.EnablePurge)
d.Set("virtual_network_configuration", flattenKustoClusterVNET(props.VirtualNetworkConfiguration))
d.Set("language_extensions", flattenKustoClusterLanguageExtensions(props.LanguageExtensions))
d.Set("uri", props.Uri)
d.Set("data_ingestion_uri", props.DataIngestionUri)
d.Set("engine", string(pointer.From(props.EngineType)))
d.Set("public_ip_type", string(pointer.From(props.PublicIPType)))

if features.FourPointOhBeta() {
d.Set("language_extensions", flattenKustoClusterLanguageExtensionList(props.LanguageExtensions))
} else {
d.Set("language_extensions", flattenKustoClusterLanguageExtensions(props.LanguageExtensions))
}

}

if err := tags.FlattenAndSet(d, model.Tags); err != nil {
Expand Down Expand Up @@ -596,23 +586,62 @@ func expandKustoClusterVNET(input []interface{}) *clusters.VirtualNetworkConfigu
}
}

func expandKustoClusterLanguageExtensions(input []interface{}) *clusters.LanguageExtensionsList {
if len(input) == 0 {
return nil
func expandKustoClusterLanguageExtensions(d *pluginsdk.ResourceData) *clusters.LanguageExtensionsList {
if v, ok := d.GetOk("language_extensions"); ok {
extList := v.(*pluginsdk.Set).List()
if len(extList) > 0 {
extensions := make([]clusters.LanguageExtension, 0)
for _, language := range extList {
name := language.(string)
lanExt := clusters.LanguageExtension{}
switch name {
case "R":
n := clusters.LanguageExtensionNameR
lanExt.LanguageExtensionName = &n
imageName := clusters.LanguageExtensionImageNameR
lanExt.LanguageExtensionImageName = &imageName
case "PYTHON":
n := clusters.LanguageExtensionNamePYTHON
lanExt.LanguageExtensionName = &n
imageName := clusters.LanguageExtensionImageNamePythonThreeSixFive
lanExt.LanguageExtensionImageName = &imageName
case "PYTHON_3.10.8":
n := clusters.LanguageExtensionNamePYTHON
lanExt.LanguageExtensionName = &n
imageName := clusters.LanguageExtensionImageNamePythonThreeOneZeroEight
lanExt.LanguageExtensionImageName = &imageName
default:
continue
}
extensions = append(extensions, lanExt)
}
return &clusters.LanguageExtensionsList{
Value: &extensions,
}
}
}
return nil
}

extensions := make([]clusters.LanguageExtension, 0)
for _, language := range input {
name := clusters.LanguageExtensionName(language.(string))
v := clusters.LanguageExtension{
LanguageExtensionName: &name,
func expandKustoClusterLanguageExtensionList(input []interface{}) *clusters.LanguageExtensionsList {
if len(input) > 0 {
extensions := make([]clusters.LanguageExtension, 0)
for _, ext := range input {
extMap := ext.(map[string]interface{})
name := clusters.LanguageExtensionName(extMap["name"].(string))
image := clusters.LanguageExtensionImageName(extMap["image"].(string))
lanExt := clusters.LanguageExtension{
LanguageExtensionName: &name,
LanguageExtensionImageName: &image,
}
extensions = append(extensions, lanExt)
}
return &clusters.LanguageExtensionsList{
Value: &extensions,
}
extensions = append(extensions, v)
}

return &clusters.LanguageExtensionsList{
Value: &extensions,
}
return nil
}

func flattenKustoClusterSku(sku *clusters.AzureSku) []interface{} {
Expand Down Expand Up @@ -653,29 +682,39 @@ func flattenKustoClusterLanguageExtensions(extensions *clusters.LanguageExtensio
output := make([]interface{}, 0)
if extensions.Value != nil {
for _, v := range *extensions.Value {
output = append(output, v.LanguageExtensionName)
if v.LanguageExtensionImageName != nil {
switch *v.LanguageExtensionImageName {
case clusters.LanguageExtensionImageNameR:
output = append(output, "R")
case clusters.LanguageExtensionImageNamePythonThreeSixFive:
output = append(output, "PYTHON")
case clusters.LanguageExtensionImageNamePythonThreeOneZeroEight:
output = append(output, "PYTHON_3.10.8")
}
}
}
}

return output
}

func diffLanguageExtensions(a, b []clusters.LanguageExtension) []clusters.LanguageExtension {
target := make(map[string]bool)
for _, x := range b {
if x.LanguageExtensionName != nil {
target[string(*x.LanguageExtensionName)] = true
}
func flattenKustoClusterLanguageExtensionList(extensions *clusters.LanguageExtensionsList) []interface{} {
if extensions == nil {
return []interface{}{}
}

diff := make([]clusters.LanguageExtension, 0)
for _, x := range a {
if x.LanguageExtensionName != nil {
if _, ok := target[string(*x.LanguageExtensionName)]; !ok {
diff = append(diff, x)
}
output := make([]interface{}, 0)
if extensions.Value != nil {
for _, v := range *extensions.Value {
output = append(
output,
map[string]interface{}{
"name": string(*v.LanguageExtensionName),
"image": string(*v.LanguageExtensionImageName),
},
)
}
}

return diff
return output
}
Loading

0 comments on commit 938514c

Please sign in to comment.