Rules
Property configuration rules and includes use behaviors to determine the action taken when specific conditions are met. The options you choose define your behavior and the criteria that trigger the behavior's action.
A rule tree is a nested block of property rules in JSON format that includes match criteria and behaviors. You can break a rule tree out into smaller JSON template files that cover individual rules.
Each rule format version contains the schema for a set of rules, behaviors, options, and criteria.
- For rule format updates, see Rule format changes.
- For more on how to work with the schema, see Property behaviors.
Update rule format
To update your rule format, pass the required dated version in the property resource.
resource "akamai_property" "my_property" {
name = "my-property"
product_id = "prd_product"
contract_id = "ctr_C-0N7RAC7"
group_id = "grp_12345"
rule_format = "v2023-01-05"
}
Edit rules JSON directly
You can have a single JSON rule tree file for storing all your default property rules.
Make updates or changes directly in your rules' JSON file. When you're done:
-
In the
akamai_property_rules_template
data source, add thetemplate_file
argument to specify the path to your main rules template file. -
Then, reference your JSON file in the
akamai_property
resource by passing the path to that file in therules
argument.data "akamai_property_rules_template" "template-update" { template_file = abspath("${path.root}/rules.json") } resource "akamai_property" "update-rule-format" { name = "my-property" product_id = "prd_product" contract_id = "ctr_C-0N7RAC7" group_id = "grp_12345" rule_format = "v2023-01-05" rules = data.akamai_property_rules_template.template-update.json }
Use rule templates
A rule template is a JSON file containing a single rule that you update and then point to in the akamai_property_rules_template
data source.
You have several options when working with JSON rule template files:
- Use a single JSON file that includes all rules for the property.
- Create separate JSON template files for each rule.
- Reference individual template files directly in the
akamai_property_rules_template
data source.
Alternatively, you can use the akamai_property_rules_builder
data source to build your property rules, includes, behaviors, and criteria into a single set of rules or a rules file.
To set up your rule templates:
-
Create a rules directory in your project. This directory will hold your full rules JSON file and any number of templated JSON files split into rule behaviors and children. To keep what file contains which rule, name your template files after the rule.
$ tree ~/terraform/rules rules ├── rules.json │ ├── behaviors │ ├── children
-
Locate the rule(s) you want to update in your
rules.json
file. -
Copy/paste any behaviors you want to update into a new JSON file that will go into the behaviors directory.
{ "name": "origin", "options": { "cacheKeyHostname": "ORIGIN_HOSTNAME", "compress": true, "enableTrueClientIp": true, "forwardHostHeader": "REQUEST_HOST_HEADER", "hostname": "example.com", "httpPort": 80, "httpsPort": 443, "ipVersion": "DUALSTACK", "minTlsVersion": "DYNAMIC", "originCertificate": "", "originSni": true, "originType": "CUSTOMER", "ports": "", "tlsVersionTitle": "", "trueClientIpClientSetting": false, "trueClientIpHeader": "True-Client-IP", "verificationMode": "PLATFORM_SETTINGS" } }
-
Copy/paste any children you want to update into a new JSON file that will go into the children directory.
{ "name": "Compress Text Content", "behaviors": [ { "name": "gzipResponse", "options": { "behavior": "ALWAYS" } } ] }
-
Make your updates.
-
Back in your rules' JSON file, point to your template files by using the
#include
statements in thechildren
andbehaviors
arrays.{ "rules": { "name": "default", "children": [ "#include:children/compress-text.json" ], "behaviors": [ "#include:behaviors/origin-hostname.json", "#include:behaviors/origin-characteristics.json", "#include:behaviors/content-characteristics.json", "#include:behaviors/cp-code.json" ], ... } }
Alternatively, you can point to the individual template files using the
template
argument in theakamai_property_rules_template
data source. Inside that argument:-
Add the
template_data
argument and use Terraform’sjsonencode
function to add the supporting JSON syntax. -
Also, in the
template_dir
argument provide a path to the directory containing template files.data "akamai_property_rules_template" "my_rules" { template { template_data = jsonencode( { "rules" : { "name" : "default", "children" : [ "#include:children/compress-text.json" ], "behaviors" : [ "#include:behaviors/origin-hostname.json", "#include:behaviors/origin-characteristics.json", "#include:behaviors/content-characteristics.json", "#include:behaviors/cp-code.json" ], "options" : true, "criteria" : [], "criteriaMustSatisfy" : "all", "comments" : "The behaviors in the Default Rule apply to all requests for the property hostnames unless another rule overrides the Default Rule settings." } } ) template_dir = "./rules" } }
-
Instead of Terraform’s
jsonencode
function, in thetemplate_data
argument, you can also use heredoc.data "akamai_property_rules_template" "my_rules" { template { template_data = <<-EOT { "rules" : { "name" : "default", "children" : [ "#include:children/compress-text.json" ], "behaviors" : [ "#include:behaviors/origin-hostname.json", "#include:behaviors/origin-characteristics.json", "#include:behaviors/content-characteristics.json", "#include:behaviors/cp-code.json" ], "options" : true, "criteria" : [], "criteriaMustSatisfy" : "all", "comments" : "The behaviors in the Default Rule apply to all requests for the property hostnames unless another rule overrides the Default Rule settings." } } EOT template_dir = "./rules" } }
-
-
Once you're done, add your rule updates to your property.
Define variables
You can add variables to your template files with one of these methods:
Use the variables
argument
variables
argument-
Define each variable individually in the
akamai_property_rules_template
data source using thevariables
argument. For each variable, specify its name, type, and value.data "akamai_property_rules_template" "my_rules" { template_file = abspath("${path.root}/main.json") variables { name = "is_encrypted" value = true type = "bool" } variables { name = "primary_guid" value = akamai_cloudaccess_key.my_access_key.primary_guid type = "string" } }
-
Then pass the defined variables to the appropriate arguments in your JSON file using the
"${env.variable_name}"
string.{ "name": "originCharacteristics", "options": { "accessKeyEncryptedStorage": "${env.is_encrypted}", "authenticationMethod": "AWS", "authenticationMethodTitle": "", "awsAccessKeyVersionGuid": "${env.primary_guid}", "awsHost": "", "awsRegion": "Asia", "awsService": "s3", "country": "UNKNOWN" } }
Call variable definition files
-
For your property variables, create a
variableDefinitions.json
file to define your variables and their default values.{ "definitions": { "enableTrueClientIp": { "type": "boolean", "default": true }, "ipVersion": { "type": "string", "default": "DUALSTACK" }, ... } }
-
Then, create one or more
variables.json
files to define settings specific to each environment. The file name should always bevariables.json
. If using multiple environments, set up a directory for each environment to store these files in.{ "enableTrueClientIp": false, "ipVersion": "IPV6", ... }
The variables defined in the JSON files need to follow the naming and formats used with the Property Manager CLI pipeline.
-
In the
akamai_property_rules_template
data source, use these arguments:var_definition_file
to add a path to thevariableDefinitions.json
file.var_values_file
to add a path to thevariables.json
file.
data "akamai_property_rules_template" "my_rules" { template_file = abspath("${path.root}/main.json") var_definition_file = abspath("${path.root}/environments/variableDefinitions.json") var_values_file = abspath("${path.root}/environments/dev.example.com/variables.json") }
-
Once you have your variables defined, pass them to the appropriate arguments in your JSON template file using the
"${env.variable_name}"
string.If you haven't defined variables for a specific environment in the
variables.json
file, then the variables you pass in the JSON template will use the default values defined in thevariableDefinitions.json
file.See the Property Manager CLI documentation for more details on how to:
{ "name": "origin", "options": { "cacheKeyHostname": "ORIGIN_HOSTNAME", "compress": true, "enableTrueClientIp": "${env.enableTrueClientIp}", "forwardHostHeader": "REQUEST_HOST_HEADER", "hostname": "example.com", "httpPort": 80, "httpsPort": 443, "ipVersion": "${env.ipVersion}", "minTlsVersion": "DYNAMIC", "originCertificate": "", "originSni": true, "originType": "CUSTOMER", "ports": "", "tlsVersionTitle": "", "trueClientIpClientSetting": false, "trueClientIpHeader": "True-Client-IP", "verificationMode": "PLATFORM_SETTINGS" } }
Updated 14 days ago