Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature-request: akamai_property_rules_template - support for array type variables #257

Closed
mkorcz opened this issue Oct 4, 2021 · 4 comments

Comments

@mkorcz
Copy link

mkorcz commented Oct 4, 2021

Hi there,

I found a need to create a cors policy with a different number of domains allowed. According to the assumptions of our project, each client has its own infrastructure based on one source of code. And here I have a problem where I need to paste a variable containing the list of domains. Creating multiple variables is not a solution as the number of domains will
vary for each deployment.

Terraform Version

Terraform v0.14.11

  • provider registry.terraform.io/akamai/akamai v1.6.0
  • provider registry.terraform.io/hashicorp/aws v3.56.0
  • provider registry.terraform.io/hashicorp/local v2.1.0
  • provider registry.terraform.io/hashicorp/random v3.1.0
  • provider registry.terraform.io/hashicorp/tls v3.1.0

Affected Resource(s)

  • akamai_property_rules_template

Terraform Configuration Files

data "akamai_property_rules_template" "akarules" {
  template_file = abspath("${path.module}/property-snippets/main.json")
  variables {
    name = "cp"
    value = tonumber(trim(akamai_cp_code.cp_code.id,"cpc_"))
    type = "number"
  }
  variables {
    name = "domain"
    value = var.cors_domain
    type = string 
}


#/property-snippets/main.tf
{
  "rules": {
    "name": "default",
    "children": [
      {
        "name": "Default CORS Policy",
        "children": [],
        "behaviors": [
          {
            "name": "modifyOutgoingResponseHeader",
            "options": {
              "action": "MODIFY",
              "avoidDuplicateHeaders": false,
              "newHeaderValue": "${env.domain}",
              "standardModifyHeaderName": "ACCESS_CONTROL_ALLOW_ORIGIN"
            }
          },

Expected Behavior

  variables {
    name = "domain"
    value = var.cors_domain
    type = list(string) 

Actual Behavior

No posibility to inject variables type other than number, string, bool, jsonBlock

Steps to Reproduce

  1. terraform apply
@hasc
Copy link

hasc commented Dec 20, 2021

Indeed, I see now way how I could configure a list of domains here

@lkowalsk-akamai-com
Copy link
Contributor

Hi @mkorcz , @hasc
This feature should be enabled now. Closing the ticket, please reopen in case of any problems.

@navjotkaur10
Copy link

navjotkaur10 commented May 24, 2024

@lkowalsk-akamai-com Could you please confirm if this was resolved? I'm getting error: 'type' has invalid value: should be 'bool', 'number', 'string' or 'jsonBlock' when using list(string) on version 5.5.0.

@PawelSnoch
Copy link

PawelSnoch commented May 29, 2024

Hi @navjotkaur10 ,

Unfortunately, list(string) is not supported this way. Please visit our techdocs page https://techdocs.akamai.com/terraform/docs/pm-ds-rules-template

variables - (Optional) The definition of one or more variables. This argument conflicts with the var_definition_file and var_values_file arguments. A variables block includes:
name - The name of the variable used in the template.
type - The type of variable: string, number, bool, or jsonBlock.
value - The value of the variable passed as a string.

We can advise you to use such form:

variable "list_string" {
default = [
"text/*",
"application/javascript",
"application/x-javascript"
]
type = list(string)
}

data "akamai_property_rules_template" "akarules" {
template_file = abspath("${path.root}/property-snippets/main.json")
variables {
name = "variable_list_string"
value = jsonencode(var.list_string)
type = "jsonBlock"
}

Then you can get this value in such way:

"values": "${env.variable_list_string}"

I hope it solves your case.

BR,
Pawel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants