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

Resolve 4.0 TODOs Kusto #28530

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9dc4b66
Resolve 4.0 TODOs Kusto
wyattfry Jan 16, 2025
154d6f3
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Jan 27, 2025
b2790d3
proper deprecation
wyattfry Jan 27, 2025
526fc6a
imports sorted
wyattfry Jan 27, 2025
c173974
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Jan 28, 2025
46ea78e
wip
wyattfry Jan 29, 2025
a916c7a
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Feb 3, 2025
b998109
cleanup
wyattfry Feb 3, 2025
c7685b0
removed unneeded
wyattfry Feb 3, 2025
c28adb7
docs
wyattfry Feb 3, 2025
af70f5b
tests
wyattfry Feb 3, 2025
7959930
fix
wyattfry Feb 3, 2025
a0947ee
implementing read changes
wyattfry Feb 3, 2025
28d1212
fixes
wyattfry Feb 3, 2025
1542311
add computed
wyattfry Feb 3, 2025
6518a8c
fmt
wyattfry Feb 4, 2025
e506264
fmt
wyattfry Feb 4, 2025
e02c82c
Apply suggestions from code review
wyattfry Feb 4, 2025
f2ce1b6
pr feedback
wyattfry Feb 4, 2025
a4e0cca
more tests for deprecated props
wyattfry Feb 4, 2025
e6ff5a7
fmt
wyattfry Feb 4, 2025
7e2f085
fixed removed property
wyattfry Feb 4, 2025
0b0ba06
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Feb 4, 2025
86b38f8
kusto update
wyattfry Feb 6, 2025
b34e6f1
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Feb 6, 2025
9fa73be
fmt
wyattfry Feb 6, 2025
2d8615e
WIP
wyattfry Feb 7, 2025
d8acb96
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Feb 8, 2025
34b378a
fix
wyattfry Feb 8, 2025
09b2b79
fmt
wyattfry Feb 8, 2025
66898e1
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Feb 12, 2025
c3221c9
feedback
wyattfry Feb 12, 2025
6c1245d
feedback
wyattfry Feb 14, 2025
4b5487b
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Feb 14, 2025
623a4d3
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
wyattfry Feb 17, 2025
51f0dee
Apply suggestions from code review
wyattfry Feb 17, 2025
1385604
Merge branch 'wyatt/todos-4-0-kusto' of https://github.com/hashicorp/…
wyattfry Feb 17, 2025
a64811d
sorted import
wyattfry Feb 17, 2025
2e88d79
5.0 wrap
wyattfry Feb 18, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2023-08-15/attacheddatabaseconfigurations"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"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/validate"
Expand All @@ -24,7 +25,7 @@ import (
)

func resourceKustoAttachedDatabaseConfiguration() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceKustoAttachedDatabaseConfigurationCreateUpdate,
Read: resourceKustoAttachedDatabaseConfigurationRead,
Update: resourceKustoAttachedDatabaseConfigurationCreateUpdate,
Expand Down Expand Up @@ -73,8 +74,7 @@ func resourceKustoAttachedDatabaseConfiguration() *pluginsdk.Resource {
ValidateFunc: validation.Any(validate.DatabaseName, validation.StringInSlice([]string{"*"}, false)),
},

// TODO: this should become `cluster_id` in 4.0
"cluster_resource_id": {
"cluster_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
Expand Down Expand Up @@ -154,6 +154,27 @@ func resourceKustoAttachedDatabaseConfiguration() *pluginsdk.Resource {
},
},
}

if !features.FivePointOh() {
resource.Schema["cluster_id"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"cluster_id", "cluster_resource_id"},
ValidateFunc: commonids.ValidateKustoClusterID,
}
resource.Schema["cluster_resource_id"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to what Steph said here, we'll have to remove ForceNew here as well for when people move from cluster_resource_id to cluster_id as cluster_resource_id will have to be removed which will cause ForceNew to trigger

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see, thanks!

ValidateFunc: commonids.ValidateKustoClusterID,
Deprecated: "`cluster_resource_id` has been deprecated in favour of the `cluster_id` property and will be removed in v5.0 of the AzureRM Provider.",
ExactlyOneOf: []string{"cluster_id", "cluster_resource_id"},
}
}

return resource
}

func resourceKustoAttachedDatabaseConfigurationCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -223,11 +244,15 @@ func resourceKustoAttachedDatabaseConfigurationRead(d *pluginsdk.ResourceData, m
if parseErr != nil {
return parseErr
}
d.Set("cluster_resource_id", clusterResourceId.ID())
d.Set("cluster_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))

if !features.FivePointOh() {
d.Set("cluster_resource_id", clusterResourceId.ID())
}
}
}

