rissson / terraform-provider-rgw

Mirror for https://gitlab.com/lama-corp/infra/tools/terraform-provider-rgw
MIT License
7 stars 1 forks source link

Plugin crashed if subuser exists #1

Closed b1ackbeardast closed 2 years ago

b1ackbeardast commented 2 years ago

Hey! I get an error:

bi@tpad:~/git/rgw$ terraform plan
rgw_user.test_user2: Refreshing state... [id=test2]
rgw_user.test_user: Refreshing state... [id=test]
rgw_user.my_user: Refreshing state... [id=my_user]
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with rgw_user.test_user2,
│   on main.tf line 35, in resource "rgw_user" "test_user2":
│   35: resource "rgw_user" "test_user2" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-rgw_v0.1.0 plugin:

panic: interface conversion: interface {} is map[string]interface {}, not struct { ID string; Permissions string }

goroutine 103 [running]:
terraform-provider-rgw/rgw.flattenRgwSubuser(0xc86ee0, 0xc000643e60, 0x0, 0x0)
        terraform-provider-rgw/rgw/resource_user.go:256 +0x1b6
reflect.Value.call(0xc638a0, 0xda6f60, 0x13, 0xd69668, 0x4, 0xc000622ae0, 0x1, 0x1, 0xc000622a18, 0x4c4a70, ...)
        reflect/value.go:476 +0x8e7
reflect.Value.Call(0xc638a0, 0xda6f60, 0x13, 0xc000622ae0, 0x1, 0x1, 0x194, 0xc000456900, 0x0)
        reflect/value.go:337 +0xb9
github.com/thoas/go-funk.mapSlice(0xc463e0, 0xc000180180, 0x97, 0xc638a0, 0xda6f60, 0x13, 0x7f266a704600, 0x20300000000000, 0xc000622bd0)
        github.com/thoas/go-funk@v0.9.1/transform.go:123 +0x3a6
github.com/thoas/go-funk.mapFn(0xc463e0, 0xc000180180, 0xc638a0, 0xda6f60, 0xd69309, 0x3, 0xc6b940, 0xd36401, 0xc000180180)
        github.com/thoas/go-funk@v0.9.1/transform.go:226 +0x276
github.com/thoas/go-funk.Map(0xc463e0, 0xc000180180, 0xc638a0, 0xda6f60, 0xc000449bc8, 0x0)
        github.com/thoas/go-funk@v0.9.1/transform.go:199 +0x65
terraform-provider-rgw/rgw.flattenRgwUser(0xc0003d87b0, 0x5, 0xc0003d87b5, 0x5, 0xc0003d87ba, 0x5, 0xc0003d87c0, 0xc0003d87c8, 0xc0005b8a80, 0x1, ...)
        terraform-provider-rgw/rgw/resource_user.go:314 +0x30f
terraform-provider-rgw/rgw.resourceUserRead(0xeea0a8, 0xc000084780, 0xc0005d6000, 0xd2a680, 0xc0006ce740, 0xc0005b2aa0, 0xc0006ed908, 0x40e0f8)
        terraform-provider-rgw/rgw/resource_user.go:368 +0x2b8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc00027aa80, 0xeea038, 0xc0006ceb40, 0xc0005d6000, 0xd2a680, 0xc0006ce740, 0x0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.9.0/helper/schema/resource.go:358 +0x17f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc00027aa80, 0xeea038, 0xc0006ceb40, 0xc000253e10, 0xd2a680, 0xc0006ce740, 0xc0005b4258, 0x0, 0x0, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.9.0/helper/schema/resource.go:635 +0x1cb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc00000d470, 0xeea038, 0xc0006ceb40, 0xc0006ceb80, 0xc0006ceb40, 0x40b965, 0xd03820)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.9.0/helper/schema/grpc_provider.go:576 +0x47d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0004cba00, 0xeea0e0, 0xc0006ceb40, 0xc0006d7980, 0xc0004cba00, 0xc0001732f0, 0xc0006e7ba0)
        github.com/hashicorp/terraform-plugin-go@v0.4.0/tfprotov5/tf5server/server.go:298 +0x105
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler(0xd32ae0, 0xc0004cba00, 0xeea0e0, 0xc0001732f0, 0xc0006d7920, 0x0, 0xeea0e0, 0xc0001732f0, 0xc000326240, 0x23f)
        github.com/hashicorp/terraform-plugin-go@v0.4.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:344 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000374fc0, 0xef1198, 0xc000602900, 0xc0006d8300, 0xc000402690, 0x13267f0, 0x0, 0x0, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc000374fc0, 0xef1198, 0xc000602900, 0xc0006d8300, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000400180, 0xc000374fc0, 0xef1198, 0xc000602900, 0xc0006d8300)
        google.golang.org/grpc@v1.32.0/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.32.0/server.go:857 +0x1fd

