opsgenie / terraform-provider-opsgenie

Terraform OpsGenie provider
https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs
Mozilla Public License 2.0
103 stars 137 forks source link

Improve validation for `opsgenie_maintenance`resource #316

Open plaes opened 2 years ago

plaes commented 2 years ago

When currently attempting to create a opsgenie_maintenance with empty rules block, it will crash the provider.

Terraform will perform the following actions:

  # module.maintenance["ops"].opsgenie_maintenance.schedule["2022-06-20T09:00:00Z-2022-06-20T10:00:00Z"] will be created
  + resource "opsgenie_maintenance" "schedule" {
      + id = (known after apply)

      + rules {
          + state = "enabled"

          + entity {}
        }

      + time {
          + end_date   = "2022-06-20T10:00:00Z"
          + start_date = "2022-06-20T09:00:00Z"
          + type       = "schedule"
        }
    }

Terraform Version

Terraform v1.2.5
on darwin_arm64
+ provider registry.terraform.io/opsgenie/opsgenie v0.6.10

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

...

Debug Output

module.maintenance["ops"].opsgenie_maintenance.schedule["2022-06-20T09:00:00Z-2022-06-20T10:00:00Z"]: Creating...
2022-07-22T12:20:46.948+0300 [INFO]  Starting apply for module.maintenance["ops"].opsgenie_maintenance.schedule["2022-06-20T09:00:00Z-2022-06-20T10:00:00Z"]
2022-07-22T12:20:46.948+0300 [DEBUG] module.maintenance["ops"].opsgenie_maintenance.schedule["2022-06-20T09:00:00Z-2022-06-20T10:00:00Z"]: applying the planned Create change
2022-07-22T12:20:46.949+0300 [WARN]  unexpected data: registry.terraform.io/opsgenie/opsgenie:stderr="INFO[2022-07-22T12:20:46.949027+03:00] Client is configured with ApiUrl: api.opsgenie.com, LogLevel: info, RetryMaxCount: 10"
2022-07-22T12:20:46.949+0300 [WARN]  Provider "registry.terraform.io/opsgenie/opsgenie" produced an invalid plan for module.opsgenie["ops"].opsgenie_team.team, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .delete_default_resources: planned value cty.False for a non-computed attribute
module.opsgenie["ops"].opsgenie_team.team: Modifying... [id=424a16bc-8fa5-4ebc-ad9d-e12c42cb45a7]
2022-07-22T12:20:46.949+0300 [INFO]  Starting apply for module.opsgenie["ops"].opsgenie_team.team
2022-07-22T12:20:46.949+0300 [DEBUG] module.opsgenie["ops"].opsgenie_team.team: applying the planned Update change
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: panic: interface conversion: interface {} is nil, not map[string]interface {}
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: 
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: goroutine 98 [running]:
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/opsgenie/terraform-provider-opsgenie/opsgenie.expandOpsgenieMaintenanceEntity(0x14000284a50, 0x1, 0x1, 0x6, 0x140000a0bc8, 0x1, 0x1039d7e60)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/opsgenie/terraform-provider-opsgenie/opsgenie/resource_opsgenie_maintenance.go:242 +0x19c
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/opsgenie/terraform-provider-opsgenie/opsgenie.expandOpsgenieMaintenanceRules(0x14000483680, 0x1400048c270, 0x8, 0x1400049acc0)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/opsgenie/terraform-provider-opsgenie/opsgenie/resource_opsgenie_maintenance.go:222 +0x19c
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/opsgenie/terraform-provider-opsgenie/opsgenie.resourceOpsgenieMaintenanceCreate(0x14000483680, 0x1033f2940, 0x1400000e930, 0xffffffffffffffff, 0x140005116b8)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/opsgenie/terraform-provider-opsgenie/opsgenie/resource_opsgenie_maintenance.go:92 +0xe0
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x140003b21c0, 0x1035654b8, 0x14000122740, 0x14000483680, 0x1033f2940, 0x1400000e930, 0x0, 0x0, 0x0)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/resource.go:329 +0x170
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140003b21c0, 0x1035654b8, 0x14000122740, 0x14000509380, 0x14000483500, 0x1033f2940, 0x1400000e930, 0x0, 0x0, 0x0, ...)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/resource.go:467 +0x4ec
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x1400000d440, 0x1035654b8, 0x14000122740, 0x14000490780, 0x1032c6728, 0x12, 0x0)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/grpc_provider.go:977 +0x870
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x14000596100, 0x103565560, 0x14000122740, 0x140005748c0, 0x0, 0x0, 0x0)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/tf5server/server.go:603 +0x338
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x10350bec0, 0x14000596100, 0x103565560, 0x1400048a690, 0x14000556060, 0x0, 0x103565560, 0x1400048a690, 0x140001b0300, 0x162)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x1c8
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: google.golang.org/grpc.(*Server).processUnaryRPC(0x140001fefc0, 0x10356df38, 0x14000297980, 0x1400012a100, 0x14000116840, 0x1039d8b20, 0x0, 0x0, 0x0)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  google.golang.org/grpc@v1.32.0/server.go:1194 +0x3e8
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: google.golang.org/grpc.(*Server).handleStream(0x140001fefc0, 0x10356df38, 0x14000297980, 0x1400012a100, 0x0)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  google.golang.org/grpc@v1.32.0/server.go:1517 +0xa50
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: google.golang.org/grpc.(*Server).serveStreams.func1.2(0x1400028c170, 0x140001fefc0, 0x10356df38, 0x14000297980, 0x1400012a100)
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  google.golang.org/grpc@v1.32.0/server.go:859 +0x94
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10: created by google.golang.org/grpc.(*Server).serveStreams.func1
2022-07-22T12:20:46.951+0300 [DEBUG] provider.terraform-provider-opsgenie_v0.6.10:  google.golang.org/grpc@v1.32.0/server.go:857 +0x1f8
2022-07-22T12:20:46.952+0300 [ERROR] plugin.(*GRPCProvider).ApplyResourceChange: error="rpc error: code = Unavailable desc = transport is closing"
2022-07-22T12:20:46.952+0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2022-07-22T12:20:46.952+0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/opsgenie/opsgenie/0.6.10/darwin_arm64/terraform-provider-opsgenie_v0.6.10 pid=90942 error="exit status 2"
2022-07-22T12:20:46.952+0300 [ERROR] plugin.(*GRPCProvider).ApplyResourceChange: error="rpc error: code = Unavailable desc = transport is closing"
2022-07-22T12:20:46.952+0300 [ERROR] vertex "module.maintenance[\"ops\"].opsgenie_maintenance.schedule[\"2022-06-20T09:00:00Z-2022-06-20T10:00:00Z\"]" error: Plugin did not respond
2022-07-22T12:20:46.952+0300 [ERROR] vertex "module.opsgenie[\"ops\"].opsgenie_team.team" error: Plugin did not respond
╷
│ Error: Plugin did not respond
│ 
│   with module.maintenance["ops"].opsgenie_maintenance.schedule["2022-06-20T09:00:00Z-2022-06-20T10:00:00Z"],
│   on maintenance/maintenance.tf line 5, in resource "opsgenie_maintenance" "schedule":
│    5: resource "opsgenie_maintenance" "schedule" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.opsgenie["ops"].opsgenie_team.team,
│   on opsgenie/team.tf line 12, in resource "opsgenie_team" "team":
│   12: resource "opsgenie_team" "team" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

OpsGenie provider should have caught it beforehand.

Actual Behavior

OpsGenie provider crashed

plaes commented 2 years ago

There also seems to be issue where 1-hour maintenances after their expiration time have changed their type from scheduleto for-1-hour:

  # module.maintenance["env"].opsgenie_maintenance.schedule["2022-08-01"] will be updated in-place
  ~ resource "opsgenie_maintenance" "schedule" {
        id          = "..."
        # (1 unchanged attribute hidden)

      ~ time {
          ~ type       = "for-1-hour" -> "schedule"
            # (2 unchanged attributes hidden)
        }

        # (1 unchanged block hidden)
    }