Skip to content

Commit

Permalink
storage - Parse Property Case Insensitively in Read
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o committed Feb 7, 2023
1 parent 2b67084 commit 248b6c0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
15 changes: 7 additions & 8 deletions internal/services/costmanagement/export_resource_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2021-10-01/exports"
"github.com/hashicorp/go-azure-sdk/resource-manager/storage/2022-05-01/blobcontainers"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
storageParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/parse"
storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/utils"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (br costManagementExportBaseResource) arguments(fields map[string]*pluginsd
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: storageValidate.StorageContainerResourceManagerID,
ValidateFunc: blobcontainers.ValidateContainerID,
},
"root_folder_path": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -292,12 +291,12 @@ func expandExportDataStorageLocation(input []interface{}) (*exports.ExportDelive
}
attrs := input[0].(map[string]interface{})

containerId, err := storageParse.StorageContainerResourceManagerID(attrs["container_id"].(string))
containerId, err := blobcontainers.ParseContainerID(attrs["container_id"].(string))
if err != nil {
return nil, err
}

storageId := storageParse.NewStorageAccountID(containerId.SubscriptionId, containerId.ResourceGroup, containerId.StorageAccountName)
storageId := blobcontainers.NewStorageAccountID(containerId.SubscriptionId, containerId.ResourceGroupName, containerId.StorageAccountName)

deliveryInfo := &exports.ExportDeliveryInfo{
Destination: exports.ExportDeliveryDestination{
Expand Down Expand Up @@ -331,18 +330,18 @@ func flattenExportDataStorageLocation(input *exports.ExportDeliveryInfo) ([]inte

destination := input.Destination
var err error
var storageAccountId *storageParse.StorageAccountId
var storageAccountId *blobcontainers.StorageAccountId

if v := destination.ResourceId; v != nil {
storageAccountId, err = storageParse.StorageAccountID(*v)
storageAccountId, err = blobcontainers.ParseStorageAccountIDInsensitively(*v)
if err != nil {
return nil, err
}
}

containerId := ""
if v := destination.Container; v != "" && storageAccountId != nil {
containerId = storageParse.NewStorageContainerResourceManagerID(storageAccountId.SubscriptionId, storageAccountId.ResourceGroup, storageAccountId.Name, "default", v).ID()
containerId = blobcontainers.NewContainerID(storageAccountId.SubscriptionId, storageAccountId.ResourceGroupName, storageAccountId.StorageAccountName, v).ID()
}

rootFolderPath := ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ 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/operationalinsights/2020-08-01/storageinsights"
"github.com/hashicorp/go-azure-sdk/resource-manager/storage/2022-05-01/storageaccounts"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loganalytics/validate"
storageParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/parse"
storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -131,7 +130,7 @@ func resourceLogAnalyticsStorageInsightsRead(d *pluginsdk.ResourceData, meta int

storageAccountIdStr := ""
if props.StorageAccount.Id != "" {
storageAccountId, err := storageParse.StorageAccountID(props.StorageAccount.Id)
storageAccountId, err := storageaccounts.ParseStorageAccountIDInsensitively(props.StorageAccount.Id)
if err != nil {
return err
}
Expand Down Expand Up @@ -190,7 +189,7 @@ func resourceLogAnalyticsStorageInsightsSchema() map[string]*pluginsdk.Schema {
"storage_account_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: storageValidate.StorageAccountID,
ValidateFunc: storageaccounts.ValidateStorageAccountID,
},

"storage_account_key": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
authRuleParse "github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/authorizationrulesnamespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/workspaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/storage/2022-05-01/storageaccounts"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/monitor/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/monitor/validate"
storageParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/parse"
storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -79,7 +78,7 @@ func resourceMonitorAADDiagnosticSetting() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: storageValidate.StorageAccountID,
ValidateFunc: storageaccounts.ValidateStorageAccountID,
AtLeastOneOf: []string{"eventhub_authorization_rule_id", "log_analytics_workspace_id", "storage_account_id"},
},

Expand Down Expand Up @@ -243,7 +242,7 @@ func resourceMonitorAADDiagnosticSettingRead(d *pluginsdk.ResourceData, meta int

storageAccountId := ""
if resp.StorageAccountID != nil && *resp.StorageAccountID != "" {
parsedId, err := storageParse.StorageAccountID(*resp.StorageAccountID)
parsedId, err := storageaccounts.ParseStorageAccountIDInsensitively(*resp.StorageAccountID)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import (
authRuleParse "github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/authorizationrulesnamespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings"
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/workspaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/storage/2022-05-01/storageaccounts"
"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/monitor/validate"
storageParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/parse"
storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -83,7 +82,7 @@ func resourceMonitorDiagnosticSetting() *pluginsdk.Resource {
"storage_account_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: storageValidate.StorageAccountID,
ValidateFunc: storageaccounts.ValidateStorageAccountID,
AtLeastOneOf: []string{"eventhub_authorization_rule_id", "log_analytics_workspace_id", "storage_account_id", "partner_solution_id"},
},

Expand Down Expand Up @@ -550,7 +549,7 @@ func resourceMonitorDiagnosticSettingRead(d *pluginsdk.ResourceData, meta interf

storageAccountId := ""
if props.StorageAccountId != nil && *props.StorageAccountId != "" {
parsedId, err := storageParse.StorageAccountID(*props.StorageAccountId)
parsedId, err := storageaccounts.ParseStorageAccountIDInsensitively(*props.StorageAccountId)
if err != nil {
return err
}
Expand Down

0 comments on commit 248b6c0

Please sign in to comment.