terraform-provider-mongodbatlas icon indicating copy to clipboard operation
terraform-provider-mongodbatlas copied to clipboard

plugin crashes during apply: panic: runtime error: invalid memory address or nil pointer dereference

Open amkartashov opened this issue 1 year ago • 4 comments

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v1.3.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v4.34.0
+ provider registry.terraform.io/mongodb/mongodbatlas v1.4.6

Terraform Configuration File

No provider configuration, just env vars MONGODB_ATLAS_PUBLIC_KEY and MONGODB_ATLAS_PRIVATE_KEY

Steps to Reproduce

Can give exact steps, stack is quite big. terraform apply fails on this resource update:

resource "mongodbatlas_cloud_backup_schedule" "this" {
  project_id   = var.atlas_project_id
  cluster_name = var.atlas_cluster_name

  reference_hour_of_day    = 9
  reference_minute_of_hour = 8
  restore_window_days      = 2 # Number of days back in time you can restore to with point-in-time accuracy.

  policy_item_hourly {
    frequency_interval = 12
    retention_unit     = "days"
    retention_value    = 2 # should be greater than or equal to restore_window_days
  }
  policy_item_daily {
    frequency_interval = 1
    retention_unit     = "days"
    retention_value    = 7
  }
  policy_item_weekly {
    frequency_interval = 6 # every Saturday
    retention_unit     = "weeks"
    retention_value    = 4
  }
  policy_item_monthly {
    frequency_interval = 40 # last day of month
    retention_unit     = "months"
    retention_value    = 12
  }

  auto_export_enabled                      = true
  use_org_and_group_names_in_export_prefix = true
  export {
    export_bucket_id = mongodbatlas_cloud_backup_snapshot_export_bucket.this.export_bucket_id
    frequency_type   = "daily"
  }
}

Expected Behavior

apply should work

Actual Behavior

Acquiring state lock. This may take a few moments...
mongodbatlas_cloud_provider_access_authorization.auth_role: Refreshing state... [id=aWQ=:NjJhMDI1NDJmZjQ4OTE1MDQwZjZjMTdm-cHJvamVjdF9pZA==:NjI0ZDQ5MGJkNWUyMzEzODJiYzFhYWIz]
mongodbatlas_cloud_backup_snapshot_export_bucket.this: Refreshing state... [id=aWQ=:NjJhMDJlNmQ4MjQxZGM0ZGYzZWRmMGM2-cHJvamVjdF9pZA==:NjI0ZDQ5MGJkNWUyMzEzODJiYzFhYWIz]
mongodbatlas_cloud_backup_schedule.this: Refreshing state... [id=Y2x1c3Rlcl9uYW1l:c3RhZ2luZw==-cHJvamVjdF9pZA==:NjI0ZDQ5MGJkNWUyMzEzODJiYzFhYWIz]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # mongodbatlas_cloud_backup_schedule.this will be updated in-place
  ~ resource "mongodbatlas_cloud_backup_schedule" "this" {
        id                                       = "Y2x1c3Rlcl9uYW1l:c3RhZ2luZw==-cHJvamVjdF9pZA==:NjI0ZDQ5MGJkNWUyMzEzODJiYzFhYWIz"
      ~ use_org_and_group_names_in_export_prefix = false -> true
        # (9 unchanged attributes hidden)

      + policy_item_daily {
          + frequency_interval = 1
          + retention_unit     = "days"
          + retention_value    = 7
        }

      + policy_item_hourly {
          + frequency_interval = 12
          + retention_unit     = "days"
          + retention_value    = 2
        }

      + policy_item_monthly {
          + frequency_interval = 40
          + retention_unit     = "months"
          + retention_value    = 12
        }

      + policy_item_weekly {
          + frequency_interval = 6
          + retention_unit     = "weeks"
          + retention_value    = 4
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

mongodbatlas_cloud_backup_schedule.this: Modifying... [id=Y2x1c3Rlcl9uYW1l:c3RhZ2luZw==-cHJvamVjdF9pZA==:NjI0ZDQ5MGJkNWUyMzEzODJiYzFhYWIz]
╷
│ Error: Request cancelled
│
│   with mongodbatlas_cloud_backup_schedule.this,
│   on main.tf line 17, in resource "mongodbatlas_cloud_backup_schedule" "this":
│   17: resource "mongodbatlas_cloud_backup_schedule" "this" {
│
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵
Releasing state lock. This may take a few moments...

Stack trace from the terraform-provider-mongodbatlas_v1.4.6 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb84ddc]

goroutine 30 [running]:
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas.cloudBackupScheduleCreateOrUpdate({0xf18288, 0xc000540f00}, 0xc00057f000, 0xc?, {0xc00067dfc8, 0x18}, {0xc00067fa89, 0x7})
        github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/resource_mongodbatlas_cloud_backup_schedule.go:468 +0x93c
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas.resourceMongoDBAtlasCloudBackupScheduleUpdate({0xf18288, 0xc000540f00}, 0xc0002d7880, {0xcbff60?, 0xc0007876f0?})
        github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/resource_mongodbatlas_cloud_backup_schedule.go:348 +0x228
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc00048b880, {0xf182c0, 0xc000151770}, 0xd?, {0xcbff60, 0xc0007876f0})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:741 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00048b880, {0xf182c0, 0xc000151770}, 0xc0004a16c0, 0xc0002d7700, {0xcbff60, 0xc0007876f0})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:847 +0x82c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0001278d8, {0xf182c0?, 0xc000151650?}, 0xc0000987d0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000370a00, {0xf182c0?, 0xc000150e40?}, 0xc0009c9d50)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xd978a0?, 0xc000370a00}, {0xf182c0, 0xc000150e40}, 0xc0009c9ce0, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0003aa000, {0xf1b6a0, 0xc0000da000}, 0xc00018fc20, 0xc00046bda0, 0x141a180, 0x0)
        google.golang.org/[email protected]/server.go:1295 +0xb0b
