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

mongodbatlas_cloud_backup_schedule with Azure results in "restore window days" mandatory #625

Closed guyguy333 closed 2 years ago

guyguy333 commented 2 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

terraform version: 1.0.7
MongoDB Atlas Provider version: 1.1.1

Terraform Configuration File

# backup policies
resource "mongodbatlas_cloud_backup_schedule" "atlas_backup" {
  project_id   = mongodbatlas_cluster.mongodb_atlas_cluster.project_id
  cluster_name = mongodbatlas_cluster.mongodb_atlas_cluster.name

  policy_item_hourly {
    frequency_interval = 1
    retention_unit     = "days"
    retention_value    = 1
  }
}

Steps to Reproduce

  1. terraform init
  2. terraform apply

Expected Behavior

Cloud backup schedule is setup

Actual Behavior

 Error: error creating a Cloud Backup Schedule: error updating a Cloud Backup Schedule: PATCH https://cloud.mongodb.com/api/atlas/v1.0/groups/XXXXXX/clusters/test/backup/schedule: 400 (request "INVALID_RESTORE_WINDOW") The restore window days should be a positive number.
│ 
│   with module.mongodb-atlas-cluster.mongodbatlas_cloud_backup_schedule.atlas_backup,
│   on ../../../modules/mongodb-atlas-cluster/backup.tf line 2, in resource "mongodbatlas_cloud_backup_schedule" "atlas_backup":
│    2: resource "mongodbatlas_cloud_backup_schedule" "atlas_backup" {

Debug Output

Crash Output

Additional Context

We use exactly the same code with our AWS clusters without any issues for many weeks. We're now having this issue deploying a cluster on Azure.

According to API (https://docs.atlas.mongodb.com/reference/api/cloud-backup/schedule/modify-one-schedule/), restoreWindowDays is optional and value is not set in our HCL.

References

themantissa commented 2 years ago

@guyguy333 thank you for the report. Do you happen to have any trace or debug level logs? If so we can more quickly check what is going on and what is being sent to the API.

guyguy333 commented 2 years ago

@themantissa Sure, here is the request:

PATCH /api/atlas/v1.0/groups/xxxxxxxx/clusters/xxxxxxxx/backup/schedule HTTP/1.1
Host: cloud.mongodb.com
User-Agent: terraform-provider-mongodbatlas/1.1.1 go-mongodbatlas/0.14.0 (darwin;amd64)
Content-Length: 227
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

{
 "referenceHourOfDay": 0,
 "referenceMinuteOfHour": 0,
 "restoreWindowDays": 0,
 "policies": [
  {
   "id": "xxxxxxxx",
   "policyItems": [
    {
     "frequencyInterval": 1,
     "frequencyType": "hourly",
     "retentionUnit": "days",
     "retentionValue": 1
    }
   ]
  }
 ]
}

restoreWindowDays is sent with value 0 but this value is not set in terraform resource and is optional according to API.

HTTP/2.0 400 Bad Request
Content-Length: 153
Content-Type: application/json
Date: Wed, 01 Dec 2021 18:18:28 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: envoy
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload;
X-Envoy-Upstream-Service-Time: 28
X-Frame-Options: DENY
X-Mongodb-Service-Version: gitHash=d9c89be46aa0993ba6c4aa98750aa952d725cd46; versionString=v20211117
X-Permitted-Cross-Domain-Policies: none

{
 "detail": "The restore window days should be a positive number.",
 "error": 400,
 "errorCode": "INVALID_RESTORE_WINDOW",
 "parameters": [],
 "reason": "Bad Request"
}
themantissa commented 2 years ago

Thank you @guyguy333 - that should be sufficient. Let me have the team take a look

themantissa commented 2 years ago

Internal ticket INTMDB-283

themantissa commented 2 years ago

@guyguy333 we are about to release the fix in version 1.2. The pre-release is completed if you'd like to test first. Thank you.

guyguy333 commented 2 years ago

Thank you, we will try to update to 1.2 asap and let you know

themantissa commented 2 years ago

Fixed in 1.2