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(subscription): add subscription budgets. #352

Merged
merged 10 commits into from
Apr 10, 2024

Conversation

nyanhp
Copy link
Contributor

@nyanhp nyanhp commented Mar 20, 2024

Overview/summary

This PR adds the ability to define cost management budgets for a subscription, excluding filters.

This PR fixes/adds/changes/removes

  1. fixes feat: budget support #64

Breaking changes

None

Testing evidence

I am not familiar enough with Go to have added tests. I tested instead in my environment.

# module.lz_vending["subname"].module.subscription[0].azapi_resource.subscription_budget["budget1"] will be created
  + resource "azapi_resource" "subscription_budget" {
      + body                      = jsonencode(
            {
              + properties = {
                  + amount        = 150
                  + category      = "Cost"
                  + notifications = {
                      + eightypercent = {
                          + contactEmails = [
                              + "[email protected]",
                            ]
                          + contactGroups = []
                          + contactRoles  = []
                          + enabled       = true
                          + locale        = "en-us"
                          + operator      = "GreaterThan"
                          + threshold     = 80
                          + thresholdType = "Actual"
                        }
                      + forecast      = {
                          + contactEmails = [
                              + "[email protected]",
                            ]
                          + contactGroups = []
                          + contactRoles  = []
                          + enabled       = true
                          + locale        = "en-us"
                          + operator      = "GreaterThanOrEqualTo"
                          + threshold     = 290
                          + thresholdType = "Forecasted"
                        }
                      + ninetypercent = {
                          + contactEmails = [
                              + "[email protected]",
                            ]
                          + contactGroups = []
                          + contactRoles  = []
                          + enabled       = true
                          + locale        = "en-us"
                          + operator      = "GreaterThanOrEqualTo"
                          + threshold     = 90
                          + thresholdType = "Actual"
                        }
                    }
                  + timeGrain     = "Monthly"
                  + timePeriod    = {
                      + endDate   = "2027-12-31T23:59:59Z"
                      + startDate = "2024-05-01T00:00:00Z"
                    }
                }
            }
        )
      + id                        = (known after apply)
      + ignore_casing             = false
      + ignore_missing_property   = true
      + location                  = (known after apply)
      + name                      = "budget1"
      + output                    = (known after apply)
      + parent_id                 = "/subscriptions/nope"
      + removing_special_chars    = false
      + schema_validation_enabled = true
      + tags                      = (known after apply)
      + type                      = "Microsoft.Consumption/budgets@2021-10-01"
    }

  # module.lz_vending["subname"].module.subscription[0].azapi_resource.subscription_budget["budget2"] will be created
  + resource "azapi_resource" "subscription_budget" {
      + body                      = jsonencode(
            {
              + properties = {
                  + amount        = 1500
                  + category      = "Cost"
                  + notifications = {
                      + eightypercent = {
                          + contactEmails = [
                              + "[email protected]",
                            ]
                          + contactGroups = []
                          + contactRoles  = []
                          + enabled       = true
                          + locale        = "en-us"
                          + operator      = "GreaterThan"
                          + threshold     = 80
                          + thresholdType = "Actual"
                        }
                      + forecast      = {
                          + contactEmails = [
                              + "[email protected]",
                            ]
                          + contactGroups = []
                          + contactRoles  = []
                          + enabled       = true
                          + locale        = "en-us"
                          + operator      = "GreaterThanOrEqualTo"
                          + threshold     = 290
                          + thresholdType = "Forecasted"
                        }
                      + ninetypercent = {
                          + contactEmails = [
                              + "[email protected]",
                            ]
                          + contactGroups = []
                          + contactRoles  = []
                          + enabled       = true
                          + locale        = "en-us"
                          + operator      = "GreaterThanOrEqualTo"
                          + threshold     = 90
                          + thresholdType = "Actual"
                        }
                    }
                  + timeGrain     = "Annually"
                  + timePeriod    = {
                      + endDate   = "2027-12-31T23:59:59Z"
                      + startDate = "2024-05-01T00:00:00Z"
                    }
                }
            }
        )
      + id                        = (known after apply)
      + ignore_casing             = false
      + ignore_missing_property   = true
      + location                  = (known after apply)
      + name                      = "budget2"
      + output                    = (known after apply)
      + parent_id                 = "/subscriptions/nope"
      + removing_special_chars    = false
      + schema_validation_enabled = true
      + tags                      = (known after apply)
      + type                      = "Microsoft.Consumption/budgets@2021-10-01"
    }

Apply was successfully completed, e.g.:
image

As part of this pull request I have

  • Checked for duplicate Pull Requests
  • Associated it with relevant issues, for tracking and closure.
  • Run and make fmt & make docs to format your code and update documentation.
  • Created unit and deployment tests and provided evidence.
  • Updated relevant and associated documentation.

@nyanhp nyanhp requested a review from a team as a code owner March 20, 2024 14:03
enabled = bool
operator = string # EqualTo, GreaterThan, GreaterThanOrEqualTo
threshold = number # 0-1000 percent
thresholdType = string # Actual, Forecasted
Copy link
Contributor

Choose a reason for hiding this comment

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

Question for the team - does it make sense to have this interface "look" like azurerm - e.g. the input name would be camel-cased, like "threshold_type", and the ones below like "contact_emails" etc.

My thoughts are if we do switch out the implementation for an AzureRM version, the interface will remain the same.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, the inputs for all terraform modules should be snake case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will add unnecessary work (in my opinion) and requires re-assembling all notifications just to bring them into the correct format for the azapi body

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't consider it unnecessary, it is something that needs to be once in the module to support creating a more consistent interface should the implementation change. It doesnt put burden on the module consumers.

It is similar to what has been done for container app managed envs, for example

https://github.com/Azure/terraform-azurerm-avm-res-app-managedenvironment/blob/main/main.tf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added local to transform the notification map.

Copy link
Member

@jaredfholgate jaredfholgate left a comment

Choose a reason for hiding this comment

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

Thank you very much for submitting this PR. I appreciate this ask is extra work, but the consistency of naming conventions will be beneficial in the longer term. Thanks

modules/subscription/main.tf Outdated Show resolved Hide resolved
variables.subscription.tf Outdated Show resolved Hide resolved
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Author Feedback ✏️ Needs the author to provide feedback label Mar 27, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Author Feedback ✏️ Needs the author to provide feedback label Mar 28, 2024
Copy link
Member

@jaredfholgate jaredfholgate left a comment

Choose a reason for hiding this comment

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

The code looks really good, just think we can improve the user experience a bit.

variables.subscription.tf Outdated Show resolved Hide resolved
variables.subscription.tf Outdated Show resolved Hide resolved
modules/subscription/variables.tf Outdated Show resolved Hide resolved
Copy link
Member

@matt-FFFFFF matt-FFFFFF left a comment

Choose a reason for hiding this comment

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

LGTM - one comment!

modules/budget/variables.tf Outdated Show resolved Hide resolved
matt-FFFFFF
matt-FFFFFF previously approved these changes Apr 10, 2024
@luke-taylor luke-taylor merged commit 2b4d457 into Azure:main Apr 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: budget support
5 participants