Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not imported ScreenBoard got an error unmarshal #105

Closed
officel opened this issue Oct 11, 2018 · 21 comments · Fixed by #404
Closed

Can not imported ScreenBoard got an error unmarshal #105

officel opened this issue Oct 11, 2018 · 21 comments · Fixed by #404

Comments

@officel
Copy link

officel commented Oct 11, 2018

Hi there,

I'm happy to be able to manage the screenboard with DataDog.
But I tried importing an existing board but it got an error.
Am I something wrong?

Terraform Version

$ terraform -v
Terraform v0.11.8
+ provider.aws v1.40.0
+ provider.datadog v1.4.0

Affected Resource(s)

  • datadog_screenboard

Terraform Configuration Files

resource "datadog_screenboard" "security_log" {
}

Of course, other resources can be managed.

Expected Behavior

imported screenboard

Actual Behavior

$ terraform import datadog_screenboard.security_log 465952
datadog_screenboard.security_log: Importing from ID "465952"...

Error: datadog_screenboard.security_log (import id: 465952): import datadog_screenboard.security_log (id: 465952): json: cannot unmarshal number into Go struct field Screenboard.height of type string

Steps to Reproduce

only use import .

Important Factoids

maybe any boards cannot import...

aws integration make some boards, can not imported.

References

https://www.terraform.io/docs/providers/datadog/r/screenboard.html

Please tell me if there is any information. Thank you.

@tobypinder
Copy link
Contributor

tobypinder commented Oct 16, 2018

100% experiencing the same issue (can provide screenboard id on request).

with TF_LOG set to trace I get the following:

2018/10/16 19:19:31 [TRACE] dag/walk: walking "datadog_screenboard.test (import id: {{SCREENBOARD_ID}}})"
2018/10/16 19:19:31 [TRACE] vertex 'root.datadog_screenboard.test (import id: {{SCREENBOARD_ID}}})': walking
2018/10/16 19:19:31 [TRACE] vertex 'root.datadog_screenboard.test (import id: {{SCREENBOARD_ID}}})': evaluating
2018/10/16 19:19:31 [TRACE] [walkImport] Entering eval tree: datadog_screenboard.test (import id: {{SCREENBOARD_ID}}})
2018/10/16 19:19:31 [TRACE] root: eval: *terraform.EvalSequence
2018/10/16 19:19:31 [TRACE] root: eval: *terraform.EvalGetProvider
2018/10/16 19:19:31 [TRACE] root: eval: *terraform.EvalImportState
datadog_screenboard.test: Importing from ID "{{SCREENBOARD_ID}}}"...
2018/10/16 19:19:31 [ERROR] root: eval: *terraform.EvalImportState, err: import datadog_screenboard.test (id: {{SCREENBOARD_ID}}}): json: cannot unmarshal number into Go struct field Screenboard.height of type string
2018/10/16 19:19:31 [ERROR] root: eval: *terraform.EvalSequence, err: import datadog_screenboard.test (id: {{SCREENBOARD_ID}}}): json: cannot unmarshal number into Go struct field Screenboard.height of type string
2018/10/16 19:19:31 [TRACE] [walkImport] Exiting eval tree: datadog_screenboard.test (import id: {{SCREENBOARD_ID}}})
2018/10/16 19:19:31 [TRACE] dag/walk: upstream errored, not walking "provider.datadog (close)"

Error: datadog_screenboard.test (import id: {{SCREENBOARD_ID}}}): import datadog_screenboard.test (id: {{SCREENBOARD_ID}}}): json: cannot unmarshal number into Go struct field Screenboard.height of type string


2018/10/16 19:19:31 [DEBUG] plugin: waiting for all plugin processes to complete...
2018-10-16T19:19:31.850+0100 [DEBUG] plugin.terraform-provider-datadog_v1.4.0_x4: 2018/10/16 19:19:31 [ERR] plugin: plugin server: accept unix /tmp/plugin764063003: use of closed network connection
2018-10-16T19:19:31.852+0100 [DEBUG] plugin: plugin process exited: path={{PATH_TO_PROJECT}}/.terraform/plugins/linux_amd64/terraform-provider-datadog_v1.4.0_x4

@guitarrapc
Copy link

same error on my account, too.

son: cannot unmarshal number into Go struct field Screenboard.height of type string

masterzen pushed a commit to masterzen/terraform-provider-datadog that referenced this issue Nov 17, 2018
…screenboards

