Editing string in mock file, in a list, to filter two parts of a string

I’ve created two rules, the first one just checks for a string and is fine. However, the second rule is causing issues since I’m getting the error below.

“policy.sentinel:33:10: only a list or map can be indexed, got undefined”

I’m targeting line 222, and my goal is to enforce parts of this:

“metric.type="logging.googleapis.com/user/mysql/metric" AND resource.type="cloudsql_instance_database"”

except what is bold which is going to be unique to each user “mysql/metric” in my case. But everything before “mysql/metric”, including quotes, and after the AND should be enforced. However, I’m trying to print the “filter” value but that isn’t working either yet.


line 30-33 is my problem

I think given the structure of the ‘filter’ property, you don’t need to do anything too complex other than make sure the prefix and suffix match the required values.

I’ve mocked up a simple example here (this is fragile if google_monitoring_alert_policy objects store filters outside of the location hardcoded in the map function):

1 Like

Thanks this works exactly how I needed