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
238 stars 167 forks source link

Failed to create Atlas network peering container #7

Closed bobhlo closed 4 years ago

bobhlo commented 4 years ago

The json payload looks fine but the plugin throws a 400 error.

main.tf

Configure the MongoDB Atlas Provider

provider "mongodbatlas" { public_key = "${var.mongodb_atlas_username}" private_key = "${var.mongodb_atlas_api_key}" version = "=0.1.0" }

Create a Group

resource "mongodbatlas_project" "rest" { org_id = "${var.mongodb_atlas_org_id}" name = "${var.project_name}" }

Create a Container

resource "mongodbatlas_network_container" "rest" { project_id = "${mongodbatlas_project.rest.id}" atlas_cidr_block = "192.168.32.0/21" provider_name = "Azure" region = "US_EAST_2" }

Excerpt from terraform apply mongodbatlas_network_container.rest: Creating... 2019/08/27 10:33:33 [DEBUG] mongodbatlas_network_container.rest: applying the planned Create change 2019/08/27 10:33:33 [TRACE] GRPCProvider: ApplyResourceChange 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: 2019/08/27 10:33:33 [DEBUG] MongoDB Atlas API Request Details: 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: ---[ REQUEST ]--------------------------------------- 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: POST /api/atlas/v1.0/groups/5d6567b9cf09a25f515f8a89/containers HTTP/1.1 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Host: cloud.mongodb.com 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: User-Agent: go-mongodbatlas0.1 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Content-Length: 81 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Accept: application/json 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Content-Type: application/json 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Accept-Encoding: gzip 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: { 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "atlasCidrBlock": "192.168.32.0/21", 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "providerName": "Azure", 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "region": "US_EAST_2" 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: } 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: 2019-08-27T10:33:33.203-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: ----------------------------------------------------- 2019-08-27T10:33:33.830-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: 2019/08/27 10:33:33 [DEBUG] MongoDB Atlas API Response Details: 2019-08-27T10:33:33.830-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: ---[ RESPONSE ]-------------------------------------- 2019-08-27T10:33:33.830-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: HTTP/2.0 400 Bad Request 2019-08-27T10:33:33.830-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Content-Length: 136 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Content-Type: application/json 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Date: Tue, 27 Aug 2019 17:33:33 GMT 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: Strict-Transport-Security: max-age=300 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: { 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "detail": "Received JSON does not match expected format.", 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "error": 400, 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "errorCode": "INVALID_JSON", 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "parameters": [], 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: "reason": "Bad Request" 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: } 2019-08-27T10:33:33.831-0700 [DEBUG] plugin.terraform-provider-mongodbatlas_v0.1.0_x4: ----------------------------------------------------- 2019/08/27 10:33:33 [DEBUG] mongodbatlas_network_container.rest: apply errored, but we're indicating that via the Error pointer rather than returning it: error creating MongoDB Network Peering Container: POST https://cloud.mongodb.com/api/atlas/v1.0/groups/5d6567b9cf09a25f515f8a89/containers: 400 (request "Bad Request") Received JSON does not match expected format. 2019/08/27 10:33:33 [TRACE] : eval: terraform.EvalMaybeTainted 2019/08/27 10:33:33 [TRACE] EvalMaybeTainted: mongodbatlas_network_container.rest encountered an error during creation, so it is now marked as tainted 2019/08/27 10:33:33 [ERROR] : eval: terraform.EvalSequence, err: error creating MongoDB Network Peering Container: POST https://cloud.mongodb.com/api/atlas/v1.0/groups/5d6567b9cf09a25f515f8a89/containers: 400 (request "Bad Request") Received JSON does not match expected format.

Error: error creating MongoDB Network Peering Container: POST https://cloud.mongodb.com/api/atlas/v1.0/groups/5d6567b9cf09a25f515f8a89/containers: 400 (request "Bad Request") Received JSON does not match expected format.

on main.tf line 15, in resource "mongodbatlas_network_container" "rest": 15: resource "mongodbatlas_network_container" "rest" {

2019-08-27T10:33:33.847-0700 [DEBUG] plugin: plugin process exited: path=/Users/cdsfblo/workspace/tf/bob-jc-sense-tf/modules/site/atlas/.terraform/plugins/darwin_amd64/terraform-provider-mongodbatlas_v0.1.0_x4 pid=76507 2019-08-27T10:33:33.847-0700 [DEBUG] plugin: plugin exited

bobhlo commented 4 years ago

Malformed JSON was caused by provider_name being set to Azure and not AZURE required by Atlas API.

PacoDw commented 4 years ago

Hello @bobhlo, thank you for your review, it resolved on pr #8, you can test it on peering_test branch.

Let us know if you have any comments.

bobhlo commented 4 years ago

Hi @PacoDw,

Thanks for getting it fixed. One thing minor is to fix the error message at https://github.com/terraform-providers/terraform-provider-mongodbatlas/blob/master/mongodbatlas/resource_mongodbatlas_network_container.go#L113

Bob

PacoDw commented 4 years ago

thank you so much for your review! 👍 let me change that.

ghost commented 4 years ago

I am facing the same issue again.