Skip to content
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

AWS_CE_COST_CATEGORY: be able to use nested operands like you can via aws api #30862

Conversation

huetterma
Copy link
Contributor

Description

AWS Cost Categories allows nested operands by default. Confirmed by their source code:

type Expression struct {
	_ struct{} `type:"structure"`

	// Return results that match both Dimension objects.
	And []*Expression `type:"list"`

	// The filter that's based on CostCategory values.
	CostCategories *CostCategoryValues `type:"structure"`

	// The specific Dimension to use for Expression.
	Dimensions *DimensionValues `type:"structure"`

	// Return results that don't match a Dimension object.
	Not *Expression `type:"structure"`

	// Return results that match either Dimension object.
	Or []*Expression `type:"list"`

	// The specific Tag to use for Expression.
	Tags *TagValues `type:"structure"`
}

As you can see all three operands not, and and or having the Expression type which allows for combination like this via AWS API

"Rules":[{
  "Rule":{
    "And":[
      {"Not":{"Dimensions":{"Key":"RECORD_TYPE","MatchOptions":["EQUALS"],"Values":["Tax"]}}},
      {"Dimensions":{"Key":"LINKED_ACCOUNT","MatchOptions":["EQUALS"],"Values":["##########","########"]}}
    ]
  },
 "Type":"REGULAR","Value":"taxexclusion"}]

This example could not be created via Terraform because the schema for the operand only allows to be of tags, dimension or cost_category, schema, eligible expression for and/or/not

This PR would allow to create the corresponding AWS API JSON and constructs like this:

rule {
    value = "taxexclusion"
    rule {
      and {
        dimension {
          key           = "LINKED_ACCOUNT_NAME"
          values      = ["########", "######"]
          match_options = ["EQUALS"]
        }
      }
      and {
        not {
          dimension {
            key           = "RECORD_TYPE"
            values        = ["Tax"]
            match_options = ["EQUALS"]
          }
        }
	  }
    }
    type = "REGULAR"

TODO

Correct value for maximum operand nesting, code variable costCategoryRuleMaxNesting

Relations

Closes #30810

References

References are included in the Description

Output from Acceptance Testing

$ make testacc TESTS=TestAccXXX PKG=ec2

...

@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added service/ce Issues and PRs that pertain to the ce service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/L Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. labels Apr 21, 2023
@huetterma huetterma force-pushed the b-aws_ce_cost_category-nested-operands-closes-30810 branch 3 times, most recently from 5fbc6e4 to bbeae66 Compare April 21, 2023 13:02
@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Apr 25, 2023
@huetterma
Copy link
Contributor Author

Hey,
@ewbankkit @justinretzolk

Would be glad, if we could work out a solution together to implement this. It is actually blocking for us.

We have to decide the max nesting factor, or come up with another solution. Glad to hear your ideas.

@huetterma huetterma force-pushed the b-aws_ce_cost_category-nested-operands-closes-30810 branch from 00c0fd1 to 5f33f02 Compare June 30, 2023 09:45
@bebold-jhr
Copy link

Hello @justinretzolk,

any chance someone can have a look at this PR?

@justinretzolk
Copy link
Member

Hey @bebold-jhr 👋 Thank you for checking in on this! Unfortunately I can't provide an ETA on when this will be reviewed/merged due to the potential of shifting priorities. We prioritize by count of 👍 reactions and a few other things (more information on our prioritization guide if you're interested).

@smokingroosters
Copy link

