-
Notifications
You must be signed in to change notification settings - Fork 827
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
terraform/k8s-infra-kubernetes-io: manage k8s-infra-sandbox-capg budget #2940
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,12 +74,13 @@ readonly DNS_GROUP="[email protected]" | |
readonly TERRAFORM_STATE_BUCKET_ENTRIES=( | ||
"${LEGACY_CLUSTER_TERRAFORM_BUCKET}:${CLUSTER_ADMINS_GROUP}" | ||
k8s-infra-tf-aws:[email protected] | ||
k8s-infra-tf-gcp:[email protected] | ||
k8s-infra-tf-monitoring:"${CLUSTER_ADMINS_GROUP}" | ||
k8s-infra-tf-prow-clusters:[email protected] | ||
k8s-infra-tf-public-clusters:"${CLUSTER_ADMINS_GROUP}" | ||
k8s-infra-tf-public-pii:"${CLUSTER_ADMINS_GROUP}" | ||
k8s-infra-tf-sandbox-ii:[email protected] | ||
k8s-infra-tf-sandbox-capg:[email protected] | ||
k8s-infra-tf-sandbox-ii:[email protected] | ||
) | ||
|
||
# The services we explicitly want enabled for the main project | ||
|
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
data "google_billing_account" "account" { | ||
billing_account = "018801-93540E-22A20E" | ||
} | ||
|
||
data "google_organization" "org" { | ||
domain = "kubernetes.io" | ||
} | ||
|
||
resource "google_project" "project" { | ||
name = "k8s-infra-kubernetes-io" | ||
project_id = "k8s-infra-kubernetes-io" | ||
org_id = data.google_organization.org.org_id | ||
billing_account = data.google_billing_account.account.billing_account | ||
} | ||
|
||
resource "google_project_service" "project" { | ||
project = google_project.project.id | ||
for_each = toset([ | ||
"billingbudgets.googleapis.com", | ||
"cloudbilling.googleapis.com", | ||
"cloudresourcemanager.googleapis.com", | ||
"monitoring.googleapis.com", | ||
"serviceusage.googleapis.com", | ||
]) | ||
service = each.value | ||
} | ||
|
||
data "google_project" "kubernetes_public" { | ||
project_id = "kubernetes-public" | ||
} | ||
|
||
resource "google_resource_manager_lien" "kubernetes_public" { | ||
parent = "projects/${data.google_project.kubernetes_public.number}" | ||
restrictions = ["resourcemanager.projects.delete"] | ||
origin = "do-not-delete-kubernetes-public" | ||
reason = "kubernetes-public hosts public-facing kubernetes project infrastructure" | ||
} | ||
|
||
data "google_project" "k8s_infra_sandbox_capg" { | ||
project_id = "k8s-infra-sandbox-capg" | ||
} | ||
|
||
data "google_monitoring_notification_channel" "sig_k8s_infra_leads" { | ||
project = data.google_project.kubernetes_public.project_id | ||
display_name = "[email protected]" | ||
} | ||
|
||
resource "google_billing_budget" "capg_budget" { | ||
billing_account = data.google_billing_account.account.billing_account | ||
display_name = "k8s-infra-sandbox-capg" | ||
budget_filter { | ||
# calendar_period = "MONTH" # TODO: terraform doesn't support this? | ||
projects = [ "projects/${data.google_project.k8s_infra_sandbox_capg.number}" ] | ||
# exclude promotions, which is where our credits come from, since that zeros out cost | ||
credit_types_treatment = "INCLUDE_SPECIFIED_CREDITS" | ||
credit_types = [ | ||
"SUSTAINED_USAGE_DISCOUNT", | ||
"DISCOUNT", | ||
"COMMITTED_USAGE_DISCOUNT", | ||
"FREE_TIER", | ||
"COMMITTED_USAGE_DISCOUNT_DOLLAR_BASE", | ||
"SUBSCRIPTION_BENEFIT", | ||
] | ||
} | ||
amount { | ||
specified_amount { | ||
currency_code = "USD" | ||
units = "5000" | ||
} | ||
} | ||
all_updates_rule { | ||
# Don't send to users with Billing Account Administrators and | ||
# Billing Account Users IAM roles for the billing account | ||
disable_default_iam_recipients = true | ||
monitoring_notification_channels = [ | ||
data.google_monitoring_notification_channel.sig_k8s_infra_leads.name | ||
] | ||
} | ||
dynamic "threshold_rules" { | ||
for_each = toset([0.2, 0.5, 0.9, 1.0]) | ||
content { | ||
threshold_percent = threshold_rules.value | ||
} | ||
} | ||
} | ||
|
||
resource "google_billing_budget" "k8s_infra" { | ||
billing_account = data.google_billing_account.account.billing_account | ||
display_name = "k8s-infra-monthly" | ||
budget_filter { | ||
# calendar_period = "MONTH" # TODO: terraform doesn't support this? | ||
# exclude promotions, which is where our credits come from, since that zeros out cost | ||
credit_types_treatment = "INCLUDE_SPECIFIED_CREDITS" | ||
credit_types = [ | ||
"SUSTAINED_USAGE_DISCOUNT", | ||
"DISCOUNT", | ||
"COMMITTED_USAGE_DISCOUNT", | ||
"FREE_TIER", | ||
"COMMITTED_USAGE_DISCOUNT_DOLLAR_BASE", | ||
"SUBSCRIPTION_BENEFIT", | ||
] | ||
} | ||
amount { | ||
specified_amount { | ||
currency_code = "USD" | ||
units = "250000" # 3M/yr / 12mo | ||
} | ||
} | ||
all_updates_rule { | ||
# Don't send to users with Billing Account Administrators and | ||
# Billing Account Users IAM roles for the billing account | ||
disable_default_iam_recipients = true | ||
monitoring_notification_channels = [ | ||
data.google_monitoring_notification_channel.sig_k8s_infra_leads.name | ||
] | ||
} | ||
dynamic "threshold_rules" { | ||
for_each = toset([0.9, 1.0]) | ||
content { | ||
threshold_percent = threshold_rules.value | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/* | ||
This file defines: | ||
- Required provider versions | ||
- Storage backend details | ||
*/ | ||
|
||
terraform { | ||
|
||
backend "gcs" { | ||
bucket = "k8s-infra-tf-gcp" | ||
prefix = "kubernetes-io" | ||
} | ||
|
||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "~> 3.87.0" | ||
} | ||
google-beta = { | ||
source = "hashicorp/google-beta" | ||
version = "~> 3.87.0" | ||
} | ||
} | ||
} | ||
|
||
provider "google" { | ||
# necessary to create google_billing_budget resources | ||
# NOTE: bootstrapping was necessary to use this, involved setting to false | ||
# and creating the project / enabling the required services using | ||
# another gcloud project with cloudresourcemanager and serviceusage | ||
# APIs enabled | ||
user_project_override = true | ||
billing_project = "k8s-infra-kubernetes-io" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/* | ||
This file defines: | ||
- Required Terraform version | ||
*/ | ||
|
||
terraform { | ||
required_version = "~> 1.0.0" | ||
} |
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.
Why not directly manage this with Terraform ? (use a resource)
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.
And I think Steering should be get notified when the threshold reach a critical percentage of the budget defined
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'll tackle these in a followup