google.golang.org/grpc.(*Server).handleStream(0xc0003aa000, {0xf1b6a0, 0xc0000da000}, 0xc00018fc20, 0x0)
        google.golang.org/[email protected]/server.go:1636 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/[email protected]/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:930 +0x28a

Error: The terraform-provider-mongodbatlas_v1.4.6 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

ERRO[0021] Terraform invocation failed in /home/me/git/papaya/payments-infrastructure/tf/stg/eu-west-1/atlas/backup/.terragrunt-cache/FWuvv3m9lKKYn6wDeaHNPI2LDTc/X_eyI9N_e2xHR5e_VtuzfvDmYw4/backup  prefix=[/home/me/git/papaya/payments-infrastructure/tf/stg/eu-west-1/atlas/backup]
ERRO[0021] 1 error occurred:
        * exit status 1

Debug Output

2022-10-07T14:51:36.349+0400 [INFO]  Starting apply for mongodbatlas_cloud_backup_schedule.this
2022-10-07T14:51:36.349+0400 [DEBUG] mongodbatlas_cloud_backup_schedule.this: applying the planned Update change
2022-10-07T14:51:36.350+0400 [TRACE] GRPCProvider: ApplyResourceChange
2022-10-07T14:51:36.350+0400 [TRACE] provider.terraform-provider-mongodbatlas_v1.4.6: Received request: @module=sdk.proto tf_provider_addr=provider tf_resource_type=mongodbatlas_cloud_backup_schedule tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:805 tf_proto_version=5.3 tf_req_id=73be348a-7808-5c60-926c-7b4a4b163261 timestamp=2022-10-07T14:51:36.350+0400
2022-10-07T14:51:36.350+0400 [TRACE] provider.terraform-provider-mongodbatlas_v1.4.6: Sending request downstream: tf_provider_addr=provider @caller=github.com/hashicorp/[email protected]/tfprotov5/internal/tf5serverlogging/downstream_request.go:17 tf_proto_version=5.3 tf_req_id=73be348a-7808-5c60-926c-7b4a4b163261 tf_resource_type=mongodbatlas_cloud_backup_schedule tf_rpc=ApplyResourceChange @module=sdk.proto timestamp=2022-10-07T14:51:36.350+0400
2022-10-07T14:51:36.352+0400 [TRACE] provider.terraform-provider-mongodbatlas_v1.4.6: Calling downstream: @module=sdk.helper_schema tf_provider_addr=provider tf_req_id=73be348a-7808-5c60-926c-7b4a4b163261 @caller=github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:846 tf_resource_type=mongodbatlas_cloud_backup_schedule tf_rpc=ApplyResourceChange timestamp=2022-10-07T14:51:36.352+0400
2022-10-07T14:51:36.352+0400 [INFO]  provider.terraform-provider-mongodbatlas_v1.4.6: 2022/10/07 14:51:36 [DEBUG] MongoDB Atlas API Request Details:
---[ REQUEST ]---------------------------------------
DELETE /api/atlas/v1.0/groups/GROUPID/clusters/CLUSTERNAME/backup/schedule HTTP/1.1
Host: cloud.mongodb.com
User-Agent: terraform-provider-mongodbatlas/1.4.6 go-mongodbatlas/0.16.0 (linux;amd64)
Accept: application/json
Accept-Encoding: gzip