Error: The terraform-provider-rgw_v0.1.0 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.

My main.tf looks like this:

terraform { 
  required_providers {
    rgw = {
      source = "risson/rgw"
      version = "0.1.0"
    }
  }
}

provider "rgw" {
  endpoint = "http://$my_rgw_endpoint"
}

resource "rgw_user" "my_user" {
  user_id      = "my_user"
  display_name = "My User"
  email = "asdasd@asda.s"
}

resource "rgw_user" "test_user" {
  user_id      = "test"
  display_name = "test"
}

resource "rgw_user" "test_user2" {
  user_id      = "test2"
  display_name = "test2"
}

My cluster version and user information:

# radosgw --version
ceph version 16.2.6 (ee28fb57e47e9f88813e24bbf4c14496ca299d31) pacific (stable)
# radosgw-admin user info --uid=test2
{
    "user_id": "test2",
    "display_name": "test2",
...
    "subusers": [
        {
            "id": "test2:bober",
            "permissions": "read"
        }
    ],
    "keys": [
        {
            "user": "test2:bober",
            "access_key": "xxxx",
            "secret_key": "xxxx"
        },
        {
            "user": "test2",
            "access_key": "xxx",
            "secret_key": "xxx"
        }
    ],
...
}

If I remove the subuser and run the terraform plan everything works.

rissson commented 2 years ago

Hi! Thank you for reporting this issue.

To make sure I can reproduce correctly, can you tell me how exactly you created your user and your subuser?

rissson commented 2 years ago

Should be fixed by https://gitlab.com/lama-corp/infra/tools/terraform-provider-rgw/-/merge_requests/7. I'll release a 0.1.1 once that gets in.

rissson commented 2 years ago

Do you mind trying with https://github.com/rissson/terraform-provider-rgw/releases/tag/0.1.1 and closing if it fixed the issue (which it should)?

b1ackbeardast commented 2 years ago

To make sure I can reproduce correctly, can you tell me how exactly you created your user and your subuser?

Hey! I had a case where I needed to create a read-only s3 key pair. I created a subuser, specifying the parent of the user that I created using your provider. # radosgw-admin subuser create --uid = test2 --subuser = bober --key-type = s3 --access = read And on the next attempt to run terraform, the provider crashed.

Do you mind trying with https://github.com/rissson/terraform-provider-rgw/releases/tag/0.1.1 and closing if it fixed the issue (which it should)?

Okay, thanks for the fix, I'll check it today.

b1ackbeardast commented 2 years ago

As an experiment, I created another subuser for another user with different permissions. # radosgw-admin subuser create --uid=test --subuser=bober3 --key-type=s3 --access=write All changes were correctly pulled in the state. Your fix works, thanks!

  # rgw_user.test_user has been changed
  ~ resource "rgw_user" "test_user" {
        id             = "test"
      ~ keys           = [
            {
                access_key = "хххххх"
                secret_key = "хххххх"
                user       = "test"
            },
          + {
              + access_key = "хххххх"
              + secret_key = "хххххх"
              + user       = "test:bober3"
            },
        ]
      ~ subusers       = [
          + {
              + id          = "test:bober3"
              + permissions = "write"
            },
        ]
        # (12 unchanged attributes hidden)
    }

It would be great if the provider supported to manage subusers and user quotas)

rissson commented 2 years ago

It would be great if the provider supported to manage subusers

Unfortunately, I use https://github.com/ceph/go-ceph/ which does not support creating subusers. Here is the associated issue: https://github.com/ceph/go-ceph/issues/521.

and user quotas

That indeed is on my roadmap, I just have to find time to write it, along with bucket quotas and the associated data sources.