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

azurerm_log_analytics_linked_storage_account - fix data_source_type case sensitivity #18116

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ package loganalytics
import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/linkedstorageaccounts"
"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"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceLogAnalyticsLinkedStorageAccountCreateUpdate,
Read: resourceLogAnalyticsLinkedStorageAccountRead,
Update: resourceLogAnalyticsLinkedStorageAccountCreateUpdate,
Expand All @@ -42,13 +43,12 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
strings.ToLower(string(linkedstorageaccounts.DataSourceTypeCustomLogs)),
strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAzureWatson)),
strings.ToLower(string(linkedstorageaccounts.DataSourceTypeQuery)),
strings.ToLower(string(linkedstorageaccounts.DataSourceTypeAlerts)),
// Value removed from enum in 2020-08-01, but effectively still works
"ingestion",
}, false),
string(linkedstorageaccounts.DataSourceTypeCustomLogs),
string(linkedstorageaccounts.DataSourceTypeAzureWatson),
string(linkedstorageaccounts.DataSourceTypeQuery),
string(linkedstorageaccounts.DataSourceTypeAlerts),
string(linkedstorageaccounts.DataSourceTypeIngestion),
}, !features.FourPointOhBeta()),
},

"resource_group_name": azure.SchemaResourceGroupName(),
Expand All @@ -71,6 +71,12 @@ func resourceLogAnalyticsLinkedStorageAccount() *pluginsdk.Resource {
},
},
}

if !features.FourPointOh() {
resource.Schema["data_source_type"].DiffSuppressFunc = suppress.CaseDifference
}

return resource
}

func resourceLogAnalyticsLinkedStorageAccountCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -131,6 +137,7 @@ func resourceLogAnalyticsLinkedStorageAccountRead(d *pluginsdk.ResourceData, met

d.Set("resource_group_name", id.ResourceGroupName)
d.Set("workspace_resource_id", linkedstorageaccounts.NewWorkspaceID(id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName).ID())
d.Set("data_source_type", string(id.DataSourceType))
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this is part of the id, we might want to do a state migration so we can remove the parse insensitively above?


if model := resp.Model; model != nil {
props := model.Properties
Expand All @@ -139,13 +146,6 @@ func resourceLogAnalyticsLinkedStorageAccountRead(d *pluginsdk.ResourceData, met
storageAccountIds = *props.StorageAccountIds
}
d.Set("storage_account_ids", storageAccountIds)

dataSourceType := ""
if props.DataSourceType != nil {
dataSourceType = string(*props.DataSourceType)
}
d.Set("data_source_type", dataSourceType)

}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"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/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
Expand Down Expand Up @@ -143,7 +144,8 @@ resource "azurerm_storage_account" "test" {
}

func (r LogAnalyticsLinkedStorageAccountResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
if !features.FourPointOh() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be required because we're ignoring case till 4.0?

return fmt.Sprintf(`
%s

resource "azurerm_log_analytics_linked_storage_account" "test" {
Expand All @@ -152,6 +154,18 @@ resource "azurerm_log_analytics_linked_storage_account" "test" {
workspace_resource_id = azurerm_log_analytics_workspace.test.id
storage_account_ids = [azurerm_storage_account.test.id]
}
`, r.template(data))
}

return fmt.Sprintf(`
%s

resource "azurerm_log_analytics_linked_storage_account" "test" {
data_source_type = "CustomLogs"
resource_group_name = azurerm_resource_group.test.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id
storage_account_ids = [azurerm_storage_account.test.id]
}
`, r.template(data))
}

Expand All @@ -169,7 +183,8 @@ resource "azurerm_log_analytics_linked_storage_account" "import" {
}

func (r LogAnalyticsLinkedStorageAccountResource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
if !features.FourPointOh() {
return fmt.Sprintf(`
%s

resource "azurerm_storage_account" "test2" {
Expand All @@ -186,6 +201,26 @@ resource "azurerm_log_analytics_linked_storage_account" "test" {
workspace_resource_id = azurerm_log_analytics_workspace.test.id
storage_account_ids = [azurerm_storage_account.test.id, azurerm_storage_account.test2.id]
}
`, r.template(data), data.RandomString)
}

return fmt.Sprintf(`
%s

resource "azurerm_storage_account" "test2" {
name = "acctestsas%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "GRS"
}

resource "azurerm_log_analytics_linked_storage_account" "test" {
data_source_type = "CustomLogs"
resource_group_name = azurerm_resource_group.test.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id
storage_account_ids = [azurerm_storage_account.test.id, azurerm_storage_account.test2.id]
}
`, r.template(data), data.RandomString)
}

Expand All @@ -194,7 +229,7 @@ func (r LogAnalyticsLinkedStorageAccountResource) ingestion(data acceptance.Test
%s

resource "azurerm_log_analytics_linked_storage_account" "test" {
data_source_type = "ingestion"
data_source_type = "Ingestion"
resource_group_name = azurerm_resource_group.test.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id
storage_account_ids = [azurerm_storage_account.test.id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resource "azurerm_log_analytics_workspace" "example" {
}

resource "azurerm_log_analytics_linked_storage_account" "example" {
data_source_type = "customlogs"
data_source_type = "CustomLogs"
resource_group_name = azurerm_resource_group.example.name
workspace_resource_id = azurerm_log_analytics_workspace.example.id
storage_account_ids = [azurerm_storage_account.example.id]
Expand All @@ -45,7 +45,9 @@ resource "azurerm_log_analytics_linked_storage_account" "example" {

The following arguments are supported:

* `data_source_type` - (Required) The data source type which should be used for this Log Analytics Linked Storage Account. Possible values are `customlogs`, `azurewatson`, `query`, `ingestion` and `alerts`. Changing this forces a new Log Analytics Linked Storage Account to be created.
* `data_source_type` - (Required) The data source type which should be used for this Log Analytics Linked Storage Account. Possible values are `CustomLogs`, `AzureWatson`, `Query`, `Ingestion` and `Alerts`. Changing this forces a new Log Analytics Linked Storage Account to be created.

> **Note:** The `data_source_type` is case-insensitive in current 3.x version. And in 4.0 or later versions, Case-sensitivity will be required.

* `resource_group_name` - (Required) The name of the Resource Group where the Log Analytics Linked Storage Account should exist. Changing this forces a new Log Analytics Linked Storage Account to be created.

Expand Down