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

`Error: error adding MongoDB Private Service Endpoint Connection(AWS) to a Private Endpoint (): endpointServiceID is invalid because must be set` #731

Closed sagefarrenholz closed 2 years ago

sagefarrenholz commented 2 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

Fails on Github Actions Runner with: hashicorp/setup-terraform@v1 Also fails locally with environment:

Terraform v1.2.0
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.9.0
+ provider registry.terraform.io/mongodb/mongodbatlas v1.3.1

provider info

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.9.0"
    }
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "1.3.1"
    }
  }
  backend "s3" {
    bucket = "blueprint-terraform-states"
    key    = "terraform.tfstate"
    region = "us-east-2"
  }
}

provider "mongodbatlas" {} # Uses env variables for login keys

Terraform Configuration File

resource "mongodbatlas_privatelink_endpoint" "privatelink" {
  project_id    = local.project_id
  provider_name = "AWS"
  region        = local.region
}

resource "aws_vpc_endpoint" "ptfe_service" {
  vpc_id            = module.vpc.vpc_id
  service_name      = mongodbatlas_privatelink_endpoint.privatelink.endpoint_service_name
  vpc_endpoint_type = "Interface"
  subnet_ids        = [module.vpc.private_subnets[0]]
}

resource "mongodbatlas_privatelink_endpoint_service" "mongoatlasdb_service" {
  project_id          = mongodbatlas_privatelink_endpoint.privatelink.project_id
  private_link_id     = mongodbatlas_privatelink_endpoint.privatelink.private_link_service_resource_id
  endpoint_service_id = aws_vpc_endpoint.ptfe_service.id
  provider_name       = "AWS"
}

Steps to Reproduce

Adding any string to the endpoint_service_id field causes this error. Destroyed and reupped the whole private link on Atlas as well as calling terraform refresh before hand.

Expected Behavior

Should create with VPC Endpoint Service for the private link. The private link is successfully created as well as the endpoint interface but not the service.

Actual Behavior

Fails with error:

mongodbatlas_privatelink_endpoint_service.mongoatlasdb_service: Creating...
╷
│ Error: error adding MongoDB Private Service Endpoint Connection(AWS) to a Private Endpoint (): endpointServiceID is invalid because must be set
│ 
│   with mongodbatlas_privatelink_endpoint_service.mongoatlasdb_service,
│   on mongodbatlas.tf line 39, in resource "mongodbatlas_privatelink_endpoint_service" "mongoatlasdb_service":
│   39: resource "mongodbatlas_privatelink_endpoint_service" "mongoatlasdb_service" {
│ 
╵

Error: Terraform exited with code 1.
Error: Process completed with exit code 1.

Debug Output

Terraform with TF_LOG=TRACE doesn't provide much more info on error info

Additional Context

Replicating the first example from here: https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_service#endpoint_service_id

sagefarrenholz commented 2 years ago

I was able to manually get it working by punching in my vpc id, subnet, and vpc endpoint id on the web app. Non-ideal but working.

themantissa commented 2 years ago

@sagefarrenholz if you have the logs they help us, not in getting more info on the error per se, but seeing what is being sent in the API calls. That's why they are requested as part of the issue. If you can provide they will help us potentially help you more quickly.