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

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

Open
yurhasko opened this issue Dec 2, 2024 · 4 comments
Open

Comments

@yurhasko
Copy link

yurhasko commented Dec 2, 2024

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
Copy link
Owner

kislerdm commented Dec 2, 2024

@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
Copy link
Author

yurhasko commented Dec 2, 2024

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
Copy link
Owner

kislerdm commented Dec 3, 2024

@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!

@yurhasko
Copy link
Author

yurhasko commented Dec 4, 2024

@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!

Yes, my intent was to modify the autoscaling limits of an already provisioned default endpoint. Can't see the other way to change its settings - maybe, there's a way.

dynamic works fine - the project settings were changed, however, it didn't affect the existing compute endpoint.

Module was called via terragrunt.hcl:

inputs = {
  neon_history_retention_seconds      = 86400
  pg_version                          = "16"
  neon_user                           = "neon_user"
  neon_org_id                         = "<REDACTED"
  neon_project_name                   = "<REDACTED>"
  neon_db_name                        = "neon_db"
  neon_api_key                        = "<REDACTED>"
  neon_region_id                      = "aws-us-east-1"
  autoscaling_enabled                 = true
  autoscaling_limit_min_cu            = 0.25
  autoscaling_limit_max_cu            = 0.5
  autoscaling_suspend_timeout_seconds = 300
}

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

No branches or pull requests

2 participants