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
246 stars 179 forks source link

terraform-provider-mongodbatlas_v1.0.1 crashes after creating mongodbatlas_cloud_provider_access_authorization resource #554

Closed nleite closed 3 years ago

nleite commented 3 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

# v1.0.1 

Terraform Configuration File

resource "mongodbatlas_cloud_backup_schedule" "backup_policy" {
  project_id   = var.project_id
  cluster_name = var.cluster_name

  reference_hour_of_day    = var.backup_reference_hour
  reference_minute_of_hour = var.backup_reference_minute
  restore_window_days      = var.pitr_restore_window

  policy_item_hourly {
    frequency_interval = var.snapshot_interval
    retention_unit     = "days"
    retention_value    = var.hourly_retention
  }
  policy_item_daily {
    frequency_interval = 1
    retention_unit     = "days"
    retention_value    = var.daily_retention
  }
  policy_item_weekly {
    frequency_interval = 1
    retention_unit     = "weeks"
    retention_value    = var.weekly_retention
  }
  policy_item_monthly {
    frequency_interval = 1
    retention_unit     = "months"
    retention_value    = var.montly_retention
  }

}

resource "mongodbatlas_cloud_provider_access_setup" "backup_access_setup" {
  project_id    = var.project_id
  provider_name = "AWS"
}

resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
  project_id = var.project_id
  role_id    = mongodbatlas_cloud_provider_access_setup.backup_access_setup.role_id

  aws {
    iam_assumed_role_arn = aws_iam_role.atlas_encrypt_role.arn
  }
}

resource "mongodbatlas_encryption_at_rest" "backup_encryption" {
  project_id = var.project_id
  depends_on = [
    mongodbatlas_cloud_provider_access_setup.backup_access_setup,
    mongodbatlas_cloud_provider_access_authorization.auth_role
  ]

  aws_kms_config {
    customer_master_key_id = aws_kms_key.atlas_backup.key_id
    region                 = local.atlas_region_name
    role_id                = mongodbatlas_cloud_provider_access_authorization.auth_role.role_id
    enabled                = true
  }

}

resource "mongodbatlas_cloud_provider_access" "backup_access" {
  project_id    = var.project_id
  provider_name = "AWS"
}

Steps to Reproduce

  1. upgrade to version 1.0.1 terraform init -upgrade
  2. terraform plan -out tfplan
  3. terraform apply tfplan

Expected Behavior

Encrypted backup keys set on Atlas. No crash expected :trollface:

Actual Behavior

Debug Output

Crash Output

...
module.test-webtask.mongodbatlas_cluster.cluster: Still modifying... [id=Y2x1c3Rlcl9pZA==:NjEyN2UwZDU1NDJjMjYxZG...ZTMzYjA0NjA1-cHJvdmlkZXJfbmFtZQ==:QVdT, 1m20s elapsed]
module.test-webtask.mongodbatlas_cluster.cluster: Still modifying... [id=Y2x1c3Rlcl9pZA==:NjEyN2UwZDU1NDJjMjYxZG...ZTMzYjA0NjA1-cHJvdmlkZXJfbmFtZQ==:QVdT, 1m30s elapsed]
module.test-webtask.mongodbatlas_cluster.cluster: Modifications complete after 1m33s [id=Y2x1c3Rlcl9pZA==:NjEyN2UwZDU1NDJjMjYxZGNmYzRiODdk-Y2x1c3Rlcl9uYW1l:dGVzdC13ZWJ0YXNr-cHJvamVjdF9pZA==:NjEyN2UwZDFkYjkyZTIwZTMzYjA0NjA1-cHJvdmlkZXJfbmFtZQ==:QVdT]
module.test-webtask.module.cluster_backup_policy.mongodbatlas_cloud_provider_access_authorization.auth_role: Modifying... [id=aWQ=:NjEyN2UyZTJkMTAyMjUyMGU2ZWQ5Njcx-cHJvamVjdF9pZA==:NjEyN2UwZDFkYjkyZTIwZTMzYjA0NjA1]
│ Error: Plugin did not respond
│ 
│   with module.test-webtask.module.cluster_backup_policy.mongodbatlas_cloud_provider_access_authorization.auth_role,
│   on ../cluster_backup/backup.tf line 110, in resource "mongodbatlas_cloud_provider_access_authorization" "auth_role":
│  110: resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

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

panic: interface conversion: interface {} is []interface {}, not map[string]interface {}

goroutine 101 [running]:
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas.resourceMongoDBAtlasCloudProviderAccessAuthorizationUpdate(0x1f45d18, 0xc0003a9c80, 0xc000892e80, 0x1bebf20, 0xc0003927a0, 0xc000a1c160, 0x16cb2ca, 0xc0007c2ec0)
        github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/resource_mongodbatlas_cloud_provider_access_authorization.go:193 +0xdb9
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc0002f9dc0, 0x1f45ca8, 0xc0006dec40, 0xc000892e80, 0x1bebf20, 0xc0003927a0, 0x0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/resource.go:364 +0x17f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0002f9dc0, 0x1f45ca8, 0xc0006dec40, 0xc0003e6cb0, 0xc0007c2ec0, 0x1bebf20, 0xc0003927a0, 0x0, 0x0, 0x0, ...)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/resource.go:464 +0x390
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0000c4108, 0x1f45ca8, 0xc0006dec40, 0xc0008245a0, 0xc0006dec40, 0x1cfcb80, 0xc000386a00)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/grpc_provider.go:955 +0x8ef
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc0005c1000, 0x1f45d50, 0xc0006dec40, 0xc0003e6bd0, 0xc0005c1000, 0xc000386ae0, 0xc000177ba0)
        github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/server/server.go:332 +0xb5
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x1cfcb80, 0xc0005c1000, 0x1f45d50, 0xc000386ae0, 0xc0003a91a0, 0x0, 0x1f45d50, 0xc000386ae0, 0xc000184800, 0x3ba)
        github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001c5c00, 0x1f50b58, 0xc000642480, 0xc0001f2900, 0xc0006904e0, 0x250d800, 0x0, 0x0, 0x0)
        google.golang.org/grpc@v1.38.0/server.go:1286 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc0001c5c00, 0x1f50b58, 0xc000642480, 0xc0001f2900, 0x0)
        google.golang.org/grpc@v1.38.0/server.go:1609 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc0000360e0, 0xc0001c5c00, 0x1f50b58, 0xc000642480, 0xc0001f2900)
        google.golang.org/grpc@v1.38.0/server.go:934 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.38.0/server.go:932 +0x1fd

Error: The terraform-provider-mongodbatlas_v1.0.1 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.

Additional Context

This operation was applying a change to already existing deployed cluster.

References

Testing new build that "fixes" https://github.com/mongodb/terraform-provider-mongodbatlas/issues/517

FYI @themantissa

N.

themantissa commented 3 years ago

@nleite I'll have the team look into why the fix did not seem to address the issue.

themantissa commented 3 years ago

Internal ticket INTMDB-255

themantissa commented 3 years ago

Slightly different issue than what we fixed last time but corrected and will be in the next release, 1.0.2.

themantissa commented 3 years ago

We have released the pre-release https://github.com/mongodb/terraform-provider-mongodbatlas/releases/tag/v1.0.2-pre.1 If you @nleite could test and verify before release that would be great.

themantissa commented 3 years ago

1.0.2 is out. Please let us know if any issues remain.

nleite commented 3 years ago

👍 I'm testing this out today. thanks!