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

PATCH network peering failed with no peer found #14

Closed bobhlo closed 5 years ago

bobhlo commented 5 years ago

The initial deployment succeeded with peer successfully created, but subsequent deployment failed with following error even without any changes. The error indicates that the peer is Not Found under the project, but the peer does exist.

module.dev_jcdigital_test345_prep.null_resource.prep (local-exec): WARNING: The behavior of this command has been altered by the following extension: aks-preview 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: 2019/08/30 11:15:50 [DEBUG] MongoDB Atlas API Response Details: 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: ---[ RESPONSE ]-------------------------------------- 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: HTTP/2.0 404 Not Found 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: Content-Length: 228 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: Content-Type: application/json 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: Date: Fri, 30 Aug 2019 18:15:50 GMT 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: Strict-Transport-Security: max-age=300 2019-08-30T11:15:50.785-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: { 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: "detail": "No peer with ID 5d696758014b767112cf712c exists in project 5d68017b014b767112c77330.", 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: "error": 404, 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: "errorCode": "PEER_NOT_FOUND", 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: "parameters": [ 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: "5d696758014b767112cf712c", 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: "5d68017b014b767112c77330" 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: ], 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: "reason": "Not Found" 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: } 2019-08-30T11:15:50.786-0700 [DEBUG] plugin.terraform-provider-mongodbatlas: ----------------------------------------------------- 2019/08/30 11:15:50 [DEBUG] module.dev_jcdigital_test345_atlas.mongodbatlas_network_peering.rest: apply errored, but we're indicating that via the Error pointer rather than returning it: error updating MongoDB Network Peering Connection (5d696758014b767112cf712c): PATCH https://cloud.mongodb.com/api/atlas/v1.0/groups/5d68017b014b767112c77330/peers/5d696758014b767112cf712c: 404 (request "Not Found") No peer with ID 5d696758014b767112cf712c exists in project 5d68017b014b767112c77330. 2019/08/30 11:15:50 [ERROR] module.dev_jcdigital_test345_atlas: eval: terraform.EvalApplyPost, err: error updating MongoDB Network Peering Connection (5d696758014b767112cf712c): PATCH https://cloud.mongodb.com/api/atlas/v1.0/groups/5d68017b014b767112c77330/peers/5d696758014b767112cf712c: 404 (request "Not Found") No peer with ID 5d696758014b767112cf712c exists in project 5d68017b014b767112c77330. 2019/08/30 11:15:50 [ERROR] module.dev_jcdigital_test345_atlas: eval: terraform.EvalSequence, err: error updating MongoDB Network Peering Connection (5d696758014b767112cf712c): PATCH https://cloud.mongodb.com/api/atlas/v1.0/groups/5d68017b014b767112c77330/peers/5d696758014b767112cf712c: 404 (request "Not Found") No peer with ID 5d696758014b767112cf712c exists in project 5d68017b014b767112c77330.

cdsfmbbl1:bob-jc-sense-tf cdsfblo$ curl --user "unllvfyp:" --digest \

--header "Accept: application/json" \ -- request GET "https://cloud.mongodb.com/api/atlas/v1.0/groups/5d68017b014b767112c77330/peers/5d696758014b767112cf712c" curl: (6) Could not resolve host: request curl: (6) Could not resolve host: GET {"azureDirectoryId":"bd2ac3b4-122a-4000-ac98-779c8efd4722","azureSubscriptionId":"38171a42-9a9e-4fa6-ac1f-43b126efd341","containerId":"5d68017d79358ee73ce91501","errorState":null,"id":"5d696758014b767112cf712c","resourceGroupName":"dev-jcdigital-test345-rg","status":"AVAILABLE","vnetName":"dev-jcdigital-test345-vnet"}

PacoDw commented 5 years ago

Hello @bobhlo thanks for your review, could you share us your terraform configuration to recreate the issue? just avoiding sensitive information.

bobhlo commented 5 years ago

Hi @PacoDw,

Please see following configuration in the module. One thing noted is terraform tried to update resource "mongodbatlas_network_peering.rest" with atlas_cidr_block which was not changed.

module.dev_jcdigital_test345_atlas.mongodbatlas_network_peering.rest will be updated in-place

~ resource "mongodbatlas_network_peering" "rest" {

Code starts below:

# Create file for peering role
data "template_file" "peering_role" {
  template = "${file("${path.module}/templates/peering-role.tpl")}"

  vars = {
    subscription_id   = "${var.subscription_id}"
    rg                = "${var.rg}"
    vnet              = "${var.vnet}"
  }
}

# Peering role files
resource "local_file" "peering_role" {
  content     = "${data.template_file.peering_role.rendered}"
  filename    = "${path.module}/files/{var.environment}-${var.customer}-${var.site}-peering-role.json"
}

# Configure the MongoDB Atlas Provider
provider "mongodbatlas" {
  public_key  = "${var.atlas_public_key}"
  private_key = "${var.atlas_private_key}"
}

# Create a Group
resource "mongodbatlas_project" "rest" {
  org_id = "${var.atlas_org_id}"
  name   = "${var.environment}-${var.customer}-${var.site}"
}

# Create a Container
resource "mongodbatlas_network_container" "rest" {
  project_id          = "${mongodbatlas_project.rest.id}"
  atlas_cidr_block    = "${var.atlas_cidr_block}"
  provider_name       = "${var.atlas_provider_name}"
  region              = "${var.atlas_region}"
}

#Create a Network Peering Connection
resource "mongodbatlas_network_peering" "rest" {
    project_id                = "${mongodbatlas_project.rest.id}"
    atlas_cidr_block          = "${var.atlas_cidr_block}"
    container_id              = "${mongodbatlas_network_container.rest.container_id}"
    provider_name             = "${var.atlas_provider_name}"
    azure_directory_id        = "${var.tenant_id}"
    azure_subscription_id     = "${var.subscription_id}"
    resource_group_name       = "${var.rg}"
    vnet_name                 = "${var.vnet}"
}

# Whitelist REST and JConnect vnets
resource "mongodbatlas_project_ip_whitelist" "rest" {
    project_id = "${mongodbatlas_project.rest.id}"

    whitelist {
      cidr_block = "${var.vnet_cidr}"
      comment    = "cidr block for ${var.vnet}"
    }
    whitelist {
      cidr_block = "${var.prod_jcdigital_jconnect_cidr}"
      comment    = "cidr block for ${var.prod_jcdigital_jconnect_vnet}"
    }
}

# Create Atlas cluster for sense-rest
resource "mongodbatlas_cluster" "rest" {
  project_id   = "${mongodbatlas_project.rest.id}"
  name         = "${var.environment}-${var.customer}-${var.site}"
  disk_size_gb = 64
  num_shards   = 1
  mongo_db_major_version       = "${var.atlas_mongodb_version}"

  replication_factor           = 3
  backup_enabled               = true
  auto_scaling_disk_gb_enabled = true

  //Provider Settings "block"
  provider_name               = "${var.atlas_provider_name}"
  provider_encrypt_ebs_volume = false
  provider_instance_size_name = "${var.atlas_cluster_tier}"
  provider_region_name        = "${var.atlas_region}"
  provider_disk_type_name     = "P6"
}

# DB admin user to manage the database
resource "mongodbatlas_database_user" "rest" {
    username        = "${var.dbuser}"
    password        = "${var.atlas_dbuser_password}"
    project_id      = "${mongodbatlas_project.rest.id}"
    database_name   = "admin"   # DB where db user created

    roles {
        role_name     = "readWrite"
        database_name = "${var.rest_db_name}"
    }
}
PacoDw commented 5 years ago

Thanks, we will check it to find the solution as soon as possible 👍

marinsalinas commented 5 years ago

@bobhlo, Modified your code to make it more readable.

PacoDw commented 5 years ago

Hello @@bobhlo, the issue was resolved you can test it on pr #22

If you have another issue or comments just let us know, thank you.

bobhlo commented 5 years ago

@PacoDw , thanks for the fix. The issue is resolved.