Anthony Kong
Anthony Kong

Reputation: 40704

Creation a always_use_https pagerule failed with error Invalid setting always_use_https

Here is my rule

resource "cloudflare_page_rule" "https-only" {
    zone = "${var.domain}"
    target = "http://*${var.domain}/*"
    priority = 1

    actions = {
        always_use_https = true,
    }
}

The documentation says the default value of always_use_https is false. I want to turn this rule on for all http traffic to the zone.

When I apply the rule, I get this error:

* cloudflare_page_rule.https-only: Failed to create page rule: error 
from makeRequest: HTTP status 400: content "
{\"success\":false,\"errors\":[{\"code\":1004,\"message\":\"Page Rule 
validation failed: See messages for details.\"}],\"messages\":
[{\"code\":1,\"message\":\".settings[0]: Invalid setting 
always_use_https\",\"type\":null}],\"result\":null}"

I have tried alternative value such as 'on', but it gets rejected because terraform says the setting only accept boolean value.

How can I set this rule with terraform?

Upvotes: 1

Views: 360

Answers (3)

higuita
higuita

Reputation: 2315

I already had a recent cloudflare provider and was getting this error too.

To fix this for me, i changed something in the URL (http to https), to force a change, it applied and then i reverted back to the original url, without any issues now.

So, as Vit Dolphin said above, i can confirmed that this looks like some out of sync info in the state vs the provider version

Upvotes: 0

Vit Dolphin
Vit Dolphin

Reputation: 83

a had the same issue with some other zone override settings as well. what worked for me was to do a complete terraform destroy, upgrade to cf 2.2.0 provider and do an apply. looks like older versions of the provider might be out of sync with the apis to perform some of the zone override functions.

Upvotes: 2

sjsc
sjsc

Reputation: 4652

Make sure you set your domain to use Cloudflare's nameservers.

Upvotes: 0

Related Questions