From d8c25175eebe2e1b86617f678f1edf937251c112 Mon Sep 17 00:00:00 2001 From: Jochen Rauschenbusch Date: Sun, 24 May 2020 15:55:48 +0200 Subject: [PATCH 1/3] Support for Kusto Cluster External Trusted Tenants --- azurerm/helpers/azure/kusto.go | 31 +++++++++++++++++++ .../services/kusto/kusto_cluster_resource.go | 17 ++++++++++ .../tests/kusto_cluster_resource_test.go | 1 + website/docs/r/kusto_cluster.html.markdown | 2 ++ 4 files changed, 51 insertions(+) diff --git a/azurerm/helpers/azure/kusto.go b/azurerm/helpers/azure/kusto.go index e77599b4fa3b..8dfc9a7bf77f 100644 --- a/azurerm/helpers/azure/kusto.go +++ b/azurerm/helpers/azure/kusto.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func SchemaKustoIdentity() *schema.Schema { @@ -89,3 +90,33 @@ func FlattenKustoIdentity(input *kusto.Identity) []interface{} { }, } } + +func ExpandKustoClusterTrustedExternalTenants(input []interface{}) *[]kusto.TrustedExternalTenant { + output := make([]kusto.TrustedExternalTenant, 0) + + for _, v := range input { + output = append(output, kusto.TrustedExternalTenant{ + Value: utils.String(v.(string)), + }) + } + + return &output +} + +func FlattenKustoClusterTrustedExternalTenants(input *[]kusto.TrustedExternalTenant) []interface{} { + if input == nil { + return []interface{}{} + } + + output := make([]interface{}, 0) + + for _, v := range *input { + if v.Value == nil { + continue + } + + output = append(output, *v.Value) + } + + return output +} diff --git a/azurerm/internal/services/kusto/kusto_cluster_resource.go b/azurerm/internal/services/kusto/kusto_cluster_resource.go index beeaac70010e..eecceb9d049e 100644 --- a/azurerm/internal/services/kusto/kusto_cluster_resource.go +++ b/azurerm/internal/services/kusto/kusto_cluster_resource.go @@ -95,6 +95,17 @@ func resourceArmKustoCluster() *schema.Resource { }, }, + "trusted_external_tenants": { + Type: schema.TypeList, + Optional: true, + Computed: true, + ConfigMode: schema.SchemaConfigModeAttr, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.Any(validation.IsUUID, validation.StringIsEmpty), + }, + }, + "enable_disk_encryption": { Type: schema.TypeBool, Optional: true, @@ -195,6 +206,11 @@ func resourceArmKustoClusterCreateUpdate(d *schema.ResourceData, meta interface{ clusterProperties.VirtualNetworkConfiguration = vnet } + if v, ok := d.GetOk("trusted_external_tenants"); ok { + trustedExternalTenants := azure.ExpandKustoClusterTrustedExternalTenants(v.([]interface{})) + clusterProperties.TrustedExternalTenants = trustedExternalTenants + } + t := d.Get("tags").(map[string]interface{}) kustoCluster := kusto.Cluster{ @@ -275,6 +291,7 @@ func resourceArmKustoClusterRead(d *schema.ResourceData, meta interface{}) error } if clusterProperties := clusterResponse.ClusterProperties; clusterProperties != nil { + d.Set("trusted_external_tenants", azure.FlattenKustoClusterTrustedExternalTenants(clusterProperties.TrustedExternalTenants)) d.Set("enable_disk_encryption", clusterProperties.EnableDiskEncryption) d.Set("enable_streaming_ingest", clusterProperties.EnableStreamingIngest) d.Set("enable_purge", clusterProperties.EnablePurge) diff --git a/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go b/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go index d00e29eb2811..dc1ac9570b95 100644 --- a/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go +++ b/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go @@ -24,6 +24,7 @@ func TestAccAzureRMKustoCluster_basic(t *testing.T) { Config: testAccAzureRMKustoCluster_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "trusted_external_tenants", "*"), ), }, data.ImportStep(), diff --git a/website/docs/r/kusto_cluster.html.markdown b/website/docs/r/kusto_cluster.html.markdown index 2ac81770333c..13e63f9d5f11 100644 --- a/website/docs/r/kusto_cluster.html.markdown +++ b/website/docs/r/kusto_cluster.html.markdown @@ -58,6 +58,8 @@ The following arguments are supported: * `tags` - (Optional) A mapping of tags to assign to the resource. +* `trusted_external_tenants` - (Optional) Specifies a list of tenant IDs that are trusted by the cluster. + * `zones` - (Optional) A list of Availability Zones in which the cluster instances should be created in. Changing this forces a new resource to be created. --- From 99e2f9b6b220bc5ad70ccee8680779d6e92eaeb1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Wed, 8 Jul 2020 12:09:35 -0700 Subject: [PATCH 2/3] fmt --- azurerm/internal/services/kusto/kusto_cluster_resource.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/kusto/kusto_cluster_resource.go b/azurerm/internal/services/kusto/kusto_cluster_resource.go index a07311f1e23f..398c5a3e36a5 100644 --- a/azurerm/internal/services/kusto/kusto_cluster_resource.go +++ b/azurerm/internal/services/kusto/kusto_cluster_resource.go @@ -104,9 +104,9 @@ func resourceArmKustoCluster() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validation.Any(validation.IsUUID, validation.StringIsEmpty), - }, + }, }, - + "optimized_auto_scale": { Type: schema.TypeList, Optional: true, From 1ce5d097a360be718104c3448262f745595a1ea8 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Wed, 8 Jul 2020 12:25:42 -0700 Subject: [PATCH 3/3] Update kusto_cluster_resource_test.go --- .../internal/services/kusto/tests/kusto_cluster_resource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go b/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go index f935f13ab262..78d8b741e8b1 100644 --- a/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go +++ b/azurerm/internal/services/kusto/tests/kusto_cluster_resource_test.go @@ -24,7 +24,6 @@ func TestAccAzureRMKustoCluster_basic(t *testing.T) { Config: testAccAzureRMKustoCluster_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKustoClusterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "trusted_external_tenants", "*"), ), }, data.ImportStep(),