I'm trying to validate the input tags against the standard tags defined by our team. A tag is a key-value pair which we are assigning to a cloud resources, for example, in case of AWS cloud, EC2 instances, S3 buckets etc. Sample input is like as-
{
"tags": {
"Environment": "poc",
"Service": "ec2",
"Product": "jenkins",
"Owner": "[email protected]"
}
}
Valid values for each key as-
Environment : poc,qa,uat,prod.
Service: ec2,s3,rds
Product: jenkins,spinnaker,nginx
Owner: [anything]@test.com
I am able to validate keys ( Environment, Service etc). For values, I am able to validate it against each key separately as-
package play
import future.keywords
owner_values = "^[a-zA-Z0-9+_.-][email protected]$"
allow_values {
owner = input.tags.InfraOwner
regex.match(owner_values,owner)
}
If I go like this, I have to repeat it for each tag. Though tags are limited, I am thinking to introduce loop. However, struggling to do same.