elastic / terraform-provider-elasticstack

Terraform provider for Elastic Stack
https://registry.terraform.io/providers/elastic/elasticstack/latest/docs
Apache License 2.0
170 stars 92 forks source link

[Bug] Error importing saved object (dashboard) #580

Open pravan07 opened 8 months ago

pravan07 commented 8 months ago

Describe the bug Trying to import a simple dashboard using the import_saved_objects resource. The file content was obtained from export API. However, I see Value conversion error during terraform apply.

To Reproduce Steps to reproduce the behavior:

  1. Use the following resource resource "elasticstack_kibana_import_saved_objects" "sample_test_dashbaord" { overwrite = false ignore_import_errors = true file_contents = <<-EOT {"attributes":{"description":"","kibanaSavedObjectMeta":{"searchSourceJSON":"{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[]}"},"optionsJSON":"{\"useMargins\":true,\"syncColors\":false,\"syncCursor\":true,\"syncTooltips\":false,\"hidePanelTitles\":false}","panelsJSON":"[{\"type\":\"lens\",\"gridData\":{\"x\":0,\"y\":0,\"w\":24,\"h\":15,\"i\":\"62af4052-0b97-4a24-a240-254a00b05af1\"},\"panelIndex\":\"62af4052-0b97-4a24-a240-254a00b05af1\",\"embeddableConfig\":{\"attributes\":{\"title\":\"\",\"description\":\"\",\"visualizationType\":\"lnsXY\",\"type\":\"lens\",\"references\":[{\"type\":\"index-pattern\",\"id\":\"138a8030-d730-11ee-9898-efd69997acab\",\"name\":\"indexpattern-datasource-layer-6f2581a6-1431-4383-8acb-e964d08ea50b\"}],\"state\":{\"visualization\":{\"title\":\"Empty XY chart\",\"legend\":{\"isVisible\":true,\"position\":\"right\"},\"valueLabels\":\"hide\",\"preferredSeriesType\":\"bar_stacked\",\"layers\":[{\"layerId\":\"6f2581a6-1431-4383-8acb-e964d08ea50b\",\"accessors\":[\"2e2cf943-09c7-4ad6-968a-b9648f0310c4\"],\"position\":\"top\",\"seriesType\":\"bar_stacked\",\"showGridlines\":false,\"layerType\":\"data\",\"xAccessor\":\"e9dfe683-d464-45dc-92e1-f6ff031e6f9a\"}]},\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filters\":[],\"datasourceStates\":{\"formBased\":{\"layers\":{\"6f2581a6-1431-4383-8acb-e964d08ea50b\":{\"columns\":{\"e9dfe683-d464-45dc-92e1-f6ff031e6f9a\":{\"label\":\"Top 5 values of sample_name\",\"dataType\":\"string\",\"operationType\":\"terms\",\"scale\":\"ordinal\",\"sourceField\":\"sample_name\",\"isBucketed\":true,\"params\":{\"size\":5,\"orderBy\":{\"type\":\"column\",\"columnId\":\"2e2cf943-09c7-4ad6-968a-b9648f0310c4\"},\"orderDirection\":\"desc\",\"otherBucket\":true,\"missingBucket\":false,\"parentFormat\":{\"id\":\"terms\"},\"include\":[],\"exclude\":[],\"includeIsRegex\":false,\"excludeIsRegex\":false}},\"2e2cf943-09c7-4ad6-968a-b9648f0310c4\":{\"label\":\"Unique count of sample_id\",\"dataType\":\"number\",\"operationType\":\"unique_count\",\"scale\":\"ratio\",\"sourceField\":\"sample_id\",\"isBucketed\":false,\"params\":{\"emptyAsNull\":true}}},\"columnOrder\":[\"e9dfe683-d464-45dc-92e1-f6ff031e6f9a\",\"2e2cf943-09c7-4ad6-968a-b9648f0310c4\"],\"sampling\":1,\"ignoreGlobalFilters\":false,\"incompleteColumns\":{}}}},\"indexpattern\":{\"layers\":{}},\"textBased\":{\"layers\":{}}},\"internalReferences\":[],\"adHocDataViews\":{}}},\"enhancements\":{}}}]","timeRestore":false,"title":"Sample Dashboard","version":1},"coreMigrationVersion":"8.8.0","created_at":"2024-03-04T15:42:24.791Z","id":"cc252270-da3d-11ee-8d06-677a03624bec","managed":false,"references":[{"id":"138a8030-d730-11ee-9898-efd69997acab","name":"62af4052-0b97-4a24-a240-254a00b05af1:indexpattern-datasource-layer-6f2581a6-1431-4383-8acb-e964d08ea50b","type":"index-pattern"}],"type":"dashboard","typeMigrationVersion":"8.9.0","updated_at":"2024-03-04T15:42:24.791Z","version":"WzY1OCwzOV0="} {"excludedObjects":[],"excludedObjectsCount":0,"exportedCount":1,"missingRefCount":0,"missingReferences":[]} EOT }

  2. Perform terraform apply. Notice the following in the log: Terraform will perform the following actions:

` # elasticstack_kibana_import_saved_objects.sample_test_dashbaord is tainted, so must be replaced -/+ resource "elasticstack_kibana_import_saved_objects" "sample_test_dashbaord" {

Terraform v1.5.3
on linux_amd64
Executing pre-apply hook...
setting files for Vault Auth
Initializing plugins and modules...
elasticstack_kibana_import_saved_objects.sample_test_dashbaord: Destroying... [id=d93f271c-9b75-4d24-940e-5da7d6c1d6cb]
elasticstack_kibana_import_saved_objects.sample_test_dashbaord: Destruction complete after 0s
elasticstack_kibana_import_saved_objects.sample_test_dashbaord: Creating...
╷
│ Error: Provider returned invalid result object after apply
│ 
│ After the apply operation, the provider still indicated an unknown value
│ for elasticstack_kibana_import_saved_objects.sample_test_dashbaord.errors.
│ All values must be known after apply, so this is always a bug in the
│ provider and should be reported in the provider's own repository. Terraform
│ will still save the other known object values in the state.
╵
╷
│ Error: Value Conversion Error
│ 
│   with elasticstack_kibana_import_saved_objects.sample_test_dashbaord,
│   on main.tf line 908, in resource "elasticstack_kibana_import_saved_objects" "sample_test_dashbaord":
│  908: resource "elasticstack_kibana_import_saved_objects" "sample_test_dashbaord" {
│ 
│ An unexpected error was encountered trying to convert from struct value.
│ This is always an error in the provider. Please report the following to the
│ provider developer:
│ 
│ error retrieving field names from struct tags: errors[0]: need a struct tag
│ for "tfsdk" on ID
╵
Executing post-apply hook...
removing files used for Vault Auth
Operation failed: failed running terraform apply (exit 1)

Versions (please complete the following information):

gaetanars commented 6 months ago

Same bug for me with provider version 0.11.2

scarnicero commented 4 months ago

Same issue here with provider version 0.11.3. Any tentative ETA for the fix? Thanks in advance

wbaker23 commented 4 months ago

Setting overwrite = true and space_id in the resource block fixed the error for me.

scarnicero commented 4 months ago

Setting overwrite = true and space_id in the resource block fixed the error for me.

Didn't work for me. Maybe I'm missing any other required parameter?

dbalucas commented 4 months ago

Same issue here with Versions:

OS: linux_amd64 Terraform Version v1.9.0 Provider version 0.11.4