-----------------------------------------------------: timestamp=2022-10-07T14:51:36.352+0400
2022-10-07T14:51:37.058+0400 [INFO]  provider.terraform-provider-mongodbatlas_v1.4.6: 2022/10/07 14:51:37 [DEBUG] MongoDB Atlas API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
Content-Length: 628
Content-Type: application/json
Date: Fri, 07 Oct 2022 10:51:37 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: envoy
Strict-Transport-Security: max-age=31536000; includeSubdomains;
X-Content-Type-Options: nosniff
X-Envoy-Upstream-Service-Time: 54
X-Frame-Options: DENY
X-Mongodb-Service-Version: gitHash=539ac661c621e1bf31d9c2206cdd9ae5a3dda603; versionString=v20221005
X-Permitted-Cross-Domain-Policies: none

{
 "autoExportEnabled": true,
 "clusterId": "CLUSTERID",
 "clusterName": "CLUSTERNAME",
 "copySettings": [],
 "export": {
  "exportBucketId": "BUCKETID",
  "frequencyType": "daily"
 },
 "links": [
  {
   "href": "https://cloud.mongodb.com/api/atlas/v1.0/groups/GROUPID/clusters/CLUSTERNAME/backup/schedule",
   "rel": "self"
  },
  {
   "href": "https://cloud.mongodb.com/api/public/v1.0/groups/GROUPID",
   "rel": "https://cloud.mongodb.com/group"
  }
 ],
 "policies": [
  {
   "id": "631b31d821edb05e13868358",
   "policyItems": []
  }
 ],
 "referenceHourOfDay": 9,
 "referenceMinuteOfHour": 8,
 "restoreWindowDays": 2,
 "useOrgAndGroupNamesInExportPrefix": false
}
-----------------------------------------------------: timestamp=2022-10-07T14:51:37.058+0400
2022-10-07T14:51:37.060+0400 [TRACE] provider.terraform-provider-mongodbatlas_v1.4.6: Served request: @module=sdk.proto tf_proto_version=5.3 tf_provider_addr=provider tf_req_id=73be348a-7808-5c60-926c-7b4a4b163261 @caller=runtime/panic.go:838 tf_resource_type=mongodbatlas_cloud_backup_schedule tf_rpc=ApplyResourceChange timestamp=2022-10-07T14:51:37.060+0400
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: panic: runtime error: invalid memory address or nil pointer dereference
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb84ddc]
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: goroutine 45 [running]:
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas.cloudBackupScheduleCreateOrUpdate({0xf18288, 0xc0005a80c0}, 0xc00058b800, 0xc?, {0xc0001588a0, 0x18}, {0xc000034ab9, 0x7})
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/resource_mongodbatlas_cloud_backup_schedule.go:468 +0x93c
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas.resourceMongoDBAtlasCloudBackupScheduleUpdate({0xf18288, 0xc0005a80c0}, 0xc0005a6180, {0xcbff60?, 0xc000611610?})
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/resource_mongodbatlas_cloud_backup_schedule.go:348 +0x228
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc0004b9a40, {0xf182c0, 0xc000214090}, 0xd?, {0xcbff60, 0xc000611610})
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:741 +0x12e
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0004b9a40, {0xf182c0, 0xc000214090}, 0xc00014f380, 0xc0005a6000, {0xcbff60, 0xc000611610})
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:847 +0x82c
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0003c8450, {0xf182c0?, 0xc00047f1d0?}, 0xc000624f00)
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe3c
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0003ae820, {0xf182c0?, 0xc00047e990?}, 0xc0006200e0)
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:818 +0x574
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xd978a0?, 0xc0003ae820}, {0xf182c0, 0xc00047e990}, 0xc000620070, 0x0)
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000003c0, {0xf1b6a0, 0xc0004d31e0}, 0xc0008deea0, 0xc0004b1470, 0x141a180, 0x0)
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   google.golang.org/[email protected]/server.go:1295 +0xb0b
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: google.golang.org/grpc.(*Server).handleStream(0xc0000003c0, {0xf1b6a0, 0xc0004d31e0}, 0xc0008deea0, 0x0)
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   google.golang.org/[email protected]/server.go:1636 +0xa1b
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: google.golang.org/grpc.(*Server).serveStreams.func1.2()
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   google.golang.org/[email protected]/server.go:932 +0x98
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6: created by google.golang.org/grpc.(*Server).serveStreams.func1
2022-10-07T14:51:37.066+0400 [DEBUG] provider.terraform-provider-mongodbatlas_v1.4.6:   google.golang.org/[email protected]/server.go:930 +0x28a
2022-10-07T14:51:37.068+0400 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/mongodb/mongodbatlas/1.4.6/linux_amd64/terraform-provider-mongodbatlas_v1.4.6 pid=30170 error="exit status 2"
2022-10-07T14:51:37.068+0400 [ERROR] plugin.(*GRPCProvider).ApplyResourceChange: error="rpc error: code = Unavailable desc = error reading from server: EOF"
2022-10-07T14:51:37.068+0400 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2022-10-07T14:51:37.068+0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for mongodbatlas_cloud_backup_schedule.this
2022-10-07T14:51:37.068+0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for mongodbatlas_cloud_backup_schedule.this
2022-10-07T14:51:37.068+0400 [TRACE] evalApplyProvisioners: mongodbatlas_cloud_backup_schedule.this is not freshly-created, so no provisioning is required
2022-10-07T14:51:37.068+0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for mongodbatlas_cloud_backup_schedule.this
2022-10-07T14:51:37.068+0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for mongodbatlas_cloud_backup_schedule.this
2022-10-07T14:51:37.069+0400 [ERROR] vertex "mongodbatlas_cloud_backup_schedule.this" error: Plugin did not respond
2022-10-07T14:51:37.069+0400 [TRACE] vertex "mongodbatlas_cloud_backup_schedule.this": visit complete, with errors
2022-10-07T14:51:37.069+0400 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/mongodb/mongodbatlas\"] (close)" errored, so skipping
2022-10-07T14:51:37.069+0400 [TRACE] dag/walk: upstream of "root" errored, so skipping
╷
│ Error: Plugin did not respond
│
│   with mongodbatlas_cloud_backup_schedule.this,
│   on main.tf line 17, in resource "mongodbatlas_cloud_backup_schedule" "this":
│   17: resource "mongodbatlas_cloud_backup_schedule" "this" {
│
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

amkartashov avatar Oct 07 '22 10:10 amkartashov

downgraded to 1.4.5 - this fixed the issue

amkartashov avatar Oct 07 '22 11:10 amkartashov

@amkartashov Thank you for the example I will run same scenario to validate using version 1.4.6 when updating use_org_and_group_names_in_export_prefix = false -> true

martinstibbe avatar Oct 10 '22 13:10 martinstibbe

@amkartashov Added this issue to INTMDB-427 to get it corrected

martinstibbe avatar Oct 11 '22 18:10 martinstibbe

@amkartashov Found a possible workaround too if blocked if I set auto_export_enabled = false apply then set it to true apply again and it works

martinstibbe avatar Oct 11 '22 18:10 martinstibbe