render-oss / terraform-provider-render

Source code for the official Render Terraform provider
40 stars 4 forks source link

Error when updating services with linked environments #10

Closed extronics closed 3 months ago

extronics commented 4 months ago

When using environment groups and linking services to them, somethings a terraform apply fails with a message like this:

│ Error: Error updating service
│
│   with module.render.render_web_service.production_api,
│   on ../../modules/render/api.tf line 1, in resource "render_web_service" "production_api":
│    1: resource "render_web_service" "production_api" {
│
│ Could not update service, unexpected error: could not remove service
│ from environment for move: cannot move service out of environment with
│ linked env groups

The services updates anyways however and a subsequent terraform apply shows no differences between tf files and the infrastructure state.

danlamanna commented 3 months ago

FWIW I was able to reproduce this same behavior.

jakemalachowski commented 3 months ago

Are you able to share more specific repro steps? I have been unable to reproduce this by moving env groups and services in and out of environments.

danlamanna commented 3 months ago

Are you able to share more specific repro steps? I have been unable to reproduce this by moving env groups and services in and out of environments.

This terraform code applies cleanly:

resource "render_project" "test_repro" {
  name = "test-repro"
  environments = {
    "test" : {
      name : "test",
      protected_status : "unprotected"
    }
  }
}

resource "render_web_service" "test_repro" {
  name           = "test-repro"
  environment_id = render_project.test_repro.environments.test.id
  plan           = "starter"
  region         = "ohio"
  start_command  = "gunicorn app:app"

  runtime_source = {
    native_runtime = {
      branch        = "master"
      repo_url      = "https://github.com/render-examples/flask-hello-world"
      build_command = "pip install -r requirements.txt"
      runtime       = "python"
    }
  }
}

resource "render_env_group" "test_repro" {
  name           = "test-repro"
  environment_id = render_project.test_repro.environments.test.id
}

resource "render_env_group_link" "test_repro" {
  env_group_id = render_env_group.test_repro.id
  service_ids  = [render_web_service.test_repro.id]
}

Trivial changes e.g.

-      build_command = "pip install -r requirements.txt"
+      build_command = "pip install -r requirements.txt "

will trigger the error on the next terraform apply, and then further applies are clean.

jakemalachowski commented 3 months ago

The issue has been fixed in v0.2.1.

@danlamanna Your test case runs into a separate issue where the Render API will trim the white space from the start command, which results in an inconsistent result after apply error. We'll work on getting a fix out for that.