GuideReference
TrainingSupportCommunity
Guide

Rules template

akamai_property_rules_template

Define which JSON template files to use for your property's rule tree based on the rule template format from the Property Manager CLI. You can also set values for variables.

📘

For details on how to work with rule templates and define variables, see the Rules guide.

data "akamai_property_rules_template" "my_rules" {
  template_file = abspath("${path.root}/main.json")
  variables {
    name  = "is_encrypted"
    value = true
    type  = "bool"
  }
  variables {
    name  = "ip_version"
    value = "IPV4"
    type  = "string"
  }
}

output "my_rules" {
  value = data.akamai_property_rules_template.my_rules.json
}

resource "akamai_property" "my-property" {
  name        = "MyProperty"
  product_id  = "prd_Object_Delivery"
  contract_id = "C-0N7RAC7"
  group_id    = "12345"
  rule_format = "v2023-05-30"
  rules       = data.akamai_property_rules_template.my_rules.json
}
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" : [
          "#include:criteria/content-type.json"
        ],
      }
    })
    template_dir = "./rules"
  }
  variables {
    name  = "is_encrypted"
    value = true
    type  = "bool"
  }
  variables {
    name  = "ip_version"
    value = "IPV4"
    type  = "string"
  }
}

output "my_rules" {
  value = data.akamai_property_rules_template.my_rules.json
}

resource "akamai_property" "my-property" {
  name        = "MyProperty"
  product_id  = "prd_Object_Delivery"
  contract_id = "C-0N7RAC7"
  group_id    = "12345"
  rule_format = "v2023-05-30"
  rules       = data.akamai_property_rules_template.my_rules.json
}
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")
}

output "my_rules" {
  value = data.akamai_property_rules_template.my_rules.json
}

resource "akamai_property" "my-property" {
  name        = "MyProperty"
  product_id  = "prd_Object_Delivery"
  contract_id = "C-0N7RAC7"
  group_id    = "12345"
  rule_format = "v2023-05-30"
  rules       = data.akamai_property_rules_template.my_rules.json
}
Changes to Outputs:
  + my_rules = jsonencode(
        {
          + accountId       = "act_A-CCT1234"
          + contractId      = "ctr_C-0N7RAC7"
          + etag            = "12a3b4567cd8e9012f34567g89hi01j23kl4567"
          + groupId         = "grp_12345"
          + propertyId      = "prp_12345"
          + propertyVersion = 2
          + ruleFormat      = "v2023-05-30"
          + rules           = {
              + behaviors = [
                  + {
                      + name    = "origin"
                      + options = {
                          + cacheKeyHostname          = "ORIGIN_HOSTNAME"
                          + compress                  = true
                          + enableTrueClientIp        = true
                          + forwardHostHeader         = "REQUEST_HOST_HEADER"
                          + hostname                  = "example.com"
                          + httpPort                  = 80
                          + httpsPort                 = 443
                          + ipVersion                 = "IPV4"
                          + minTlsVersion             = "DYNAMIC"
                          + originCertificate         = ""
                          + originSni                 = true
                          + originType                = "CUSTOMER"
                          + ports                     = ""
                          + tlsVersionTitle           = ""
                          + trueClientIpClientSetting = false
                          + trueClientIpHeader        = "True-Client-IP"
                          + verificationMode          = "PLATFORM_SETTINGS"
                        }
                    },
                  + {
                      + name    = "originCharacteristics"
                      + options = {
                          + accessKeyEncryptedStorage = true
                          + authenticationMethod      = "GCS_HMAC_AUTHENTICATION"
                          + authenticationMethodTitle = ""
                          + country                   = "NORTH_AMERICA"
                          + gcsAccessKeyVersionGuid   = "12abcd3ef-45gh-678i-j9k12345l6m7"
                          + originLocationTitle       = ""
                        }
                    },
                  + {
                      + name    = "contentCharacteristics"
                      + options = {
                          + catalogSize            = "MEDIUM"
                          + contentType            = "USER_GENERATED"
                          + objectSize             = "LESS_THAN_1MB"
                          + popularityDistribution = "LONG_TAIL"
                        }
                    },
                  + {
                      + name    = "cpCode"
                      + options = {
                          + value = {
                              + createdDate = 1708523914000
                              + description = "My CP code"
                              + id          = 123456
                              + name        = "My CP code"
                              + products    = [
                                  + "Obj_Delivery",
                                ]
                            }
                        }
                    },
                ]
              + children  = [
                  + {
                      + behaviors = [
                          + {
                              + name    = "gzipResponse"
                              + options = {
                                  + behavior = "ALWAYS"
                                }
                            },
                        ]
                      + name      = "Compress Text Content"
                    },
                ]
              + criteria  = [
                  + {
                      + name    = "contentType"
                      + options = {
                          + matchCaseSensitive = false
                          + matchOperator      = "IS_ONE_OF"
                          + matchWildcard      = true
                          + values             = [
                              + "text/html*",
                              + "text/css*",
                              + "application/x-javascript*",
                            ]
                        }
                    },
                ]
              + name      = "default"
              + options   = {}
            }
        }
    )

Arguments

Depending on how you work with templates, pass a path to your single JSON template file or point to individual templates in the body of the declaration to get the full rule tree.

Attribute Required Description
template_file An absolute path to your top-level JSON template file. The top-level template combines smaller, nested JSON templates to form your property rule tree.

Note: This argument conflicts with the template argument.
template The template you use in your configuration. Contains:
  • template_data. Required. The content of your JSON template as a string.
  • template_dir. Required. An absolute or relative path to a directory containing your template files.

Note: This argument conflicts with the template_file argument.
variables The definition of one or more variables. Contains:
  • name. Required. The name of a variable used in the template.
  • type. Required. The type of a variable: string, number, bool, or jsonBlock.
  • value. Required. The value of a variable passed as a string.

Note: This argument conflicts with the var_definition_file and var_values_file arguments.
var_definition_file Required only when using var_values_file. An absolute path to your file containing variable definitions and defaults.

Note: This argument conflicts with the variables argument.
var_values_file Required only when using var_definition_file. An absolute path to your file containing variable values.

Note: This argument conflicts with the variables argument.

Attributes

Returned to you is the fully expanded JSON-encoded rule template with all nested templates.