cloudflare / terraform-provider-cloudflare

Cloudflare Terraform Provider
https://registry.terraform.io/providers/cloudflare/cloudflare
Mozilla Public License 2.0
770 stars 596 forks source link

Pages does not update project when removing environment variables #2639

Open Cyb3r-Jak3 opened 1 year ago

Cyb3r-Jak3 commented 1 year ago

Confirmation

Terraform and Cloudflare provider version

Terraform v1.5.0 on windows_amd64

Affected resource(s)

pages_project

Terraform configuration files

resource "cloudflare_pages_project" "test-project" {
  account_id        = var.account_id
  name              = "test-project"
  production_branch = "main"
  deployment_configs {
    preview {
      always_use_latest_compatibility_date = true
      fail_open                            = false
      environment_variables = {
        NODE_VERSION   = "18"
      }
      placement {}
    }
    production {
      fail_open = false
      environment_variables = {
        NODE_VERSION   = "18"
        PYTHON_VERSION = "3.7"
      }
      placement {}
    }
  }
}

Link to debug output

https://gist.github.com/Cyb3r-Jak3/57af688997416a9027b10f9141076b76

Panic output

No response

Expected output

That deleting the environment variable of PYTHON_VERSION removes it from the project

Actual output

The variable still set.

Steps to reproduce

  1. Create a pages project with an environment variable
  2. Delete the environment variable
  3. The environment variable stays

Additional factoids

It appears to be an issue with the backend API, as the PATCH request has the variable removed, but the response still has it. Looking at how the dashboard handles it, it sets the variable as a null value.

References

No response

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

jacobbednarz commented 1 year ago

what you're seeing here is a consequence of the service using a HTTP PATCH. as HTTP schemantics for PATCH are (generally) "only modify what changes in the payload" you can't really know what to remove. that is where a PUT request is usually a better choice which gives you the entirety of the resource picture.

@WalshyDev is this something you can address in the service itself when parameters are removed from the env var payloads?

WalshyDev commented 1 year ago

Yeah as mentioned, this is a PATCH not PUT so expected from an API perspective.

imo the service should not change here. { env_vars: { ENV: {} } } is a lot less explicit than { env_vars: { ENV: null } } for removal I'd say that an empty env object is expected to not change (just like an empty root project does not change).