-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add fields to azurerm_*_cost_management_export
: partition_data
and export_data_options.data_version
#26219
Open
joshk0
wants to merge
4
commits into
hashicorp:main
Choose a base branch
from
TernaryInc:exports-add-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add fields to azurerm_*_cost_management_export
: partition_data
and export_data_options.data_version
#26219
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2021-10-01/exports" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2023-07-01-preview/exports" | ||
"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" | ||
|
@@ -39,6 +39,25 @@ func TestAccBillingAccountCostManagementExport_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccBillingAccountCostManagementExport_complete(t *testing.T) { | ||
if os.Getenv("ARM_BILLING_ACCOUNT") == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Subscriptions are supported as well |
||
t.Skip("skipping tests - no billing account data provided") | ||
} | ||
|
||
data := acceptance.BuildTestData(t, "azurerm_billing_account_cost_management_export", "test") | ||
r := BillingAccountCostManagementExport{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.complete(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}) | ||
} | ||
|
||
func TestAccBillingAccountCostManagementExport_update(t *testing.T) { | ||
if os.Getenv("ARM_BILLING_ACCOUNT") == "" { | ||
t.Skip("skipping tests - no billing account data provided") | ||
|
@@ -146,7 +165,7 @@ resource "azurerm_billing_account_cost_management_export" "test" { | |
|
||
export_data_storage_location { | ||
container_id = azurerm_storage_container.test.resource_manager_id | ||
root_folder_path = "/root" | ||
root_folder_path = "root" | ||
} | ||
|
||
export_data_options { | ||
|
@@ -157,6 +176,56 @@ resource "azurerm_billing_account_cost_management_export" "test" { | |
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, billingAccount, start, end) | ||
} | ||
|
||
func (BillingAccountCostManagementExport) complete(data acceptance.TestData) string { | ||
start := time.Now().AddDate(0, 0, 1).Format("2006-01-02") | ||
end := time.Now().AddDate(0, 0, 2).Format("2006-01-02") | ||
billingAccount := os.Getenv("ARM_BILLING_ACCOUNT") | ||
return fmt.Sprintf(` | ||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-cm-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_storage_account" "test" { | ||
name = "unlikely23exst2acct%s" | ||
resource_group_name = azurerm_resource_group.test.name | ||
|
||
location = azurerm_resource_group.test.location | ||
account_tier = "Standard" | ||
account_replication_type = "LRS" | ||
} | ||
|
||
resource "azurerm_storage_container" "test" { | ||
name = "acctestcontainer%s" | ||
storage_account_name = azurerm_storage_account.test.name | ||
} | ||
|
||
resource "azurerm_billing_account_cost_management_export" "test" { | ||
name = "accs%d" | ||
billing_account_id = "%s" | ||
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 { | ||
type = "Usage" | ||
time_frame = "TheLastMonth" | ||
data_version = "2021-10-01" | ||
} | ||
} | ||
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, billingAccount, start, end) | ||
} | ||
|
||
func (BillingAccountCostManagementExport) update(data acceptance.TestData) string { | ||
start := time.Now().AddDate(0, 3, 0).Format("2006-01-02") | ||
end := time.Now().AddDate(0, 4, 0).Format("2006-01-02") | ||
|
@@ -194,12 +263,12 @@ resource "azurerm_billing_account_cost_management_export" "test" { | |
|
||
export_data_storage_location { | ||
container_id = azurerm_storage_container.test.resource_manager_id | ||
root_folder_path = "/root/updated" | ||
root_folder_path = "root/updated" | ||
} | ||
|
||
export_data_options { | ||
type = "Usage" | ||
time_frame = "WeekToDate" | ||
type = "Usage" | ||
time_frame = "WeekToDate" | ||
} | ||
} | ||
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, billingAccount, start, end) | ||
|
@@ -216,15 +285,17 @@ 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 | ||
|
||
export_data_storage_location { | ||
container_id = azurerm_storage_container.test.resource_manager_id | ||
root_folder_path = "/root" | ||
root_folder_path = "root" | ||
} | ||
|
||
export_data_options { | ||
type = "Usage" | ||
time_frame = "TheLastMonth" | ||
data_version = "2019-11-01" | ||
type = "Usage" | ||
time_frame = "TheLastMonth" | ||
} | ||
} | ||
`, template) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import ( | |
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"github.com/hashicorp/go-azure-helpers/lang/response" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2021-10-01/exports" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2023-07-01-preview/exports" | ||
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
|
@@ -29,6 +29,13 @@ func (br costManagementExportBaseResource) arguments(fields map[string]*pluginsd | |
Default: true, | ||
}, | ||
|
||
"partition_data_enabled": { | ||
Type: pluginsdk.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
ForceNew: true, | ||
}, | ||
|
||
"recurrence_type": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
|
@@ -104,6 +111,12 @@ func (br costManagementExportBaseResource) arguments(fields map[string]*pluginsd | |
"TheLast7Days", | ||
}, false), | ||
}, | ||
|
||
"data_version": { | ||
joshk0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should be optional. I'm pretty sure it's required unless the API is defaulting. |
||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -174,6 +187,8 @@ func (br costManagementExportBaseResource) readFunc(scopeFieldName string) sdk.R | |
|
||
if model := resp.Model; model != nil { | ||
if props := model.Properties; props != nil { | ||
metadata.ResourceData.Set("partition_data_enabled", pointer.From(props.PartitionData)) | ||
|
||
if schedule := props.Schedule; schedule != nil { | ||
if recurrencePeriod := schedule.RecurrencePeriod; recurrencePeriod != nil { | ||
metadata.ResourceData.Set("recurrence_period_start_date", recurrencePeriod.From) | ||
|
@@ -272,6 +287,7 @@ func createOrUpdateCostManagementExport(ctx context.Context, client *exports.Exp | |
props := exports.Export{ | ||
ETag: etag, | ||
Properties: &exports.ExportProperties{ | ||
PartitionData: pointer.To(metadata.ResourceData.Get("partition_data_enabled").(bool)), | ||
Schedule: &exports.ExportSchedule{ | ||
Recurrence: &recurrenceType, | ||
RecurrencePeriod: &exports.ExportRecurrencePeriod{ | ||
|
@@ -321,7 +337,18 @@ func expandExportDefinition(input []interface{}) *exports.ExportDefinition { | |
} | ||
|
||
attrs := input[0].(map[string]interface{}) | ||
var dataset *exports.ExportDataset | ||
|
||
if v, ok := attrs["data_version"]; ok { | ||
dataset = &exports.ExportDataset{ | ||
Configuration: &exports.ExportDatasetConfiguration{ | ||
DataVersion: pointer.To(v.(string)), | ||
}, | ||
} | ||
} | ||
|
||
definitionInfo := &exports.ExportDefinition{ | ||
DataSet: dataset, | ||
Type: exports.ExportType(attrs["type"].(string)), | ||
Timeframe: exports.TimeframeType(attrs["time_frame"].(string)), | ||
} | ||
|
@@ -373,10 +400,14 @@ func flattenExportDefinition(input *exports.ExportDefinition) []interface{} { | |
queryType = string(input.Type) | ||
} | ||
|
||
return []interface{}{ | ||
map[string]interface{}{ | ||
"time_frame": string(input.Timeframe), | ||
"type": queryType, | ||
}, | ||
result := map[string]interface{}{ | ||
"time_frame": string(input.Timeframe), | ||
"type": queryType, | ||
} | ||
|
||
if input.DataSet != nil && input.DataSet.Configuration != nil && input.DataSet.Configuration.DataVersion != nil { | ||
result["data_version"] = pointer.From(input.DataSet.Configuration.DataVersion) | ||
} | ||
|
||
return []interface{}{result} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably keep the old version as well. I believe there are some gaps between what's supported in each version.
@jojohpm would know more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have a provision to keep 2 versions, then we could keep both.
2021-10-01 = Exports v1. Legacy exports.
2023-07-01-preview = Exports v2. The new one with file partitioning, compression, file format, newer datasets etc... This is going to be the default experience going forward.