Skip to content

Commit

Permalink
azurerm_billing_account_cost_management_export, `azurerm_resource_g…
Browse files Browse the repository at this point in the history
…roup_cost_management_export`, `azurerm_subscription_cost_management_export` adding property `file_format` (#27122)

* add file format argument

* make fmt

* Extract value from format pointer

* Update internal/services/costmanagement/export_resource_group_resource_test.go

Co-authored-by: stephybun <steph@hashicorp.com>

* Update internal/services/costmanagement/export_resource_base.go

Co-authored-by: stephybun <steph@hashicorp.com>

---------

Co-authored-by: stephybun <steph@hashicorp.com>
  • Loading branch information
ned1313 and stephybun authored Jan 8, 2025
1 parent e686181 commit c5b2f19
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/services/costmanagement/export_resource_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -195,6 +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)
}
metadata.ResourceData.Set("file_format", string(pointer.From(props.Format)))
}
}

Expand Down Expand Up @@ -267,7 +278,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c5b2f19

Please sign in to comment.