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

Unable to pass in the Dynamic list of Children in akamai_property_rules_builder #542

Open
junaid-mukhtar opened this issue Apr 18, 2024 · 5 comments

Comments

@junaid-mukhtar
Copy link

Hi there,

We are trying to use the Akamai terraform provider and the aim is to pass in the child rules dynamically to the terraform config. Our setup is

Multiple brands --> Multiple Env --> Single Terraform config

But we are unable to pass in the values of children dynamically.

Terraform Version

% terraform -v
Terraform v1.8.1
on darwin_amd64

  • provider registry.terraform.io/akamai/akamai v6.0.0

Affected Resource(s)

akamai_property_rules_builder

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

locals {
  formatted_list = [
  [trim(var.list, "\"" )]
  ]
}

data "akamai_property_rules_builder" "akamai_rule_redirects" {
  rules_v2023_10_30 {
    name                  = "Redirects"
    criteria_must_satisfy = "all"
    children = local.formatted_list

  }
}

variable "list" {
  type = string
  default = "data.akamai_property_rules_builder.rule_http_to_https.json,  data.akamai_property_rules_builder.rule_-shop-tag-_-_locale.json,data.akamai_property_rules_builder.rule_vas_redirect.json,"
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

data.akamai_property_rules_builder.akamai_rule_redirects should get the values from the variable default without the quotes

Actual Behavior

Planning failed. Terraform encountered an error while generating this plan.


│ Error: building rules: invalid character 'd' looking for beginning of value

│ with data.akamai_property_rules_builder.rule_redirects,
│ on rules.tf line 825, in data "akamai_property_rules_builder" "rule_redirects":
│ 825: data "akamai_property_rules_builder" "ule_redirects" {

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create the code for akamai_property_rules_builder
  2. Add a variable that will pass in the list of children to be included
  3. terraform apply

Important Factoids

No

References

No

@mgwoj
Copy link
Contributor

mgwoj commented Apr 18, 2024

Hello,

What about defining it this way?

locals {
  formatted_list = [data.akamai_property_rules_builder.rule_http_to_https.json,  data.akamai_property_rules_builder.rule_-shop-tag-_-_locale.json,data.akamai_property_rules_builder.rule_vas_redirect.json]
}

@junaid-mukhtar
Copy link
Author

junaid-mukhtar commented Apr 18, 2024 via email

@mgwoj
Copy link
Contributor

mgwoj commented Apr 18, 2024

I don't know your planned setup, but what about this approach?

locals {
  prod_list = [data.akamai_property_rules_builder.rule_http_to_https.json,  data.akamai_property_rules_builder.rule_-shop-tag-_-_locale.json,data.akamai_property_rules_builder.rule_vas_redirect.json]
  stag_list = [ .... ]
}

variable "stag" {
  type = bool
  default = true
}

data "akamai_property_rules_builder" "akamai_rule_redirects" {
  rules_v2023_10_30 {
    name                  = "Redirects"
    criteria_must_satisfy = "all"
    children = var.stag ?  local.stag_list : local.prod_list
  }
}

@junaid-mukhtar
Copy link
Author

This approach also works, but the problem we have is that we have 8 brands (many more to come) and each brand has 4 properties (dev, qa, staging and production). The approach you mentioned will not work in our case.

@mgwoj
Copy link
Contributor

mgwoj commented Apr 22, 2024

Hello,

This configuration works for me

locals {
  config = {
    brand1 = {
      dev = []
      qa = [data.akamai_property_rules_builder.rule_http_to_https.json,  data.akamai_property_rules_builder.rule_-shop-tag-_-_locale.json,data.akamai_property_rules_builder.rule_vas_redirect.json]
      staging = []
      production = []
    }
    brand2 = {
      dev = []
      qa = [data.akamai_property_rules_builder.rule_http_to_https.json]
      staging = []
      production = []
    }
  }
}

variable "brand" {
  type    = string
  default = "brand1"
}

variable "environment" {
  type    = string
  default = "qa"
}

data "akamai_property_rules_builder" "akamai_rule_redirects" {
  rules_v2023_10_30 {
    name                  = "Redirects"
    criteria_must_satisfy = "all"
    children = local.config[var.brand][var.environment]
  }
}

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

No branches or pull requests

3 participants