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

feat!: Budget module should support filtering on labels #627

Merged
merged 5 commits into from
Feb 18, 2022
Merged

feat!: Budget module should support filtering on labels #627

merged 5 commits into from
Feb 18, 2022

Conversation

tpdownes
Copy link
Member

@tpdownes tpdownes commented Sep 30, 2021

This PR adds the ability to support creating budgets that track spending filtered by labels on GCP resources. There is a single CI error that traces to a separate repo. The error will be revised once this PR is accepted (and maybe tagged as well):

terraform-google-modules/terraform-google-vpc-service-controls#65

@bharathkkb
Copy link
Member

@tpdownes
Copy link
Member Author

tpdownes commented Nov 9, 2021

@bharathkkb I'll give it a shot. Thanks for poking me here and on a few other related threads.

@tpdownes
Copy link
Member Author

@bharathkkb It appears to me that this was merged into the GA and beta providers simultaneously at versions 4.1.0. The CFT modules don't yet support 4.x. If I trace the PRs, the only thing I can find that is an example of what should work is a unit test that does:

  budget_filter {
    projects = ["projects/${data.google_project.project.number}"]
    labels  = {
      label = "bar"
    }
  }

Is this the only supported format? A map from string to string with only 1 element?

@bharathkkb
Copy link
Member

@tpdownes #636 will allow the module to use 4.0+

@tpdownes
Copy link
Member Author

tpdownes commented Dec 9, 2021

@tpdownes
Copy link
Member Author

Note: GoogleCloudPlatform/magic-modules#5545 probably means provider v4.5 will support modifying budget filters with labels. Will test once available.

Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

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

You will also need to bump the provider version used in examples

modules/budget/variables.tf Show resolved Hide resolved
@tpdownes tpdownes marked this pull request as ready for review January 5, 2022 17:00
@tpdownes tpdownes requested a review from a team as a code owner January 5, 2022 17:00
@tpdownes
Copy link
Member Author

tpdownes commented Jan 5, 2022

@tpdownes
Copy link
Member Author

@bharathkkb I believe that I've addressed your concerns and that this is ready to go

Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Lets also expose this via the main module maybe as budget_labels?

@@ -48,4 +48,5 @@ module "additional_budget" {
services = var.budget_services
alert_spent_percents = var.budget_alert_spent_percents
alert_pubsub_topic = "projects/${module.budget_project.project_id}/topics/${google_pubsub_topic.budget.name}"
labels = var.budget_labels
Copy link
Member

Choose a reason for hiding this comment

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

Lets hardcode this in examples

Suggested change
labels = var.budget_labels
labels = {
"cost-center" : "dept-x"
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done on HEAD

examples/simple_project/versions.tf Outdated Show resolved Hide resolved
@bharathkkb bharathkkb changed the title Budget module should support filtering on labels feat!: Budget module should support filtering on labels Jan 18, 2022
@tpdownes
Copy link
Member Author

@bharathkkb I think this now merits a review

Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

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

Minor comments but overall LGTM. We can merge this with out next breaking release.

locals {
perimeter_name = "regular_service_perimeter_${var.random_string_for_testing}"
}

module "regular_service_perimeter_1" {
source = "terraform-google-modules/vpc-service-controls/google//modules/regular_service_perimeter"
source = "github.com/terraform-google-modules/terraform-google-vpc-service-controls//modules/regular_service_perimeter"
Copy link
Member

Choose a reason for hiding this comment

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

Can we open an issue to track revert of this in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

You want me to do this before PR is merged?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it makes the most sense to open this issue immediately after PR is closed to ensure I point to the right commit hash to revert. I've left this specific change as its own commit.

examples/shared_vpc/main.tf Outdated Show resolved Hide resolved
examples/group_project/versions.tf Outdated Show resolved Hide resolved
@tpdownes
Copy link
Member Author

tpdownes commented Feb 9, 2022

@bharathkkb I think the conversations are ready to be resolved. Can you do another review? I will open issue once you confirm that the PR is ready to go or if you merge it.

* Update all examples and tests to allow version 4.x of Terraform provider
* Bump required version of Google provider to ~> 4.5 for submodules, examples
  and tests that use budget submodule
@comment-bot-dev
Copy link

@tpdownes
Thanks for the PR! 🚀
✅ Lint checks have passed.

@bharathkkb
Copy link
Member

Test failure looks unrelated

@bharathkkb bharathkkb merged commit 44a9fec into terraform-google-modules:master Feb 18, 2022
@tpdownes tpdownes deleted the billing_labels branch February 18, 2022 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants