OpenNebula / terraform-provider-opennebula

Terraform provider for OpenNebula
https://www.terraform.io/docs/providers/opennebula/
Mozilla Public License 2.0
63 stars 53 forks source link

`opennebula_service`: Plugin did not respond #445

Closed anabel1012 closed 1 year ago

anabel1012 commented 1 year ago

Description

Hello,

I am trying to deploy a service from Terraform but I find this error. Could you help me?

opennebula_service.ubuntu_service: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with opennebula_service.ubuntu_service,
│   on one_create_service.tf line 18, in resource "opennebula_service" "ubuntu_service":
│   18: resource "opennebula_service" "ubuntu_service" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more
│ details.
╵

Terraform and Provider version

Terraform v1.4.2
on darwin_arm64
+ provider registry.terraform.io/opennebula/opennebula v1.2.0

Affected resources and data sources

opennebula_service

Terraform configuration

resource "opennebula_service" "ubuntu_service" {
  name           = "service-template-test"
  template_id    = 2
}

Expected behavior

Service to be deployed

Actual behavior

The terraform-provider-opennebula_v1.2.0 plugin crashed!

Steps to Reproduce

terraform init terraform apply

Debug output

No response

Panic output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x100737540]

goroutine 51 [running]:
github.com/OpenNebula/one/src/oca/go/src/goca.(*STemplateController).Instantiate(0x14000636ba8, {0x0, 0x0})
        github.com/OpenNebula/one/src/oca/go/src/goca@v0.0.0-20230301133003-197f04efa071/service_template.go:159 +0x260
github.com/OpenNebula/terraform-provider-opennebula/opennebula.resourceOpennebulaServiceCreate({0x100c867a8, 0x140004a5320}, 0x14000564e00, {0x100b3ba60?, 0x14000516980})
        github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_service.go:164 +0xe4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x14000476380, {0x100c867e0, 0x1400055ecf0}, 0xd?, {0x100b3ba60, 0x14000516980})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:707 +0xec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x14000476380, {0x100c867e0, 0x1400055ecf0}, 0x14000611ad0, 0x14000564b80, {0x100b3ba60, 0x14000516980})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:837 +0x874
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x14000205758, {0x100c867e0?, 0x1400055ebd0?}, 0x1400007d090)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xb94
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x1400035d040, {0x100c867e0?, 0x1400055e3c0?}, 0x14000368850)
        github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/tf5server/server.go:818 +0x3c0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x100c4c1c0?, 0x1400035d040}, {0x100c867e0, 0x1400055e3c0}, 0x140003687e0, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x174
google.golang.org/grpc.(*Server).processUnaryRPC(0x140003641e0, {0x100c897e0, 0x14000489380}, 0x1400018e000, 0x140004901e0, 0x10115a6a0, 0x0)
        google.golang.org/grpc@v1.50.1/server.go:1340 +0xb90
google.golang.org/grpc.(*Server).handleStream(0x140003641e0, {0x100c897e0, 0x14000489380}, 0x1400018e000, 0x0)
        google.golang.org/grpc@v1.50.1/server.go:1713 +0x840
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.50.1/server.go:965 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.50.1/server.go:963 +0x298

Important factoids

No response

References

No response

frousselet commented 1 year ago

Reproduced on my side. We will work on it for the v1.2.1 release.

treywelsh commented 1 year ago

Ok, I'm able to create the service from a template on minione when everything is configured so I'll need more informations. I reproduced the error with flow_endpoint = "" Did you define flow_endpoint in the provider configuration ? (see doc)

Are you able to create a service from sunstone ? (the oneflow service has to be configured and running)

At least It appears that we're missing a basic check somewhere in the provider but overall it seems to work

anabel1012 commented 1 year ago

Thank you for the quick answer!

Yes, I can create services from the GUI and they work correctly. However, I had not defined the variable flow_endpoint but with the rest of the resources it works perfectly just pointing to endpoint. If I define it, I get the following:

opennebula_service.ubuntu_service: Creating...
╷
│ Error: Failed to instantiate service
│ 
│   with opennebula_service.ubuntu_service,
│   on one_create_service.tf line 19, in resource "opennebula_service" "ubuntu_service":
│   19: resource "opennebula_service" "ubuntu_service" {
│ 
│ <!DOCTYPE html>
│ <html>
│ <head>
│   <style type="text/css">
│   body { text-align:center;font-family:helvetica,arial;font-size:22px;
│     color:#888;margin:20px}
│   #c {margin:0 auto;width:500px;text-align:left}
│   </style>
│ </head>
│ <body>
│   <h2>Sinatra doesn’t know this ditty.</h2>
│   <img src='http://10.X.X.X:2474/__sinatra__/404.png'>
│   <div id="c">
│     Try this:
│     <pre>post &#x27;&#x2F;RPC2&#x2F;service_template&#x2F;14&#x2F;action&#x27; do
│   &quot;Hello World&quot;
│ end
│ </pre>
│   </div>
│ </body>
│ </html>
│ 
treywelsh commented 1 year ago

Not sure of what this error is, this seems to be an error returned from Goca: https://github.com/OpenNebula/one/blob/master/src/oca/go/src/goca/service_template.go#L136

But the Goca errors in service template resource lack of a bit of context, I suspect this to be returned at this line: https://github.com/OpenNebula/one/blob/master/src/oca/go/src/goca/service_template.go#L163

At first glance I don't know who made an error here, is oneflow properly configured ? is it an error from Goca ? from the provider ? There is some old issues around sinatra in the ONE repository, not sure it helps: https://github.com/OpenNebula/one/search?q=ditty&type=issues

This will require some more investigations

anabel1012 commented 1 year ago

Thank you, I look forward to the resolution!

Do you have an estimated date for v1.2.1 release?

frousselet commented 1 year ago

Hello @anabel1012,

I just merged the pull request fixing the crash. I keep the issue open for further investigation.

treywelsh commented 1 year ago

I took some content from the test files just to see if I was able to deploy a service (the vm_template value has to be updated to select an existing template ID), and it works. Even when I made some errors I got errors from OpenNebula etc.

So, are you able to make deploy something like this :

resource "opennebula_service_template" "service_template" {
  name        = "ig1-one-acceptance-svc"
  permissions = "760"
  template    = <<EOF
{
    "TEMPLATE": {
        "BODY": {
            "name": "ig1-one-acceptance-svc",
            "deployment": "straight",
            "roles": [{
                "name": "master",
                "cardinality": 3,
                "vm_template": 2,
                "min_vms": 2
            }]
        }
    }
}
EOF
}

resource "opennebula_service" "service" {
  name        = "ig1-one-acceptance-svc-01"
  permissions = "760"
  template_id = opennebula_service_template.service_template.id
}

If yes, could you provide an example to reproduce your problem ?

As a side note I made some tests with minione, it seems that timeouts are sometimes a bit short and not user configurable, this should be improved.

anabel1012 commented 1 year ago

Hello again @treywelsh @frousselet ! I saw that a new version was released so I have returned to the issue again. But the error is still the same with v1.2.2. See below:

Terraform will perform the following actions:

  # opennebula_service.service will be created
  + resource "opennebula_service" "service" {
      + gid         = (known after apply)
      + gname       = (known after apply)
      + id          = (known after apply)
      + name        = "ig1-one-acceptance-svc-01"
      + networks    = (known after apply)
      + permissions = "760"
      + roles       = (known after apply)
      + state       = (known after apply)
      + template_id = (known after apply)
      + uid         = (known after apply)
      + uname       = (known after apply)
    }

  # opennebula_service_template.service_template will be created
  + resource "opennebula_service_template" "service_template" {
      + gid         = (known after apply)
      + gname       = (known after apply)
      + id          = (known after apply)
      + name        = "ig1-one-acceptance-svc"
      + permissions = "760"
      + template    = jsonencode(
            {
              + TEMPLATE = {
                  + BODY = {
                      + deployment = "straight"
                      + name       = "ig1-one-acceptance-svc"
                      + roles      = [
                          + {
                              + cardinality = 3
                              + min_vms     = 2
                              + name        = "master"
                              + vm_template = 2
                            },
                        ]
                    }
                }
            }
        )
      + uid         = (known after apply)
      + uname       = (known after apply)
    }

Plan: 2 to add, 0 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

opennebula_service_template.service_template: Creating...
╷
│ Error: Failed to create the service template
│ 
│   with opennebula_service_template.service_template,
│   on one_resource_service.tf line 19, in resource "opennebula_service_template" "service_template":
│   19: resource "opennebula_service_template" "service_template" {
│ 
│ <!DOCTYPE html>
│ <html>
│ <head>
│   <style type="text/css">
│   body { text-align:center;font-family:helvetica,arial;font-size:22px;
│     color:#888;margin:20px}
│   #c {margin:0 auto;width:500px;text-align:left}
│   </style>
│ </head>
│ <body>
│   <h2>Sinatra doesn’t know this ditty.</h2>
│   <img src='http://IP_FLOW_ENDPOINT/__sinatra__/404.png'>
│   <div id="c">
│     Try this:
│     <pre>post &#x27;&#x2F;RPC2&#x2F;service_template&#x27; do
│   &quot;Hello World&quot;
│ end
│ </pre>
│   </div>
│ </body>
│ </html>
│ 
╵

Do you have an estimated release date for version v1.3.0? Thanks!

benjamb commented 1 year ago

@anabel1012 I hit a very similar issue with getting the Sinatra doesn’t know this ditty error response. What worked for me was dropping the /RPC2 path from the flow endpoint.

vickmp commented 1 year ago

Hi @anabel1012 the error comes from Sinatra (OneFlow API server) indicating that the endpoint is not valid. The /RPC2 path only applies to the main OpenNebula endpoint, not for the OneFlow endpoint. So, as @benjamb said, it should be removed.

I just realized that this error is also present in the documentation, so it should be fixed with this PR that I have already opened. Please confirm if after modifying the endpoint everything works as expected.