Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
Co-authored-by: stephybun <[email protected]>
  • Loading branch information
joshk0 and stephybun committed Jul 8, 2024
1 parent 7b7f1c0 commit 86c9289
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,15 @@ resource "azurerm_billing_account_cost_management_export" "test" {
recurrence_type = "Monthly"
recurrence_period_start_date = "%sT00:00:00Z"
recurrence_period_end_date = "%sT00:00:00Z"
partition_data_enabled = true
export_data_storage_location {
container_id = azurerm_storage_container.test.resource_manager_id
root_folder_path = "/root"
}
export_data_options {
data_version = "2019-11-01"
type = "Usage"
time_frame = "TheLastMonth"
type = "Usage"
time_frame = "TheLastMonth"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, billingAccount, start, end)
Expand Down Expand Up @@ -219,7 +217,7 @@ resource "azurerm_billing_account_cost_management_export" "import" {
recurrence_type = azurerm_billing_account_cost_management_export.test.recurrence_type
recurrence_period_start_date = azurerm_billing_account_cost_management_export.test.recurrence_period_start_date
recurrence_period_end_date = azurerm_billing_account_cost_management_export.test.recurrence_period_start_date
partition_data_enabled = azurerm_billing_account_cost_management_export.test.partition_data
partition_data_enabled = azurerm_billing_account_cost_management_export.test.partition_data
export_data_storage_location {
container_id = azurerm_storage_container.test.resource_manager_id
Expand Down
20 changes: 8 additions & 12 deletions internal/services/costmanagement/export_resource_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (br costManagementExportBaseResource) arguments(fields map[string]*pluginsd
"partition_data_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Required: false,
Default: false,
ForceNew: true,
},
Expand Down Expand Up @@ -108,16 +107,15 @@ func (br costManagementExportBaseResource) arguments(fields map[string]*pluginsd
string(exports.TimeframeTypeTheLastMonth),
string(exports.TimeframeTypeWeekToDate),
string(exports.TimeframeTypeMonthToDate),
string(exports.TimeframeTypeMonthToDate),
// TODO Use value from SDK after https://github.com/Azure/azure-rest-api-specs/issues/23707 is fixed
"TheLast7Days",
}, false),
},

"data_version": {
Type: pluginsdk.TypeString,
Optional: true,
Required: false,
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
Expand Down Expand Up @@ -189,9 +187,7 @@ func (br costManagementExportBaseResource) readFunc(scopeFieldName string) sdk.R

if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
if partitionData := props.PartitionData; partitionData != nil {
metadata.ResourceData.Set("partition_data_enabled", *partitionData)
}
metadata.ResourceData.Set("partition_data_enabled", pointer.From(props.PartitionData))

if schedule := props.Schedule; schedule != nil {
if recurrencePeriod := schedule.RecurrencePeriod; recurrencePeriod != nil {
Expand Down Expand Up @@ -291,7 +287,7 @@ func createOrUpdateCostManagementExport(ctx context.Context, client *exports.Exp
props := exports.Export{
ETag: etag,
Properties: &exports.ExportProperties{
PartitionData: pointer.FromBool(metadata.ResourceData.Get("partition_data_enabled").(bool)),
PartitionData: pointer.To(metadata.ResourceData.Get("partition_data_enabled").(bool)),
Schedule: &exports.ExportSchedule{
Recurrence: &recurrenceType,
RecurrencePeriod: &exports.ExportRecurrencePeriod{
Expand Down Expand Up @@ -346,7 +342,7 @@ func expandExportDefinition(input []interface{}) *exports.ExportDefinition {
if v, ok := attrs["data_version"]; ok {
dataset = &exports.ExportDataset{
Configuration: &exports.ExportDatasetConfiguration{
DataVersion: utils.String(v.(string)),
DataVersion: pointer.To(v.(string)),
},
}
}
Expand Down Expand Up @@ -405,8 +401,8 @@ func flattenExportDefinition(input *exports.ExportDefinition) []interface{} {
}

version := ""
if input.DataSet != nil && input.DataSet.Configuration != nil && input.DataSet.Configuration.DataVersion != nil {
version = *input.DataSet.Configuration.DataVersion
if input.DataSet != nil && input.DataSet.Configuration != nil {
version = pointer.From(input.DataSet.Configuration.DataVersion)
}

return []interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,12 @@ resource "azurerm_resource_group_cost_management_export" "test" {
recurrence_type = "Monthly"
recurrence_period_start_date = "%sT00:00:00Z"
recurrence_period_end_date = "%sT00:00:00Z"
partition_data_enabled = true
export_data_storage_location {
container_id = azurerm_storage_container.test.resource_manager_id
root_folder_path = "/root"
}
export_data_options {
data_version = "2019-11-01"
type = "Usage"
time_frame = "TheLastMonth"
}
Expand Down Expand Up @@ -173,7 +171,6 @@ resource "azurerm_resource_group_cost_management_export" "test" {
recurrence_type = "Monthly"
recurrence_period_start_date = "%sT00:00:00Z"
recurrence_period_end_date = "%sT00:00:00Z"
partition_data_enabled = true
export_data_storage_location {
container_id = azurerm_storage_container.test.resource_manager_id
Expand All @@ -199,15 +196,13 @@ resource "azurerm_resource_group_cost_management_export" "import" {
recurrence_type = azurerm_resource_group_cost_management_export.test.recurrence_type
recurrence_period_start_date = azurerm_resource_group_cost_management_export.test.recurrence_period_start_date
recurrence_period_end_date = azurerm_resource_group_cost_management_export.test.recurrence_period_start_date
partition_data_enabled = azurerm_resource_group_cost_management_export.test.partition_data
export_data_storage_location {
container_id = azurerm_storage_container.test.resource_manager_id
root_folder_path = "/root"
}
export_data_options {
data_version = "2019-11-01"
type = "Usage"
time_frame = "TheLastMonth"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ resource "azurerm_subscription_cost_management_export" "test" {
recurrence_type = "Monthly"
recurrence_period_start_date = "%sT00:00:00Z"
recurrence_period_end_date = "%sT00:00:00Z"
partition_data_enabled = true
export_data_storage_location {
container_id = azurerm_storage_container.test.resource_manager_id
root_folder_path = "/root"
}
export_data_options {
data_version = "2019-11-01"
type = "Usage"
time_frame = "TheLastMonth"
}
Expand Down Expand Up @@ -210,15 +208,13 @@ resource "azurerm_subscription_cost_management_export" "import" {
recurrence_type = azurerm_subscription_cost_management_export.test.recurrence_type
recurrence_period_start_date = azurerm_subscription_cost_management_export.test.recurrence_period_start_date
recurrence_period_end_date = azurerm_subscription_cost_management_export.test.recurrence_period_start_date
partition_data_enabled = azurerm_subscription_cost_management_export.test.partition_data
export_data_storage_location {
container_id = azurerm_storage_container.test.resource_manager_id
root_folder_path = "/root"
}
export_data_options {
data_version = "2019-11-01"
type = "Usage"
time_frame = "TheLastMonth"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The following arguments are supported:

* `billing_account_id` - (Required) The id of the billing account on which to create an export. Changing this forces a new resource to be created.

* `partition_data_enabled` - (Optional) Whether data will be partitioned into smaller files to facilitate consumption.
* `partition_data_enabled` - (Optional) Whether data will be partitioned into smaller files to facilitate consumption. Changing this forces a new resource to be created. Defaults to `false`.

* `recurrence_type` - (Required) How often the requested information will be exported. Valid values include `Annually`, `Daily`, `Monthly`, `Weekly`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The following arguments are supported:

* `resource_group_id` - (Required) The id of the resource group on which to create an export. Changing this forces a new resource to be created.

* `partition_data_enabled` - (Optional) Whether data will be partitioned into smaller files to facilitate consumption.
* `partition_data_enabled` - (Optional) Whether data will be partitioned into smaller files to facilitate consumption. Changing this forces a new resource to be created. Defaults to `false`.

* `recurrence_type` - (Required) How often the requested information will be exported. Valid values include `Annually`, `Daily`, `Monthly`, `Weekly`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The following arguments are supported:

* `subscription_id` - (Required) The id of the subscription on which to create an export. Changing this forces a new resource to be created.

* `partition_data_enabled` - (Optional) Whether data will be partitioned into smaller files to facilitate consumption.
* `partition_data_enabled` - (Optional) Whether data will be partitioned into smaller files to facilitate consumption. Changing this forces a new resource to be created. Defaults to `false`.

* `recurrence_type` - (Required) How often the requested information will be exported. Valid values include `Annually`, `Daily`, `Monthly`, `Weekly`.

Expand Down

0 comments on commit 86c9289

Please sign in to comment.