cli-terraform icon indicating copy to clipboard operation
cli-terraform copied to clipboard

DXE-4473 Error exporting property. Saving terraform files. Executing template: rules_v2024-10-21. Range can't iterate over

Open glenthomas opened this issue 1 year ago • 9 comments

I have a bug with the export-property command when exporting rule format 2024-10-21.

The output is:

Fetching property www.something.com [OK]
Fetching group  [OK]
Fetching property version  [OK]
Fetching property rules  [OK]
Fetching product name  [OK]
Fetching hostnames  [OK]
Fetching activation details  [OK]
Saving TF configurations  [FAIL]
Error exporting property: saving terraform project files: executing template: rules_v2024-10-21.tmpl: 
template: rules_v2024-10-21.tmpl:9347:20: executing "queryStringParameter" at <$v>: 
range can't iterate over api.blah.something.com

I have some match criteria that uses an array of strings for match values. This is from the downloaded rules JSON:

"criteria": [
    {
        "name": "queryStringParameter",
        "options": {
            "parameterName": "host",
            "matchOperator": "IS_ONE_OF",
            "values": "api.blah.something.com",
            "matchWildcardName": false,
            "matchCaseSensitiveName": true,
            "matchWildcardValue": false,
            "matchCaseSensitiveValue": true,
            "escapeValue": false
        }
    }
],

Strangely, I have similar blocks of JSON in the export that have a single array item, but include it as an array of strings rather than just a string:

"criteria": [
    {
        "name": "queryStringParameter",
        "options": {
            "parameterName": "host",
            "matchOperator": "IS_ONE_OF",
            "values": [
                "api.blah.something.com",
            ],
            "matchWildcardName": false,
            "matchCaseSensitiveName": true,
            "matchWildcardValue": false,
            "matchCaseSensitiveValue": true,
            "escapeValue": false
        }
    }
],

glenthomas avatar Dec 10 '24 11:12 glenthomas

Hi @glenthomas

I was able to reproduce it. We will inform you about progress.

BR, Lukasz

lsadlon avatar Dec 10 '24 12:12 lsadlon

Hello @lsadlon, please let me know if there are any suitable workarounds as I would like to continue with my work ASAP. Thanks.

glenthomas avatar Dec 11 '24 14:12 glenthomas

Hi @glenthomas,

You can open your property in UI and save it there even without any changes. It should covert this problematic element to array of strings.

BR, Lukasz

lsadlon avatar Dec 11 '24 15:12 lsadlon

Hello @lsadlon, to confirm, are you saying that I can:

  1. Edit a new version of the property in the Control Center.
  2. Save the version without any changes.
  3. Export using cli-terraform

and it will now work? So somebody has fixed the values attribute so that it is always a list of strings?

glenthomas avatar Dec 11 '24 15:12 glenthomas

...I have just tried this and am still getting the same error.

glenthomas avatar Dec 11 '24 16:12 glenthomas

Hi @glenthomas,

So problem is that cli-terraform while exporting data expect values attribute to be list of strings. Other way you can fix it is using API (e.g. Postman) https://techdocs.akamai.com/property-mgr/reference/put-property-version-rules and update your rules accordingly.

BR, Lukasz

lsadlon avatar Dec 12 '24 07:12 lsadlon

I have downloaded the rules from the property as JSON. I have corrected the schema to use an array of strings and am now trying to PUT the rules back via Postman. I am getting this generic error:

{
    "type": "https://problems.luna.akamaiapis.net/papi/v0/http/bad-request",
    "title": "Bad Request",
    "detail": "The system cannot understand your request.  Please check the syntax and correct any problems.",
    "instance": "https://{redacted}.luna.akamaiapis.net/papi/v1/properties/123456/versions/1234/rules#d1b1675ae15852fa",
    "status": 400
}

How can I validate the rules JSON? I have tried using params validateRules=true and validateMode=full and still get the same error response.

glenthomas avatar Dec 12 '24 13:12 glenthomas

I have also tried the rules PATCH endpoint and am getting the same error response

Request:

[
  {
    "op": "replace",
    "path": "/rules/children/117/children/0/children/0/criteria/0/values",
    "value": ["api.blah.something.com"]
  }
]

Response:

{
    "type": "https://problems.luna.akamaiapis.net/papi/v0/http/bad-request",
    "title": "Bad Request",
    "detail": "The system cannot understand your request.  Please check the syntax and correct any problems.",
    "instance": "https://{redacted}.luna.akamaiapis.net/papi/v1/properties/123456/versions/1234/rules#d1b1675ae15852fa",
    "status": 400
}

glenthomas avatar Dec 12 '24 14:12 glenthomas

Hi @glenthomas,

To be honest from error message that you get I cannot tell you what is wrong, but it looks there is something wrong with request itself, rather than rules.

BR, Lukasz

lsadlon avatar Dec 13 '24 07:12 lsadlon