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
242 stars 168 forks source link

`app_id` In documentation is ambiguous for MongoDB Atlas Event Trigger #957

Closed TylerSustare closed 1 year ago

TylerSustare commented 1 year ago

tl;dr;

The app_id to create an Atlas Event Trigger in the documentation is ambiguous. What is your application in the doc talking about here?

app_id - (Required) The ObjectID of your application.

Terraform CLI and Terraform MongoDB Atlas Provider Version

$ terraform --version
Terraform v1.3.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.45.0
+ provider registry.terraform.io/mongodb/mongodbatlas v1.6.1

Terraform Configuration File

# database to keep track of all otters on earth

provider "mongodbatlas" {
  public_key  = var.atlas_public_key
  private_key = var.atlas_private_key
}
resource "mongodbatlas_project" "otter_atlas" {
  name   = "otter-otter"
  org_id = var.atlas_org_id
}
resource "mongodbatlas_advanced_cluster" "otter_free" {
  project_id   = mongodbatlas_project.otter_atlas.id
  name         = "otter-otter"
  cluster_type = "REPLICASET"

  replication_specs {
    region_configs {
      electable_specs {
        instance_size = "M0" # free
      }
      provider_name         = "TENANT"
      backing_provider_name = "AWS"
      region_name           = var.atlas_region
      priority              = 1
    }
  }
  depends_on = [mongodbatlas_project.otter_atlas]
}

resource "mongodbatlas_database_user" "db-user" {
  username           = var.atlas_dbuser
  password           = var.atlas_dbpassword
  auth_database_name = "admin"
  project_id         = mongodbatlas_project.otter_atlas.id
  roles {
    role_name     = "readWriteAnyDatabase"
    database_name = "admin"
  }
  depends_on = [mongodbatlas_project.otter_atlas]
}

resource "mongodbatlas_event_trigger" "otter" {
  project_id             = mongodbatlas_project.otter_atlas.id
  app_id                 = mongodbatlas_advanced_cluster.otter_free.id
  name                   = "Event trigger to AWS Event Bridge"
  type                   = "DATABASE"
  disabled               = false
  config_operation_types = ["INSERT", "UPDATE", "REPLACE", "DELETE"]
  config_database        = "otterotter"
  config_collection      = "otter"
  config_service_id      = "1"
  config_full_document   = true
  event_processors {
    aws_eventbridge {
      config_region     = var.aws_region
      config_account_id = var.aws_account_id
    }
  }
  depends_on = [mongodbatlas_project.otter_atlas, mongodbatlas_advanced_cluster.otter_free]
}

data "mongodbatlas_event_triggers" "otter" {
  project_id = mongodbatlas_event_trigger.otter.project_id
  app_id     = mongodbatlas_event_trigger.otter.app_id
}

Steps to Reproduce

  1. $ terraform apply -auto-approve

Expected Behavior

  1. Created the database trigger with the cluster's ID.
  2. Helpful documentation on what the app should be relating to the app_id

Actual Behavior

│ Error: error creating MongoDB EventTriggers (63935a667e4e335fe1d47e63): POST https://realm.mongodb.com/api/admin/v3.0/groups/63935a667e4e335fe1d47e63/apps/Y2x1c3Rlcl9pZA==:NjM5MzVhNmIwNWUxMTI3M2IzZmFhOGE4-Y2x1c3Rlcl9uYW1l:ZmVlZGJhY2stb3R0ZXI=-cHJvamVjdF9pZA==:NjM5MzVhNjY3ZTRlMzM1ZmUxZDQ3ZTYz/triggers: 404 (request "") app not found
│ 
│   with mongodbatlas_event_trigger.otter,
│   on atlas.tf line 60, in resource "mongodbatlas_event_trigger" "otter":
│   60: resource "mongodbatlas_event_trigger" "otter" {

Debug Output

Additional Context

Not needed.

References

According to the doc for event triggers we need the app_id but the example shows a string as an example. In the Argument Reference section it doesn't help to know what the Application should be.

TylerSustare commented 1 year ago

Based on the POST attempt it looks like I need to create a realm app. But based on creating an event trigger in the console, that doesn't seem like it would be needed to create a trigger in terraform.

Zuhairahmed commented 1 year ago

Thanks @TylerSustare. To learn more about what is and how to pull app_id see here: https://www.mongodb.com/docs/atlas/app-services/admin/api/v3/#section/Project-and-Application-IDs Also you are right, we can make this more clear in our docs. Will add this supporting link to help future users. Appreciate the feedback here.

Zuhairahmed commented 1 year ago

Doc update in internal tracking INTMDB-517. Should go out as part of near term release.

TylerSustare commented 1 year ago

Thank you @Zuhairahmed 😄 I appreciate the link to how to get the app_id via the Atlas App Services API. And that was incredibly quick!

My real question, and what I would hope to get out of the docs though is: what mongodb resource would have this app_id in order to not have to go outside of terraform to use the Atlas App Services API to get the app_id?

TylerSustare commented 1 year ago

For example, I would assume that based on the "Atlas App Services API" getting the app ID from the group/cluster ID then I could use the cluster_id from mongodbatlas_advanced_cluster

When I try to update the TF file like this I still get the same error, just with the cluster ID.

resource "mongodbatlas_event_trigger" "otter" {
  project_id             = mongodbatlas_project.otter_atlas.id
  app_id                 = mongodbatlas_advanced_cluster.otter_free.cluster_id 
Zuhairahmed commented 1 year ago

@TylerSustare thanks for highlighting error, this is going to require a code change. Will include as part of INTMDB-517 and let you know when issue has been resolved. Feel free to reach out if you need anything else in the interim.

github-actions[bot] commented 1 year ago

This issue has gone 30 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 30 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!

TylerSustare commented 1 year ago

bump

Ballymultani commented 1 year ago

Hi, is there any update on this please? We're facing a similar problem.

Zuhairahmed commented 1 year ago

hi @Ballymultani @TylerSustare we should have an update on this soon. feel free to reach out if you need anything else in the interim.

Ballymultani commented 1 year ago

Hi, any update?

Futhark commented 1 year ago

Is there any plan to add App Services resource types?

Zuhairahmed commented 1 year ago

@TylerSustare @Ballymultani fix for this has been picked up for v1.8.1 sprint which should be released in ~3 weeks. @Futhark yes we are planning to integrate Atlas App Services into Atlas Admin API/Terraform Provider, but this is a large effort and still several quarters away. Feel free to reach out in future and can share updates if you need.

Zuhairahmed commented 1 year ago

@TylerSustare @Ballymultani @Futhark v1.8.1 has been published to the Terraform Public Registry! take a spin and let us know if you need anything else.

Zuhairahmed commented 1 year ago

closing this issue, but feel free to re-open if you need anything else here

Alexkuva commented 1 year ago

Hi,

Since the 1.8.1 release how to get app_id (without leaving terraform or adding static values) please? Neither mongodbatlas_advanced_cluster.otter_free.cluster_id or mongodbatlas_advanced_cluster.otter_free.id works