Expand Down Expand Up @@ -259,7 +284,11 @@ func resourceKustoAttachedDatabaseConfigurationDelete(d *pluginsdk.ResourceData,
func expandKustoAttachedDatabaseConfigurationProperties(d *pluginsdk.ResourceData) *attacheddatabaseconfigurations.AttachedDatabaseConfigurationProperties {
AttachedDatabaseConfigurationProperties := &attacheddatabaseconfigurations.AttachedDatabaseConfigurationProperties{}

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

if clusterResourceID, ok := d.GetOk("cluster_resource_id"); !features.FivePointOh() && ok {
AttachedDatabaseConfigurationProperties.ClusterResourceId = clusterResourceID.(string)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/features"

wyattfry marked this conversation as resolved.
Show resolved Hide resolved
"github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2023-08-15/attacheddatabaseconfigurations"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
Expand All @@ -32,6 +34,24 @@ func TestAccKustoAttachedDatabaseConfiguration_basic(t *testing.T) {
})
}

func TestAccKustoAttachedDatabaseConfiguration_clusterResourceId(t *testing.T) {
if features.FivePointOh() {
t.Skip()
}
data := acceptance.BuildTestData(t, "azurerm_kusto_attached_database_configuration", "test")
r := KustoAttachedDatabaseConfigurationResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.clusterResourceId(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (KustoAttachedDatabaseConfigurationResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := attacheddatabaseconfigurations.ParseAttachedDatabaseConfigurationID(state.ID)
if err != nil {
Expand Down Expand Up @@ -104,7 +124,74 @@ resource "azurerm_kusto_attached_database_configuration" "test" {
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
cluster_name = azurerm_kusto_cluster.cluster1.name
cluster_resource_id = azurerm_kusto_cluster.cluster2.id
cluster_id = azurerm_kusto_cluster.cluster2.id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to ensure that we haven't introduced any regressions to how the deprecated property behaves now and should still validate that is works as expected until it's removed in the next major version, so we might want to add another test and test configuration just for the deprecated property.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger. Added a test TestAccKustoAttachedDatabaseConfiguration_clusterResourceId()

database_name = azurerm_kusto_database.test.name

sharing {
external_tables_to_exclude = ["ExternalTable2"]
external_tables_to_include = ["ExternalTable1"]
materialized_views_to_exclude = ["MaterializedViewTable2"]
materialized_views_to_include = ["MaterializedViewTable1"]
tables_to_exclude = ["Table2"]
tables_to_include = ["Table1"]
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KustoAttachedDatabaseConfigurationResource) clusterResourceId(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "rg" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_kusto_cluster" "cluster1" {
name = "acctestkc1%s"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

sku {
name = "Dev(No SLA)_Standard_D11_v2"
capacity = 1
}
}

resource "azurerm_kusto_cluster" "cluster2" {
name = "acctestkc2%s"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

sku {
name = "Dev(No SLA)_Standard_D11_v2"
capacity = 1
}
}

resource "azurerm_kusto_database" "followed_database" {
name = "acctestkd-%d"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
cluster_name = azurerm_kusto_cluster.cluster1.name
}

resource "azurerm_kusto_database" "test" {
name = "acctestkd2-%d"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
cluster_name = azurerm_kusto_cluster.cluster2.name
}

resource "azurerm_kusto_attached_database_configuration" "test" {
name = "acctestka-%d"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
cluster_name = azurerm_kusto_cluster.cluster1.name
cluster_resource_id = azurerm_kusto_cluster.cluster2.id ### <-- Testing this deprecated property
database_name = azurerm_kusto_database.test.name

sharing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ resource "azurerm_storage_account" "test" {

resource "azurerm_storage_container" "test" {
name = "setup-files"
storage_account_name = azurerm_storage_account.test.name
storage_account_id = azurerm_storage_account.test.id
container_access_type = "private"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"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/features"
eventhubValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/validate"
Expand All @@ -29,7 +30,7 @@ import (
)

func resourceKustoEventGridDataConnection() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceKustoEventGridDataConnectionCreateUpdate,
Update: resourceKustoEventGridDataConnectionCreateUpdate,
Read: resourceKustoEventGridDataConnectionRead,
Expand Down Expand Up @@ -138,15 +139,13 @@ func resourceKustoEventGridDataConnection() *pluginsdk.Resource {
ValidateFunc: validation.StringInSlice(dataconnections.PossibleValuesForDatabaseRouting(), false),
},

// TODO: rename this to `eventgrid_event_subscription_id` in 4.0
"eventgrid_resource_id": {
"eventgrid_event_subscription_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: eventsubscriptions.ValidateScopedEventSubscriptionID,
},

// TODO: rename this to `managed_identity_id` in 4.0
"managed_identity_resource_id": {
"managed_identity_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.Any(
Expand All @@ -156,6 +155,35 @@ func resourceKustoEventGridDataConnection() *pluginsdk.Resource {
},
},
}

if !features.FivePointOh() {
resource.Schema["eventgrid_resource_id"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: eventsubscriptions.ValidateScopedEventSubscriptionID,
Deprecated: "`eventgrid_resource_id` has been deprecated in favour of the `eventgrid_event_subscription_id` property and will be removed in v5.0 of the AzureRM Provider.",
ConflictsWith: []string{"eventgrid_event_subscription_id"},
}
resource.Schema["eventgrid_event_subscription_id"].ConflictsWith = []string{"eventgrid_resource_id"}
resource.Schema["eventgrid_event_subscription_id"].Computed = true

resource.Schema["managed_identity_resource_id"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.Any(
commonids.ValidateKustoClusterID,
commonids.ValidateUserAssignedIdentityID,
),
Deprecated: "`managed_identity_resource_id` has been deprecated in favour of the `managed_identity_id` property and will be removed in v5.0 of the AzureRM Provider.",
ConflictsWith: []string{"managed_identity_id"},
}
resource.Schema["managed_identity_id"].ConflictsWith = []string{"managed_identity_resource_id"}
resource.Schema["managed_identity_id"].Computed = true
}

return resource
}

func resourceKustoEventGridDataConnectionCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -211,11 +239,19 @@ func resourceKustoEventGridDataConnectionCreateUpdate(d *pluginsdk.ResourceData,
dataConnection.Properties.DatabaseRouting = &databaseRoutingType
}

if eventGridRID, ok := d.GetOk("eventgrid_resource_id"); ok {
if eventGridRID, ok := d.GetOk("eventgrid_event_subscription_id"); ok {
dataConnection.Properties.EventGridResourceId = utils.String(eventGridRID.(string))
}

if eventGridRID, ok := d.GetOk("eventgrid_resource_id"); !features.FivePointOh() && ok {
dataConnection.Properties.EventGridResourceId = utils.String(eventGridRID.(string))
}

if managedIdentityRID, ok := d.GetOk("managed_identity_resource_id"); ok {
if managedIdentityRID, ok := d.GetOk("managed_identity_id"); ok {
dataConnection.Properties.ManagedIdentityResourceId = utils.String(managedIdentityRID.(string))
}

if managedIdentityRID, ok := d.GetOk("managed_identity_resource_id"); !features.FivePointOh() && ok {
dataConnection.Properties.ManagedIdentityResourceId = utils.String(managedIdentityRID.(string))
}

Expand Down Expand Up @@ -266,7 +302,11 @@ func resourceKustoEventGridDataConnectionRead(d *pluginsdk.ResourceData, meta in
d.Set("mapping_rule_name", props.MappingRuleName)
d.Set("data_format", string(pointer.From(props.DataFormat)))
d.Set("database_routing_type", string(pointer.From(props.DatabaseRouting)))
d.Set("eventgrid_resource_id", props.EventGridResourceId)
d.Set("eventgrid_event_subscription_id", props.EventGridResourceId)

if !features.FivePointOh() {
d.Set("eventgrid_resource_id", props.EventGridResourceId)
}

managedIdentityResourceId := ""
if props.ManagedIdentityResourceId != nil && *props.ManagedIdentityResourceId != "" {
Expand All @@ -279,11 +319,16 @@ func resourceKustoEventGridDataConnectionRead(d *pluginsdk.ResourceData, meta in
if userAssignedIdentityIdErr == nil {
managedIdentityResourceId = userAssignedIdentityId.ID()
} else {
return fmt.Errorf("parsing `managed_identity_resource_id`: %+v; %+v", clusterIdErr, userAssignedIdentityIdErr)
return fmt.Errorf("parsing `managed_identity_id`: %+v; %+v", clusterIdErr, userAssignedIdentityIdErr)
}
}
}
d.Set("managed_identity_resource_id", managedIdentityResourceId)

d.Set("managed_identity_id", managedIdentityResourceId)

if !features.FivePointOh() {
d.Set("managed_identity_resource_id", managedIdentityResourceId)
}
}
}
}
Expand Down
Loading
Loading