Any update on this?

Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccCE' PKG=ce ACCTEST_PARALLELISM=2        
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.21.8 test ./internal/service/ce/... -v -count 1 -parallel 2  -run=TestAccCE -timeout 360m
=== RUN   TestAccCEAnomalyMonitor_basic
=== PAUSE TestAccCEAnomalyMonitor_basic
=== RUN   TestAccCEAnomalyMonitor_disappears
=== PAUSE TestAccCEAnomalyMonitor_disappears
=== RUN   TestAccCEAnomalyMonitor_update
=== PAUSE TestAccCEAnomalyMonitor_update
=== RUN   TestAccCEAnomalyMonitor_tags
=== PAUSE TestAccCEAnomalyMonitor_tags
=== RUN   TestAccCEAnomalyMonitor_Dimensional
=== PAUSE TestAccCEAnomalyMonitor_Dimensional
=== RUN   TestAccCEAnomalySubscription_basic
=== PAUSE TestAccCEAnomalySubscription_basic
=== RUN   TestAccCEAnomalySubscription_disappears
=== PAUSE TestAccCEAnomalySubscription_disappears
=== RUN   TestAccCEAnomalySubscription_Frequency
=== PAUSE TestAccCEAnomalySubscription_Frequency
=== RUN   TestAccCEAnomalySubscription_MonitorARNList
=== PAUSE TestAccCEAnomalySubscription_MonitorARNList
=== RUN   TestAccCEAnomalySubscription_Subscriber
=== PAUSE TestAccCEAnomalySubscription_Subscriber
=== RUN   TestAccCEAnomalySubscription_Tags
=== PAUSE TestAccCEAnomalySubscription_Tags
=== RUN   TestAccCECostAllocationTag_basic
=== PAUSE TestAccCECostAllocationTag_basic
=== RUN   TestAccCECostAllocationTag_disappears
=== PAUSE TestAccCECostAllocationTag_disappears
=== RUN   TestAccCECostCategoryDataSource_basic
=== PAUSE TestAccCECostCategoryDataSource_basic
=== RUN   TestAccCECostCategory_basic
=== PAUSE TestAccCECostCategory_basic
=== RUN   TestAccCECostCategory_effectiveStart
=== PAUSE TestAccCECostCategory_effectiveStart
=== RUN   TestAccCECostCategory_disappears
=== PAUSE TestAccCECostCategory_disappears
=== RUN   TestAccCECostCategory_complete
=== PAUSE TestAccCECostCategory_complete
=== RUN   TestAccCECostCategory_notWithAnd
=== PAUSE TestAccCECostCategory_notWithAnd
=== RUN   TestAccCECostCategory_splitCharge
=== PAUSE TestAccCECostCategory_splitCharge
=== RUN   TestAccCECostCategory_tags
=== PAUSE TestAccCECostCategory_tags
=== RUN   TestAccCETagsDataSource_basic
=== PAUSE TestAccCETagsDataSource_basic
=== RUN   TestAccCETagsDataSource_filter
=== PAUSE TestAccCETagsDataSource_filter
=== CONT  TestAccCEAnomalyMonitor_basic
=== CONT  TestAccCECostAllocationTag_disappears
--- PASS: TestAccCECostAllocationTag_disappears (17.73s)
=== CONT  TestAccCECostCategory_notWithAnd
--- PASS: TestAccCEAnomalyMonitor_basic (20.82s)
=== CONT  TestAccCETagsDataSource_filter
--- PASS: TestAccCETagsDataSource_filter (18.06s)
=== CONT  TestAccCETagsDataSource_basic
--- PASS: TestAccCECostCategory_notWithAnd (21.40s)
=== CONT  TestAccCECostCategory_tags
--- PASS: TestAccCETagsDataSource_basic (17.80s)
=== CONT  TestAccCECostCategory_splitCharge
--- PASS: TestAccCECostCategory_tags (48.39s)
=== CONT  TestAccCECostCategory_complete
--- PASS: TestAccCECostCategory_splitCharge (38.68s)
=== CONT  TestAccCEAnomalySubscription_disappears
--- PASS: TestAccCEAnomalySubscription_disappears (24.32s)
=== CONT  TestAccCECostAllocationTag_basic
--- PASS: TestAccCECostCategory_complete (42.97s)
=== CONT  TestAccCEAnomalySubscription_Tags
--- PASS: TestAccCECostAllocationTag_basic (49.41s)
=== CONT  TestAccCEAnomalySubscription_Subscriber
--- PASS: TestAccCEAnomalySubscription_Tags (50.47s)
=== CONT  TestAccCEAnomalySubscription_MonitorARNList
--- PASS: TestAccCEAnomalySubscription_MonitorARNList (38.38s)
=== CONT  TestAccCEAnomalySubscription_Frequency
--- PASS: TestAccCEAnomalySubscription_Subscriber (76.40s)
=== CONT  TestAccCECostCategory_basic
--- PASS: TestAccCEAnomalySubscription_Frequency (40.98s)
=== CONT  TestAccCECostCategoryDataSource_basic
--- PASS: TestAccCECostCategory_basic (26.32s)
=== CONT  TestAccCECostCategory_disappears
--- PASS: TestAccCECostCategoryDataSource_basic (20.93s)
=== CONT  TestAccCEAnomalyMonitor_tags
--- PASS: TestAccCECostCategory_disappears (20.40s)
=== CONT  TestAccCEAnomalySubscription_basic
--- PASS: TestAccCEAnomalySubscription_basic (23.99s)
=== CONT  TestAccCEAnomalyMonitor_Dimensional
--- PASS: TestAccCEAnomalyMonitor_tags (53.34s)
=== CONT  TestAccCEAnomalyMonitor_update
--- PASS: TestAccCEAnomalyMonitor_Dimensional (25.53s)
=== CONT  TestAccCEAnomalyMonitor_disappears
--- PASS: TestAccCEAnomalyMonitor_disappears (18.06s)
=== CONT  TestAccCECostCategory_effectiveStart
--- PASS: TestAccCEAnomalyMonitor_update (35.88s)
--- PASS: TestAccCECostCategory_effectiveStart (35.40s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ce	406.679s

@ewbankkit ewbankkit added bug Addresses a defect in current functionality. and removed bug Addresses a defect in current functionality. labels Apr 19, 2024
@ewbankkit
Copy link
Contributor

@huetterma Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit 6e64c8e into hashicorp:main Apr 19, 2024
25 checks passed
@github-actions github-actions bot added this to the v5.47.0 milestone Apr 19, 2024
Copy link

This functionality has been released in v5.47.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ce Issues and PRs that pertain to the ce service. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Usage of 'not' block in aws_ce_cost_category throws error
5 participants