From aab6a94c81295193e7e8f1d6783b1051206efb6c Mon Sep 17 00:00:00 2001 From: ned1313 Date: Wed, 21 Aug 2024 09:21:58 -0400 Subject: [PATCH 1/5] add file format argument --- .../costmanagement/export_resource_base.go | 16 +++++++++++++++- .../export_resource_group_resource_test.go | 2 ++ ..._account_cost_management_export.html.markdown | 3 +++ ...ce_group_cost_management_export.html.markdown | 3 +++ ...cription_cost_management_export.html.markdown | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/services/costmanagement/export_resource_base.go b/internal/services/costmanagement/export_resource_base.go index 577625cd4381..39a68adef489 100644 --- a/internal/services/costmanagement/export_resource_base.go +++ b/internal/services/costmanagement/export_resource_base.go @@ -52,6 +52,16 @@ func (br costManagementExportBaseResource) arguments(fields map[string]*pluginsd ValidateFunc: validation.IsRFC3339Time, }, + "file_format": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(exports.FormatTypeCsv), + ValidateFunc: validation.StringInSlice([]string{ + string(exports.FormatTypeCsv), + // TODO add support for Parquet once added to the SDK + }, false), + }, + "export_data_storage_location": { Type: pluginsdk.TypeList, MaxItems: 1, @@ -195,6 +205,9 @@ func (br costManagementExportBaseResource) readFunc(scopeFieldName string) sdk.R if err := metadata.ResourceData.Set("export_data_options", flattenExportDefinition(&props.Definition)); err != nil { return fmt.Errorf("setting `export_data_options`: %+v", err) } + if format := props.Format; format != nil { + metadata.ResourceData.Set("file_format", format) + } } } @@ -267,7 +280,8 @@ func createOrUpdateCostManagementExport(ctx context.Context, client *exports.Exp return fmt.Errorf("expanding `export_data_storage_location`: %+v", err) } - format := exports.FormatTypeCsv + format := exports.FormatType(metadata.ResourceData.Get("file_format").(string)) + recurrenceType := exports.RecurrenceType(metadata.ResourceData.Get("recurrence_type").(string)) props := exports.Export{ ETag: etag, diff --git a/internal/services/costmanagement/export_resource_group_resource_test.go b/internal/services/costmanagement/export_resource_group_resource_test.go index 91992dda2743..ba6265d0fcd2 100644 --- a/internal/services/costmanagement/export_resource_group_resource_test.go +++ b/internal/services/costmanagement/export_resource_group_resource_test.go @@ -127,6 +127,7 @@ 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" + file_format = "Csv" export_data_storage_location { container_id = azurerm_storage_container.test.resource_manager_id @@ -171,6 +172,7 @@ 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" + file_format = "Csv" export_data_storage_location { container_id = azurerm_storage_container.test.resource_manager_id diff --git a/website/docs/r/billing_account_cost_management_export.html.markdown b/website/docs/r/billing_account_cost_management_export.html.markdown index e361193b324b..ba0f3ffbcd88 100644 --- a/website/docs/r/billing_account_cost_management_export.html.markdown +++ b/website/docs/r/billing_account_cost_management_export.html.markdown @@ -39,6 +39,7 @@ resource "azurerm_billing_account_cost_management_export" "example" { recurrence_type = "Monthly" recurrence_period_start_date = "2020-08-18T00:00:00Z" recurrence_period_end_date = "2020-09-18T00:00:00Z" + file_format = "Csv" export_data_storage_location { container_id = azurerm_storage_container.example.resource_manager_id @@ -72,6 +73,8 @@ The following arguments are supported: * `active` - (Optional) Is the cost management export active? Default is `true`. +* * `file_format` - (Optional) Format for export. Valid values are `Csv` only. Default is `Csv`. + --- A `export_data_storage_location` block supports the following: diff --git a/website/docs/r/resource_group_cost_management_export.html.markdown b/website/docs/r/resource_group_cost_management_export.html.markdown index c817a748e337..80e2b6692a52 100644 --- a/website/docs/r/resource_group_cost_management_export.html.markdown +++ b/website/docs/r/resource_group_cost_management_export.html.markdown @@ -38,6 +38,7 @@ resource "azurerm_resource_group_cost_management_export" "example" { recurrence_type = "Monthly" recurrence_period_start_date = "2020-08-18T00:00:00Z" recurrence_period_end_date = "2020-09-18T00:00:00Z" + file_format = "Csv" export_data_storage_location { container_id = azurerm_storage_container.example.resource_manager_id @@ -71,6 +72,8 @@ The following arguments are supported: * `active` - (Optional) Is the cost management export active? Default is `true`. +* `file_format` - (Optional) Format for export. Valid values are `Csv` only. Default is `Csv`. + --- A `export_data_storage_location` block supports the following: diff --git a/website/docs/r/subscription_cost_management_export.html.markdown b/website/docs/r/subscription_cost_management_export.html.markdown index c815fd0c23d7..e960fddba167 100644 --- a/website/docs/r/subscription_cost_management_export.html.markdown +++ b/website/docs/r/subscription_cost_management_export.html.markdown @@ -40,6 +40,7 @@ resource "azurerm_subscription_cost_management_export" "example" { recurrence_type = "Monthly" recurrence_period_start_date = "2020-08-18T00:00:00Z" recurrence_period_end_date = "2020-09-18T00:00:00Z" + file_format = "Csv" export_data_storage_location { container_id = azurerm_storage_container.example.resource_manager_id @@ -73,6 +74,8 @@ The following arguments are supported: * `active` - (Optional) Is the cost management export active? Default is `true`. +* `file_format` - (Optional) Format for export. Valid values are `Csv` only. Default is `Csv`. + --- A `export_data_storage_location` block supports the following: From 3a234bfb47e061937db91d6c01498f6974e50805 Mon Sep 17 00:00:00 2001 From: ned1313 Date: Wed, 21 Aug 2024 09:36:41 -0400 Subject: [PATCH 2/5] make fmt --- .../services/costmanagement/export_resource_base.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/services/costmanagement/export_resource_base.go b/internal/services/costmanagement/export_resource_base.go index 39a68adef489..f91df1b3cb96 100644 --- a/internal/services/costmanagement/export_resource_base.go +++ b/internal/services/costmanagement/export_resource_base.go @@ -54,12 +54,12 @@ func (br costManagementExportBaseResource) arguments(fields map[string]*pluginsd "file_format": { Type: pluginsdk.TypeString, - Optional: true, - Default: string(exports.FormatTypeCsv), - ValidateFunc: validation.StringInSlice([]string{ - string(exports.FormatTypeCsv), - // TODO add support for Parquet once added to the SDK - }, false), + Optional: true, + Default: string(exports.FormatTypeCsv), + ValidateFunc: validation.StringInSlice([]string{ + string(exports.FormatTypeCsv), + // TODO add support for Parquet once added to the SDK + }, false), }, "export_data_storage_location": { From 3e8ab8771df798dbddf8e48f5c04706b31bdbc60 Mon Sep 17 00:00:00 2001 From: ned1313 Date: Wed, 21 Aug 2024 09:58:51 -0400 Subject: [PATCH 3/5] Extract value from format pointer --- internal/services/costmanagement/export_resource_base.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/costmanagement/export_resource_base.go b/internal/services/costmanagement/export_resource_base.go index f91df1b3cb96..3111502c7993 100644 --- a/internal/services/costmanagement/export_resource_base.go +++ b/internal/services/costmanagement/export_resource_base.go @@ -206,7 +206,7 @@ func (br costManagementExportBaseResource) readFunc(scopeFieldName string) sdk.R return fmt.Errorf("setting `export_data_options`: %+v", err) } if format := props.Format; format != nil { - metadata.ResourceData.Set("file_format", format) + metadata.ResourceData.Set("file_format", string(pointer.From(format))) } } } From 6a9c5b21af447c3b356ed5e21ca63a381a6a1b3c Mon Sep 17 00:00:00 2001 From: Ned Bellavance Date: Tue, 17 Dec 2024 14:14:36 -0500 Subject: [PATCH 4/5] Update internal/services/costmanagement/export_resource_group_resource_test.go Co-authored-by: stephybun --- .../costmanagement/export_resource_group_resource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/costmanagement/export_resource_group_resource_test.go b/internal/services/costmanagement/export_resource_group_resource_test.go index ba6265d0fcd2..eba68bbd8cff 100644 --- a/internal/services/costmanagement/export_resource_group_resource_test.go +++ b/internal/services/costmanagement/export_resource_group_resource_test.go @@ -127,7 +127,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" - file_format = "Csv" export_data_storage_location { container_id = azurerm_storage_container.test.resource_manager_id From aacfa364133a6836e7979886af66624baa5a575f Mon Sep 17 00:00:00 2001 From: Ned Bellavance Date: Tue, 17 Dec 2024 14:14:46 -0500 Subject: [PATCH 5/5] Update internal/services/costmanagement/export_resource_base.go Co-authored-by: stephybun --- internal/services/costmanagement/export_resource_base.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/services/costmanagement/export_resource_base.go b/internal/services/costmanagement/export_resource_base.go index 3111502c7993..138857271288 100644 --- a/internal/services/costmanagement/export_resource_base.go +++ b/internal/services/costmanagement/export_resource_base.go @@ -205,9 +205,7 @@ func (br costManagementExportBaseResource) readFunc(scopeFieldName string) sdk.R if err := metadata.ResourceData.Set("export_data_options", flattenExportDefinition(&props.Definition)); err != nil { return fmt.Errorf("setting `export_data_options`: %+v", err) } - if format := props.Format; format != nil { - metadata.ResourceData.Set("file_format", string(pointer.From(format))) - } + metadata.ResourceData.Set("file_format", string(pointer.From(props.Format))) } }