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

kusto_cluster_resource - allowed_fqdns, allowed_ip_ranges, outbound_network_access_restricted #17581

Merged
merged 9 commits into from
Jul 20, 2022
82 changes: 79 additions & 3 deletions internal/services/kusto/kusto_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,43 @@ func resourceKustoCluster() *pluginsdk.Resource {
string(kusto.AzureSkuNameStandardD12V2),
string(kusto.AzureSkuNameStandardD13V2),
string(kusto.AzureSkuNameStandardD14V2),
string(kusto.AzureSkuNameStandardD16dV5),
string(kusto.AzureSkuNameStandardD32dV4),
string(kusto.AzureSkuNameStandardD32dV5),
string(kusto.AzureSkuNameStandardDS13V21TBPS),
string(kusto.AzureSkuNameStandardDS13V22TBPS),
string(kusto.AzureSkuNameStandardDS14V23TBPS),
string(kusto.AzureSkuNameStandardDS14V24TBPS),
string(kusto.AzureSkuNameStandardE16aV4),
string(kusto.AzureSkuNameStandardE16adsV5),
string(kusto.AzureSkuNameStandardE16asV43TBPS),
string(kusto.AzureSkuNameStandardE16asV44TBPS),
string(kusto.AzureSkuNameStandardE16aV4),
string(kusto.AzureSkuNameStandardE16asV53TBPS),
string(kusto.AzureSkuNameStandardE16asV54TBPS),
string(kusto.AzureSkuNameStandardE16sV43TBPS),
string(kusto.AzureSkuNameStandardE16sV44TBPS),
string(kusto.AzureSkuNameStandardE16sV53TBPS),
string(kusto.AzureSkuNameStandardE16sV54TBPS),
string(kusto.AzureSkuNameStandardE2aV4),
string(kusto.AzureSkuNameStandardE2adsV5),
string(kusto.AzureSkuNameStandardE4aV4),
string(kusto.AzureSkuNameStandardE4adsV5),
string(kusto.AzureSkuNameStandardE64iV3),
string(kusto.AzureSkuNameStandardE80idsV4),
string(kusto.AzureSkuNameStandardE8aV4),
string(kusto.AzureSkuNameStandardE8adsV5),
string(kusto.AzureSkuNameStandardE8asV41TBPS),
string(kusto.AzureSkuNameStandardE8asV42TBPS),
string(kusto.AzureSkuNameStandardE8aV4),
string(kusto.AzureSkuNameStandardE8asV51TBPS),
string(kusto.AzureSkuNameStandardE8asV52TBPS),
string(kusto.AzureSkuNameStandardE8sV41TBPS),
string(kusto.AzureSkuNameStandardE8sV42TBPS),
string(kusto.AzureSkuNameStandardE8sV51TBPS),
string(kusto.AzureSkuNameStandardE8sV52TBPS),
string(kusto.AzureSkuNameStandardL16s),
string(kusto.AzureSkuNameStandardL16sV2),
string(kusto.AzureSkuNameStandardL4s),
string(kusto.AzureSkuNameStandardL8s),
string(kusto.AzureSkuNameStandardL16sV2),
string(kusto.AzureSkuNameStandardL8sV2),
}, false),
},
Expand All @@ -108,6 +128,24 @@ func resourceKustoCluster() *pluginsdk.Resource {
},
},

"allowed_fqdns": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
},
},

"allowed_ip_ranges": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
},
},

"trusted_external_tenants": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -213,6 +251,12 @@ func resourceKustoCluster() *pluginsdk.Resource {
Default: true,
},

"outbound_network_access_restricted": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"double_encryption_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -334,6 +378,21 @@ func resourceKustoClusterCreateUpdate(d *pluginsdk.ResourceData, meta interface{
clusterProperties.VirtualNetworkConfiguration = vnet
}

if v, ok := d.GetOk("allowed_fqdns"); ok {
clusterProperties.AllowedFqdnList, _ = expandKustoListString(v.([]interface{}))
}

if v, ok := d.GetOk("allowed_ip_ranges"); ok {
clusterProperties.AllowedIPRangeList, _ = expandKustoListString(v.([]interface{}))
}

