kislerdm / terraform-provider-neon

Terraform provider to manage Neon SaaS resources
https://registry.terraform.io/providers/kislerdm/neon/latest/docs
Mozilla Public License 2.0
42 stars 14 forks source link

`terraform import` doesn't work for project's default compute endpoint #131

Open yurhasko opened 1 day ago

yurhasko commented 1 day ago

Hi there

Import for neon_endpoint doesn't work neither as terraform import via CLI, nor using import block (both were done as described in https://registry.terraform.io/providers/kislerdm/neon/latest/docs/resources/endpoint#import)

Versions

terraform v1.6.3 terragrunt v0.50.14 provider v0.6.3

Affected resources

neon_endpoint

Output with TF_LOG=TRACE

4-12-02T13:49:52.517Z [ERROR] vertex "neon_endpoint.neon_db_main_endpoint (import id \"<REDACTED>\")" error: no endpoint <REDACTED> found
2024-12-02T13:49:52.517Z [TRACE] vertex "neon_endpoint.neon_db_main_endpoint (import id \"<REDACTED>\")": visit complete, with errors
2024-12-02T13:49:52.517Z [TRACE] dag/walk: upstream of "root" errored, so skipping
2024-12-02T13:49:52.517Z [TRACE] vertex "neon_endpoint.neon_db_main_endpoint (expand)": dynamic subgraph encountered errors: no endpoint <REDACTED> found
2024-12-02T13:49:52.517Z [ERROR] vertex "neon_endpoint.neon_db_main_endpoint (expand)" error: no endpoint <REDACTED> found
2024-12-02T13:49:52.517Z [TRACE] vertex "neon_endpoint.neon_db_main_endpoint (expand)": visit complete, with errors
2024-12-02T13:49:52.517Z [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/kislerdm/neon\"] (close)" errored, so skipping
2024-12-02T13:49:52.517Z [TRACE] dag/walk: upstream of "root" errored, so skipping
╷
│ Error: no endpoint <REDACTED> found
│ 
│ 
kislerdm commented 1 day ago

@yurhasko hello! Thanks for raising the issue. Could you please describe how the describe the exact steps followed to import the resource. Also, did I get it right: an attempt to import the default endpoint has been made, correct? Could you please share the use case: what is the rationale behind importing the default project endpoint? What are you trying to achieve? Thanks!

yurhasko commented 1 day ago

The reason to import the default project endpoint was to adjust its settings (enable autoscaling with min and max CUs). I tried to enable autoscaling via dynamic block at the project resource, but it doesn't change anything for existing branches and their compute endpoints. Here's my Terraform config:

resource "project_resource" "project" {
  name                       = var.project_name
  enable_logical_replication = "yes"
  org_id                     = var.organization_id
  pg_version                 = "16"
  history_retention_seconds  = var.history_retention_seconds

  dynamic "endpoint_settings" {
    for_each = var.autoscaling_enabled ? [1] : []
    content {
      autoscaling_limit_min_cu = var.autoscaling_limit_min_cu
      autoscaling_limit_max_cu = var.autoscaling_limit_max_cu
      suspend_timeout_seconds  = var.suspend_timeout_seconds
    }
  }
}

resource "role_resource" "role" {
  project_id = project_resource.project.id
  name       = "role_name"
  branch_id  = project_resource.project.default_branch_id
}

resource "database_resource" "database" {
  project_id = project_resource.project.id
  branch_id  = project_resource.project.default_branch_id
  name       = var.database_name
  owner_name = role_resource.role.name
}

resource "endpoint_resource" "main_endpoint" {
  project_id               = project_resource.project.id
  branch_id                = project_resource.project.default_branch_id
  type                     = "read_write"
  autoscaling_limit_min_cu = var.autoscaling_limit_min_cu
  autoscaling_limit_max_cu = var.autoscaling_limit_max_cu
  suspend_timeout_seconds  = var.suspend_timeout_seconds
}
kislerdm commented 18 hours ago

@yurhasko I see, thanks for sharing details. Please do not import the default resources provisioned with the project for their further modification. It leads to inconsistent terraform state and ultimately defeats the purpose of IaC.

Regarding your use case, did I get it right: the intent was, to modify the autoscaling limits of already provisioned default endpoint, right?

Have you tried configuring the endpoint compute limits without using the "dynamic" block?

Also, please share the manifest you used to provision the env. You only shared the module; how was it configured, what variable values have been used?

Thanks!