Apply resource policies for names and text

This topic shows several resource policies you can apply to establish naming and text conventions. These policies ensure consistency for resource names and tag values.

Set naming convention with wildcard

The following example shows the use of wildcard, which is supported by the like condition. The condition states that if the name does match the mentioned pattern (namePrefix*nameSuffix) then deny the request:

{
  "if": {
    "not": {
      "field": "name",
      "like": "namePrefix*nameSuffix"
    }
  },
  "then": {
    "effect": "deny"
  }
}

Set naming convention with pattern

To specify that resource names match a pattern, use the match condition. The following example requires names to start with contoso and contain six additional letters:

{
  "if": {
    "not": {
      "field": "name",
      "match": "contoso??????"
    }
  },
  "then": {
    "effect": "deny"
  }
}

Set date pattern for tag value

To require a date pattern of two digits, dash, three letters, dash, and four digits, use:

{
  "if": {
    "field": "tags.date",
    "match": "##-???-####"
  },
  "then": {
    "effect": "deny"
  }
}

Next steps