clusterProperties.RestrictOutboundNetworkAccess = kusto.ClusterNetworkAccessFlagDisabled
if v, ok := d.GetOk("outbound_network_access_restricted"); ok {
if v.(bool) {
clusterProperties.RestrictOutboundNetworkAccess = kusto.ClusterNetworkAccessFlagEnabled
}
}

expandedIdentity, err := expandClusterIdentity(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
Expand Down Expand Up @@ -451,6 +510,8 @@ func resourceKustoClusterRead(d *pluginsdk.ResourceData, meta interface{}) error
}

if props := resp.ClusterProperties; props != nil {
d.Set("allowed_fqdns", props.AllowedFqdnList)
d.Set("allowed_ip_ranges", props.AllowedIPRangeList)
d.Set("double_encryption_enabled", props.EnableDoubleEncryption)
d.Set("trusted_external_tenants", flattenTrustedExternalTenants(props.TrustedExternalTenants))
d.Set("auto_stop_enabled", props.EnableAutoStop)
Expand All @@ -463,6 +524,7 @@ func resourceKustoClusterRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("data_ingestion_uri", props.DataIngestionURI)
d.Set("engine", props.EngineType)
d.Set("public_ip_type", props.PublicIPType)
d.Set("outbound_network_access_restricted", props.RestrictOutboundNetworkAccess == kusto.ClusterNetworkAccessFlagEnabled)
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down Expand Up @@ -529,6 +591,20 @@ func flattenOptimizedAutoScale(optimizedAutoScale *kusto.OptimizedAutoscale) []i
}
}

func expandKustoListString(input []interface{}) (*[]string, error) {
if input == nil || len(input) == 0 {
return nil, fmt.Errorf("list of string is empty")
}

result := make([]string, 0)

for _, v := range input {
result = append(result, v.(string))
}

return &result, nil
}

func expandKustoClusterSku(input []interface{}) (*kusto.AzureSku, error) {
sku := input[0].(map[string]interface{})
name := sku["name"].(string)
Expand Down
18 changes: 13 additions & 5 deletions internal/services/kusto/kusto_cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func TestAccKustoCluster_complete(t *testing.T) {
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("allowed_fqdns.#").HasValue("1"),
check.That(data.ResourceName).Key("allowed_fqdns.0").HasValue("255.255.255.0/24"),
check.That(data.ResourceName).Key("allowed_ip_ranges.#").HasValue("1"),
check.That(data.ResourceName).Key("allowed_ip_ranges.0").HasValue("0.0.0.0/0"),
check.That(data.ResourceName).Key("outbound_network_access_restricted").HasValue("true"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -399,11 +404,14 @@ resource "azurerm_resource_group" "test" {
}

resource "azurerm_kusto_cluster" "test" {
name = "acctestkc%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
public_network_access_enabled = false
public_ip_type = "DualStack"
name = "acctestkc%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allowed_fqdns = ["255.255.255.0/24"]
allowed_ip_ranges = ["0.0.0.0/0"]
public_network_access_enabled = false
public_ip_type = "DualStack"
outbound_network_access_restricted = true
sku {
name = "Standard_D13_v2"
capacity = 2
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/kusto_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ The following arguments are supported:

* `sku` - (Required) A `sku` block as defined below.

* `allowed_fqdns` - (Optional) List of allowed FQDNs(Fully Qualified Domain Name) for egress from Cluster.

* `allowed_ip_ranges` - (Optional) The list of ips in the format of CIDR allowed to connect to the cluster.

* `double_encryption_enabled` - (Optional) Is the cluster's double encryption enabled? Defaults to `false`. Changing this forces a new resource to be created.

* `identity` - (Optional) An `identity` block as defined below.
Expand All @@ -60,6 +64,8 @@ The following arguments are supported:

* `public_network_access_enabled` - (Optional) Is the public network access enabled? Defaults to `true`.

* `outbound_network_access_restricted` - (Optional) Whether to restrict outbound network access. Value is optional but if passed in, must be `true` or `false`, default is `false`.

* `purge_enabled` - (Optional) Specifies if the purge operations are enabled.

* `virtual_network_configuration`- (Optional) A `virtual_network_configuration` block as defined below. Changing this forces a new resource to be created.
Expand Down