This contains the fixes from PR DataDog#194 and DataDog#195 from
zorkian/go-datadog-api and the necessary changes in the provider.
@masci
Copy link
Contributor

masci commented Nov 27, 2018

This is related to an issue we're tracking with #117, let's use that to consolidate communications.

@rodush
Copy link

rodush commented Jan 25, 2019

Same here, tried plugin v1.5.0 and 1.6.0; terraform -v: 0.11.11:

  • module.screenboards.datadog_screenboard.help_screenboard: datadog_screenboard.help_screenboard: json: cannot unmarshal number into Go struct field Screenboard.height of type string

ℹ️ help_screenboard is the resource name in our specific case, not related to the issue directly.

@rodush
Copy link

rodush commented Jan 25, 2019

@masci would you mind reopening this? Exactly the same issue!
Our assumption is it looks like if one modifies the Dashboard in Datadog manually, then it can not pick up by terraform/datadog-provider.

@masci masci reopened this Jan 25, 2019
@rodush
Copy link

rodush commented Jan 25, 2019

Thank you for reopening this, @masci 😉 .
Few more updates (if they could help somehow):
with version of plugin 1.6.0 error is being reported as: json: cannot unmarshal string into Go struct field Screenboard.width of type int

@rodush
Copy link

rodush commented Jan 25, 2019

I wonder, can it be source of problem? https://github.com/terraform-providers/terraform-provider-datadog/blob/master/datadog/resource_datadog_screenboard.go#L555
because plugin does this:
https://github.com/terraform-providers/terraform-provider-datadog/blob/master/datadog/resource_datadog_screenboard.go#L994
And same for the height properly.

Thoughts, @masci ?

Sorry, this message was a result of a brief scan of plugin's source code, don't have time to verify properly.

@rodush
Copy link

rodush commented Feb 6, 2019

Hi! @masci did you have time to look into it, by any chance?

@codezninja
Copy link

any update on this error? I'm having the same issue and wanted to manage the boards via terraform

@officel
Copy link
Author

officel commented Mar 12, 2019

Errors will continue to occur with provider.datadog v1.7.0 ...

terraform import datadog_screenboard.context 421493
datadog_screenboard.context: Importing from ID "421493"...

Error: datadog_screenboard.context (import id: 421493): import datadog_screenboard.context (id: 421493): json: cannot unmarshal string into Go struct field Screenboard.width of type int

@officel
Copy link
Author

officel commented Mar 12, 2019

Whether use create or get with the Screenboard API, width and height will be passed by string.
I think it would be fine to pass the typeInt and its surroundings as a string, what do you think?

