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

Page rule creation with redirect fails #5178

Open
3 tasks done
albertodonato opened this issue Feb 23, 2025 · 8 comments
Open
3 tasks done

Page rule creation with redirect fails #5178

albertodonato opened this issue Feb 23, 2025 · 8 comments
Labels
triage/needs-information Indicates an issue needs more information in order to work on it. version/5 Categorizes issue or PR as related to version 5 of the provider.

Comments

@albertodonato
Copy link

Confirmation

  • This is a bug with an existing resource and is not a feature request or enhancement. Feature requests should be submitted with Cloudflare Support or your account team.
  • I have searched the issue tracker and my issue isn't already found.
  • I have replicated my issue using the latest version of the provider and it is still present.

Terraform and Cloudflare provider version

Using v5.1.0 plugin, creating a page rule with a redirect action fails.

The resource is defined as:

resource "cloudflare_page_rule" "mydomain_redirect" {
  zone_id = "my-zone-id"

  target = "example.com"
  actions = {
    forwarding_url = {
      url         = "https://something.example.com"
      status_code = 302
    }
  }
  status = "active"
}

Applying fails with the following error:

│ Value Conversion Error An unexpected error was encountered trying to build a value. This is always an error in the provider. Please report the following to the provider developer:
│ 
│ Received null value, however the target type cannot handle null values. Use the corresponding `types` package type, a pointer type or a custom type that handles null values.
│ 
│ Path: 
│ Target Type: page_rule.PageRuleActionsForwardingURLModel
│ Suggested `types` Type: basetypes.ObjectValue
│ Suggested Pointer Type: *page_rule.PageRuleActionsForwardingURLModel

As a side note, documentation shows examples of actions as a struct, but it needs to be a variable.

Affected resource(s)

  • cloudflare_page_rule

Terraform configuration files

resource "cloudflare_page_rule" "mydomain_redirect" {
  zone_id = "my-zone-id"

  target = "example.com"
  actions = {
    forwarding_url = {
      url         = "https://something.example.com"
      status_code = 302
    }
  }
  status = "active"
}

Link to debug output

n/a

Panic output

No response

Expected output

n/a

Actual output

n/a

Steps to reproduce

create a resource like the one described

Additional factoids

No response

References

No response

@albertodonato albertodonato added kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 23, 2025
@jacobbednarz
Copy link
Member

please provide the TF_LOG=DEBUG output for this to be triaged.

@jacobbednarz jacobbednarz added triage/needs-information Indicates an issue needs more information in order to work on it. and removed kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 23, 2025
@albertodonato
Copy link
Author

debug.log

@jacobbednarz jacobbednarz added the version/4 Categorizes issue or PR as related to version 4 of the provider. label Feb 26, 2025
@dhjensen
Copy link

dhjensen commented Mar 3, 2025

I have similar problems with 5.1.0 in an attempt to upgrade from 4.x.x. As his side note shows the actions part is wrongly documented and/or functioning wrongly:

terraform plan
╷
│ Error: Missing required argument
│ 
│   on cloudflare.tf line 298, in resource "cloudflare_page_rule" "domain_redirect":
│  298: resource "cloudflare_page_rule" "domain_redirect" {
│ 
│ The argument "actions" is required, but no definition was found.
╵
╷
│ Error: Unsupported block type
│ 
│   on cloudflare.tf line 302, in resource "cloudflare_page_rule" "domian_redirect":
│  302:   actions {
│ 
│ Blocks of type "actions" are not expected here. Did you mean to define argument "actions"? If so, use the equals sign to assign it a value.
╵

I have used a similar terraform configuration without the = for "actions" producing the failure seen above.

@jacobbednarz
Copy link
Member

using 5.1.0, i'm unable to reproduce this one using a new resource.

resource "cloudflare_page_rule" "mydomain_redirect" {
  zone_id = var.zone_id

  target = "terraform.cfapi.net"
  actions = {
    forwarding_url = {
      url         = "https://example.com"
      status_code = 302
    }
  }
  status = "active"
}

@dhjensen if you're not using the grit migration path, you'll need to manually review the upgrade guide which mentions changing this from a block to an attribute - https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/guides/version-5-upgrade#cloudflare_page_rule. depending on the complexity of it, you may also need to manually adjust your state or reimport to get the correct structure.

@jacobbednarz jacobbednarz added version/5 Categorizes issue or PR as related to version 5 of the provider. and removed version/4 Categorizes issue or PR as related to version 4 of the provider. labels Mar 6, 2025
@dhjensen
Copy link

dhjensen commented Mar 6, 2025

Thank you.

I will use the grit migration path when 5.2.0 comes out with support for cloudflare_zone account_id migration

@jacobbednarz
Copy link
Member

there is no difference in the migration between 5.2 and 5.1. you can follow it today and have it work.

@dhjensen
Copy link

dhjensen commented Mar 6, 2025

That was unsuccessful as the zones is going to be replaced(And a buck load of other issues). Using 5.1.0 grit does not modify the zone account_id but I can see some commits for 5.2.0 related to this. 7bb3f3f

@jacobbednarz
Copy link
Member

the grit pattern is already available (hence no change with 5.2.0).

if you're having other issues with the zone management, please open individual issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/needs-information Indicates an issue needs more information in order to work on it. version/5 Categorizes issue or PR as related to version 5 of the provider.
Projects
None yet
Development

No branches or pull requests

3 participants