mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
230 stars 167 forks source link

[Bug]: mongodbatlas_access_list_api_key returns PATH_PARAM_PARSE_ERROR #2317

Closed peterhubbard-mongodb closed 2 weeks ago

peterhubbard-mongodb commented 1 month ago

Is there an existing issue for this?

Provider Version

v1.15.3

Terraform Version

v1.7.5

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

Trying to restrict access for an API key returns a 400 error:

mongodbatlas_access_list_api_key.test: Creating... ╷ │ Error: error create API key: https://cloud.mongodb.com/api/atlas/v2/orgs/5a05659cd383ad74f1cc1047/apiKeys/ugurosox/accessList POST: HTTP 400 Bad Request (Error code: "PATH_PARAM_PARSE_ERROR") Detail: One or more path parameter in the request URI /api/atlas/v2/orgs/5a05659xxxxx7/apiKeys/uxxxxx/accessList is malformed. Reason: Bad Request. Params: [/api/atlas/v2/orgs/5a05659xxxx/apiKeys/uxxxxx/accessList] │ │ with mongodbatlas_access_list_api_key.test, │ on api_key.tf line 1, in resource "mongodbatlas_access_list_api_key" "test": │ 1: resource "mongodbatlas_access_list_api_key" "test" { │

Documentation claims that "The mongodbatlas_project_ip_access_list_key resource can be used to manage all Programmatic API Keys, regardless of whether they were created at the Organization level or Project level." but this resource does not exist:

╷ │ Error: Invalid resource type │ │ on api_key.tf line 1, in resource "mongodbatlas_project_ip_access_list_key" "test": │ 1: resource "mongodbatlas_project_ip_access_list_key" "test" { │ │ The provider mongodb/mongodbatlas does not support resource type "mongodbatlas_project_ip_access_list_key".

Terraform configuration to reproduce the issue

resource "mongodbatlas_project_ip_access_list_key" "test" {
  org_id = "5a05659xxxxxxxxx"
  ip_address = "104.30.134.186"
  api_key_id = "uxxxxx"
}

OR

resource "mongodbatlas_access_list_api_key" "test" {
  org_id = "5a05659xxxxxxxxx"
  ip_address = "104.30.134.186"
  api_key_id = "uxxxxx"
}

Steps To Reproduce

  1. Create resource mongodbatlas_access_list_api_key as above
  2. Run terraform plan - "# mongodbatlas_access_list_api_key.test will be created"
  3. Run terraform apply

Logs

No response

Code of Conduct

github-actions[bot] commented 1 month ago

Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:

The ticket CLOUDP-251354 was created for internal tracking.

github-actions[bot] commented 1 month ago

This issue has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

AgustinBettati commented 3 weeks ago

Hi @peterhubbard-mongodb.

From the terraform configuration provided it would appear that you are using an incorrect value for the api_key_id attribute.

resource "mongodbatlas_access_list_api_key" "test" {
  org_id = "5a05659xxxxxxxxx"
  ip_address = "104.30.134.186"
  api_key_id = "uxxxxx"
}

Instead of providing the public key value, you must provide the key id (24 character long string). One simple way of obtaining this value is by using the api_keys data source.

Let me know if this solves your issue.

AgustinBettati commented 3 weeks ago

Regarding the mention of mongodbatlas_project_ip_access_list_key in the documentation: This is outdated and is being fixed in https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2337, thanks for bringing it up.

github-actions[bot] commented 2 weeks ago

This issue has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!