( I'm sorry. I'm not familiar with Golang, so I can't say I can fix it all...

see https://docs.datadoghq.com/ja/api/?lang=console#screenboards-get

$ cat create_screen.sh
#!/bin/sh
# Make sure you replace the API and/or APP key below
# with the ones for your account

api_key="yyy"
app_key="xxx"

board_id=$(curl -X POST -H "Content-type: application/json" \
-d '{
        "width": "100%",
        "height": 100,
        "board_title": "dogapi tests",
        "widgets": [
            {
              "type": "image",
              "height": 20,
              "width": 32,
              "y": 7,
              "x": 32,
              "url": "https://path/to/image.jpg"
            }
        ]
    }' \
"https://api.datadoghq.com/api/v1/screen?api_key=${api_key}&application_key=${app_key}" | jq '.id')


curl -X GET \
"https://api.datadoghq.com/api/v1/screen/${board_id}?api_key=${api_key}&application_key=${app_key}"


sh create_screen.sh | jq
{
  "board_title": "dogapi tests",
  "read_only": false,
  "description": null,
  "created": "2019-03-12T06:58:43.527411+00:00",
  "new_id": "z5j-7fv-xxxxxxx",
  "modified": "2019-03-12T06:58:43.527418+00:00",
  "created_by": {
    "disabled": false,
    "handle": "my mail",
    "name": "my name",
    "is_admin": true,
    "role": null,
    "access_role": "adm",
    "verified": true,
    "email": "my mail...",
    "icon": "my avator"
  },
  "height": 100,
  "width": "100%",
  "widgets": [
    {
      "url": "https://path/to/image.jpg",
      "height": 20,
      "width": 32,
      "y": 7,
      "x": 32,
      "type": "image"
    }
  ],
  "id": 99999999999
}

$ terraform import datadog_screenboard.context 610566
datadog_screenboard.context: Importing from ID "610566"...
datadog_screenboard.context: Import complete!
  Imported datadog_screenboard (ID: 610566)
datadog_screenboard.context: Refreshing state... (ID: 610566)

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

@officel
Copy link
Author

officel commented Mar 12, 2019

Organize the plan additionally

$ terraform plan
  ~ datadog_screenboard.context
      height:               "768" => ""
      widget.0.height:      "20" => "15"
      widget.0.text_size:   "" => "auto"
      widget.0.title_align: "" => "left"
      widget.0.title_size:  "0" => "16"
      widget.0.url:         "https://path/to/image.jpg" => ""
      widget.0.width:       "32" => "50"
      widget.0.x:           "32" => "0"
      widget.0.y:           "7" => "0"
      width:                "1024" => ""

width and height is auto fix on DataDog...?

@codezninja
Copy link

i think this might have to do with higher issue in the library upstream. After looking through the code. Not a go expert though. zorkian/go-datadog-api#219

@mohnishbasha
Copy link

mohnishbasha commented Apr 26, 2019

I am also facing the same issue importing a screen board.
Error: datadog_screenboard.dashboard (import id: 276895): import datadog_screenboard.dashboard (id: 276895): json: cannot unmarshal string into Go struct field Screenboard.width of type int 2019/04/26 14:00:42 [ERROR] root: eval: *terraform.EvalImportState, err: import datadog_screenboard.tools_dashboard (id: 276895): json: cannot unmarshal string into Go struct field Screenboard.width of type int 2019/04/26 14:00:42 [ERROR] root: eval: *terraform.EvalSequence, err: import datadog_screenboard.tools_dashboard (id: 276895): json: cannot unmarshal string into Go struct field Screenboard.width of type int

@wbuiejr
Copy link

wbuiejr commented May 17, 2019

I also saw an issue with not being able to import a screenboard that had been touched by human hands. Regrettably, WYSIWYG is the easiest way to develop a screenboard.

When I was working with this, I noticed there was a 'palette_flip' flip attribute on a host map widget which was defined with a boolean value of 'true' in my terraform code, which functions correctly when applied to Datadog, whose value was represented in the JSON (which I could see when editing the screenboard) as the numeral '1'. This was causing an error in Datadog when I was trying to modify a clone of this screenboard. When I edited the JSON backend to spell out "true", the screenboard was happy with it.

I offer this clue in hope that it might help a source maintainer identify where the problem lies.

@facundovictor
Copy link

I'm facing the same problem and it is preventing me to update the provider even to 1.5:

json: cannot unmarshal string into Go struct field Screenboard.height of type int

This will be an issue to go to terraform 0.12.X soon, as I can't update the provider without removing the the dashboard from the state.

@bkabrda
Copy link
Contributor

bkabrda commented Feb 4, 2020

Hey folks 👋 due to some changes in the backend code, this shouldn't be happening as of August 20th 2019. Can you please try again and confirm that it's the case? Thanks!

@officel
Copy link
Author

officel commented Feb 4, 2020

@bkabrda

Thanks for the great news.
But unfortunately the problem has not been solved yet.
It looks like another problem.

can you check this sample?
https://www.terraform.io/docs/providers/datadog/r/screenboard.html

resource "datadog_screenboard" "test" {
  title  = "Test Screenboard"
  # width  = 0
  # height = 0
  widget {
    type       = "free_text"
    x          = 5
    y          = 5
    text       = "test text"
    text_align = "right"
    font_size  = "36"
    color      = "#ffc0cb"
  }

}
  • width and height should be optional but always seem to be updated to null.
  • set width and height to 0, it seems that it will not be changed after that
  • and dashboard is generated, but no widget seems to be created.

@officel
Copy link
Author

officel commented Feb 4, 2020

Widgets are created after several tests of apply & destroy...

@bkabrda
Copy link
Contributor

bkabrda commented Feb 4, 2020

Yeah, I can reproduce the issue with non-empty TF plan when width and height are not set. I'll submit a PR to get that fixed. The widget seems to be created for me (and it was for you eventually as well, so I'm going to assume that this is working fine).

@bkabrda
Copy link
Contributor

bkabrda commented Feb 4, 2020

So I closed this by #404 - please give this a try when the new version of the provider gets released and open a new issue if there are other errors.

Also consider trying the new datadog_dashboard resource, which unifies screenboards and timeboards and we recommend using that instead of the old datadog_screenboard and datadog_timeboard resources: https://www.terraform.io/docs/providers/datadog/r/dashboard.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants