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

Add Alerts, Logging, Channels Factories #2758

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

joshw123
Copy link
Contributor

@joshw123 joshw123 commented Dec 10, 2024


Checklist

I applicable, I acknowledge that I have:

  • Read the contributing guide
  • Ran terraform fmt on all modified files
  • Regenerated the relevant README.md files using tools/tfdoc.py
  • Made sure all relevant tests pass

Copy link
Collaborator

@juliocc juliocc left a comment

Choose a reason for hiding this comment

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

@joshw123 this is great stuff!

I left comments below, but besides that:

  1. We need to update project/README.md to include examples the new variables and factories
  2. FAST tests need to be updated

I have a few more things, but let's start with this batch.

modules/project/variables.tf Show resolved Hide resolved
modules/project/alerts-factory.tf Outdated Show resolved Hide resolved
modules/project/README.md Outdated Show resolved Hide resolved
modules/project/alerts-factory.tf Outdated Show resolved Hide resolved
modules/project/logging-metrics-factory.tf Outdated Show resolved Hide resolved
modules/project/variables-metrics-alerts.tf Outdated Show resolved Hide resolved
modules/project/variables-metrics-alerts.tf Outdated Show resolved Hide resolved
modules/project/variables-metrics-alerts.tf Outdated Show resolved Hide resolved
modules/project/variables-metrics-alerts.tf Outdated Show resolved Hide resolved
modules/project/variables-metrics-alerts.tf Outdated Show resolved Hide resolved
@joshw123
Copy link
Contributor Author

@joshw123 this is great stuff!

I left comments below, but besides that:

  1. We need to update project/README.md to include examples the new variables and factories
  2. FAST tests need to be updated

I have a few more things, but let's start with this batch.

Thank You, Ill look at the above, Im checking through all the fields too to ensure optional and required match the docs, and to include validation where necessary :)

@joshw123
Copy link
Contributor Author

@ludoo @juliocc The only two tests that are still not passing are Module Examples Test report

examples.test_plan.test_example[terraform:modules/project-factory:Example:1]
AssertionError: wrong number of resources
assert 56 == 59

examples.test_plan.test_example[terraform:modules/project-factory:Tests:1]
AssertionError: wrong number of resources
assert 22 == 25

I don't know if its just me, but I can't seem to see where it is getting them values, could you point me in the right direction please? :)

Thank You.

@juliocc
Copy link
Collaborator

juliocc commented Dec 13, 2024

examples.test_plan.test_example[terraform:modules/project-factory:Example:1] AssertionError: wrong number of resources assert 56 == 59

Look at the #tftest tag at the end of the code block in this section.

examples.test_plan.test_example[terraform:modules/project-factory:Tests:1] AssertionError: wrong number of resources assert 22 == 25

Same thing here.

Take a look at the contributing guide for more details.

@joshw123 joshw123 requested review from juliocc and ludoo December 13, 2024 15:28
@ludoo
Copy link
Collaborator

ludoo commented Dec 15, 2024

Can you sign the CLA from the ju****c​@gmail.com account?

@juliocc
Copy link
Collaborator

juliocc commented Dec 15, 2024

Can you sign the CLA from the ju****c​@gmail.com account?

That address is mine. Should be fixed now.

@juliocc
Copy link
Collaborator

juliocc commented Dec 16, 2024

@joshw123 I'll do my second pass today. Apologies for the delay.

@@ -102,6 +102,12 @@ variable "custom_roles" {
default = {}
}

variable "default_alerts_email" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we use the existing essential_contacts email here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had a similar thought either using an existing group, or building something with var.organization.domain

I actually prefer using essential_contacts

@@ -23,7 +23,7 @@ locals {
# If users give a list of custom audiences we set by default the first element.
# If no audiences are given, we set https://iam.googleapis.com/{PROVIDER_NAME}
audiences = try(
local.cicd_providers[v["identity_provider"]].audiences, ""
local.cicd_providers[v["identity_provider"]].audiences, "e"
Copy link
Collaborator

Choose a reason for hiding this comment

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

"e"?

@@ -109,6 +109,7 @@ locals {
vpcsc = module.automation-tf-vpcsc-sa.email
vpcsc-r = module.automation-tf-vpcsc-r-sa.email
}
default_alerts_email = var.default_alerts_email
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should go in globals, but TBH I would not even pass this down as it's specific to stage 0

@@ -109,6 +109,7 @@ locals {
vpcsc = module.automation-tf-vpcsc-sa.email
vpcsc-r = module.automation-tf-vpcsc-r-sa.email
}
default_alerts_email = var.default_alerts_email
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we export notification channels to the following stages?

@@ -68,6 +68,12 @@ variable "custom_roles" {
default = null
}

variable "default_alerts_email" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this might be different for notifications set here, I would not include it in FAST variables

@@ -37,6 +37,12 @@ variable "billing_account" {
}
}

variable "default_alerts_email" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as for resman, this should be configurable at the stage level

Copy link
Collaborator

@juliocc juliocc left a comment

Choose a reason for hiding this comment

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

Leaving a few more comments below.

I also sent you a PR against your branch with a few styling fixes. Once you get that merged I'll try to get started on removing the default_alerts_email variable and use essential_contacts


network-firewall-config-changes:
description: "Monitor VPC network firewall configuration changes inside GCP projects"
filter: "resource.type=\"gce_firewall_rule\" AND (protoPayload.methodName:\"compute.firewalls.delete\" OR protoPayload.methodName:\"compute.firewalls.insert\")"
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use "|" syntax for all filters in this file

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've done this in the PR I sent

sensitive = true
value = local.tfvars_globals
sensitive = false
value = jsonencode(local.tfvars_globals)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's this about?

/cc @ludoo

Copy link
Collaborator

Choose a reason for hiding this comment

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

We mark large outputs as sensitive so as not to pollute the screen at every apply, as they still can be fetched explictly even when sensitive. So I would keep it.

As for jsonencode, we never do it for outputs and the globals file is JSON anyway, so I would also revert that.

@@ -102,6 +102,12 @@ variable "custom_roles" {
default = {}
}

variable "default_alerts_email" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had a similar thought either using an existing group, or building something with var.organization.domain

I actually prefer using essential_contacts

alerts = var.factories_config.alerts
channels = var.factories_config.channels
logging_metrics = var.factories_config.logging_metrics
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

now that we are creating LBMs and alerts, do we need to enable the logging and monitoring APIs?

Same, applies to all projects

Comment on lines +125 to +129
notification_channels = [
try(google_monitoring_notification_channel.this[each.value.notification_channels].id,
each.value.notification_channels),
try(google_monitoring_notification_channel.default[0].id, "")
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this works (you're indexing google_monitoring_notification_channel.this with each.value.notification_channels, which is a list). Please double check.

Also, I think the default shouldn't be used if there are notification channels defined by the alert. For me, the logic should be:

  1. Try to use the locally created channel first,
  2. If the specified channel id is not created by us, use it as as an id (i.e. the notification channel was created elsewhere)
  3. If there are no notification channels, use the default, if provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants