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

403 Error while applying a netlify_site_build_settings resource on Netlify's free tier #74

Closed
RogWilco opened this issue Nov 9, 2024 · 6 comments · Fixed by #78 or #90
Closed

Comments

@RogWilco
Copy link

RogWilco commented Nov 9, 2024

I have a fairly straightforward netlify_site_build_settings resource defined, and after importing I am unable to run apply with no changes. Viewing the plan it appears to want to change the read only property functions_region from us-east-1 to us-east-2.

Here's the resource block:

resource "netlify_site_build_settings" "production" {
  site_id = data.netlify_site.production.id
  build_command = "yarn dist"
  production_branch = "main"
  publish_directory = "dist"

  branch_deploy_branches = [
    "main"
  ]
}

The plan output:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # netlify_site_build_settings.production will be updated in-place
  ~ resource "netlify_site_build_settings" "production" {
      ~ branch_deploy_branches     = [
          ~ "master" -> "main",
        ]
      ~ functions_region           = "us-east-1" -> "us-east-2"
      + last_updated               = (known after apply)
        # (12 unchanged attributes hidden)
    }

  # netlify_site_domain_settings.production will be updated in-place
  ~ resource "netlify_site_domain_settings" "production" {
      ~ last_updated                 = "Saturday, 09-Nov-24 14:26:22 PST" -> (known after apply)
        # (5 unchanged attributes hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

And the 403 response:

│ Error: Error updating site build settings
│
│   with netlify_site_build_settings.production,
│   on terraform.tf line 27, in resource "netlify_site_build_settings" "production":
│   27: resource "netlify_site_build_settings" "production" {
│
│ Could not update site build settings for site "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx": "422 Unprocessable Entity: {\"code\":422,\"message\":\"You cannot edit functions
│ regions\"}"

I think the 403 error is correct and it should not be trying to change a read only property. If I try to set it to the preexisting value anyway, the plan output will omit the change. But if I then apply, I'll still get the same 403 error about the same field.

@RogWilco RogWilco changed the title 403 Error while applying a netlify_site_build_settings resource on Netlify 403 Error while applying a netlify_site_build_settings resource on Netlify's free tier Nov 9, 2024
@ramonsnir

This comment was marked as resolved.

@RogWilco

This comment was marked as resolved.

@ramonsnir
Copy link
Member

@RogWilco Can you try to manually specify functions_region = "us-east-1"?

If that works, I'll check if it makes sense to change the default to us-east-1.

Also, I am seeing internally that configuring the functions region will soon become available to all plans, so that would suppress the error too.

@mazxaxz
Copy link

mazxaxz commented Jan 15, 2025

Hey @ramonsnir, I'd like to reopen this issue.

Problem still occurs, I have latest version 0.2.1, I've tried us-east-1, us-east-2, null and not specifying functions_region field at all and API responds with the same 422 status code saying I cannot modify functions_region value on free tier.

I've tried calling API manually and I reckon the issue here is that the field is always populated and API doesn't let you through if you have anything as functions_region, only omitting this field works.

terraform {
  required_providers {
    netlify = {
      source  = "netlify/netlify"
      version = "0.2.1"
    }
  }
}

data "netlify_site" "current" {
  team_slug = var.team_name
  name      = var.site_name
}

resource "netlify_site_build_settings" "current" {
  site_id                = data.netlify_site.current.id
  build_command          = var.build_command
  publish_directory      = "dist"
  production_branch      = var.build_branch
  branch_deploy_branches = [ var.build_branch ]
}

output:

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
  ~ update in-place
Terraform will perform the following actions:
  # module.netlify_docs[0].netlify_site_build_settings.current will be created
  + resource "netlify_site_build_settings" "current" ***
      + branch_deploy_all_branches = false
      + branch_deploy_branches     = [
          + "main",
        ]
      + build_command              = "npm run build"
      + build_image                = (known after apply)
      + deploy_previews            = true
      + functions_region           = (known after apply)
      + last_updated               = (known after apply)
      + pretty_urls                = true
      + production_branch          = "main"
      + publish_directory          = "dist"
      + site_id                    = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      + stop_builds                = false
        # (3 unchanged attributes hidden)
    ***
  # module.netlify_docs[0].netlify_site_domain_settings.current[0] will be updated in-place
  ~ resource "netlify_site_domain_settings" "current" ***
      ~ last_updated                 = "Wednesday, 15-Jan-25 13:54:00 UTC" -> (known after apply)
        # (5 unchanged attributes hidden)
    ***
Plan: 2 to add, 1 to change, 0 to destroy.
module.netlify_docs[0].netlify_site_build_settings.current: Creating...
module.netlify_docs[0].netlify_site_domain_settings.current[0]: Modifying...
module.netlify_docs[0].netlify_site_domain_settings.current[0]: Modifications complete after 0s
Error: Error updating site build settings
  with module.netlify_docs[0].netlify_site_build_settings.current,
  on modules/netlify/site/main.tf line 19, in resource "netlify_site_build_settings" "current":
  19: resource "netlify_site_build_settings" "current" ***
Could not update site build settings for site
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx": "422 Unprocessable Entity:
***\"code\":422,\"message\":\"You cannot edit functions regions\"***"
Error: Terraform exited with code 1.
Error: Process completed with exit code 1.

@ramonsnir ramonsnir reopened this Jan 16, 2025
@ramonsnir
Copy link
Member

Thank you @mazxaxz for reporting this!

I have fixed it, hopefully correctly this time, and added a test case.

@mazxaxz
Copy link

mazxaxz commented Jan 17, 2025

Awesome, thanks @ramonsnir

I'll give it a try right after it is being released as v0.2.2

Have a great day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants