diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ec23c0bc..9c78e4042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Add support for `data_view_id` in the `elasticstack_kibana_slo` resource ([#1305](https://github.com/elastic/terraform-provider-elasticstack/pull/1305)) - Add support for `unenrollment_timeout` in `elasticstack_fleet_agent_policy` ([#1169](https://github.com/elastic/terraform-provider-elasticstack/issues/1169)) - Handle default value for `allow_restricted_indices` in `elasticstack_elasticsearch_security_api_key` ([#1315](https://github.com/elastic/terraform-provider-elasticstack/pull/1315)) +- Fixed `nil` reference in kibana synthetics API client in case of response errors ([#1320](https://github.com/elastic/terraform-provider-elasticstack/pull/1320)) ## [0.11.17] - 2025-07-21 diff --git a/libs/go-kibana-rest/docker-compose.yml b/libs/go-kibana-rest/docker-compose.yml index 9374bdd1c..515a53e3c 100644 --- a/libs/go-kibana-rest/docker-compose.yml +++ b/libs/go-kibana-rest/docker-compose.yml @@ -1,6 +1,6 @@ services: elasticsearch: - image: docker.elastic.co/elasticsearch/elasticsearch:9.1.3@sha256:d620e80b7222e32eff42ac0fc614a0a5753f6ce9859df33b9ddea49c3bf5fb01 + image: docker.elastic.co/elasticsearch/elasticsearch:9.1.2@sha256:d1a8016cf55be8ffec635ed69f5a9acb0c459db35b46a4549ec5b2847a2f170a environment: cluster.name: test discovery.type: single-node @@ -11,7 +11,7 @@ services: ports: - "9200:9200/tcp" set-kibana-password: - image: docker.elastic.co/kibana/kibana:9.1.3@sha256:26792c8e4a68ba0bff3efcc46755f60bf36bb16b2431014c210f2546ca1819ad + image: docker.elastic.co/kibana/kibana:9.0.3@sha256:c4c00a485fbc3619d8373f3bc74e9dd5b5a34380ef50442be4366e8fb57cd50a restart: on-failure links: - elasticsearch @@ -22,7 +22,7 @@ services: elasticsearch: condition: service_started kibana: - image: docker.elastic.co/kibana/kibana:9.1.3@sha256:26792c8e4a68ba0bff3efcc46755f60bf36bb16b2431014c210f2546ca1819ad + image: docker.elastic.co/kibana/kibana:9.0.3@sha256:c4c00a485fbc3619d8373f3bc74e9dd5b5a34380ef50442be4366e8fb57cd50a environment: SERVER_NAME: kibana ELASTICSEARCH_HOSTS: http://es:9200 diff --git a/libs/go-kibana-rest/kbapi/api.kibana_logstash_pipeline.go b/libs/go-kibana-rest/kbapi/api.kibana_logstash_pipeline.go index 698e399b0..458924b24 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_logstash_pipeline.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_logstash_pipeline.go @@ -73,7 +73,7 @@ func newKibanaLogstashPipelineGetFunc(c *resty.Client) KibanaLogstashPipelineGet if resp.StatusCode() == 404 { return nil, nil } - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } logstashPipeline := &LogstashPipeline{} err = json.Unmarshal(resp.Body(), logstashPipeline) @@ -97,7 +97,7 @@ func newKibanaLogstashPipelineListFunc(c *resty.Client) KibanaLogstashPipelineLi } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } logstashPipelinesList := &LogstashPipelinesList{} err = json.Unmarshal(resp.Body(), logstashPipelinesList) @@ -140,7 +140,7 @@ func newKibanaLogstashPipelineCreateOrUpdateFunc(c *resty.Client) KibanaLogstash log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } // Retrive the object to return it @@ -174,7 +174,7 @@ func newKibanaLogstashPipelineDeleteFunc(c *resty.Client) KibanaLogstashPipeline } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return NewAPIError(resp.StatusCode(), resp.Status()) + return NewAPIError(resp.StatusCode(), "%s", resp.Status()) } return nil diff --git a/libs/go-kibana-rest/kbapi/api.kibana_role_management.go b/libs/go-kibana-rest/kbapi/api.kibana_role_management.go index b3a557c1f..faaa2762a 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_role_management.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_role_management.go @@ -100,7 +100,7 @@ func newKibanaRoleManagementGetFunc(c *resty.Client) KibanaRoleManagementGet { if resp.StatusCode() == 404 { return nil, nil } - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } kibanaRole := &KibanaRole{} err = json.Unmarshal(resp.Body(), kibanaRole) @@ -124,7 +124,7 @@ func newKibanaRoleManagementListFunc(c *resty.Client) KibanaRoleManagementList { } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } kibanaRoles := make(KibanaRoles, 0, 1) err = json.Unmarshal(resp.Body(), &kibanaRoles) @@ -165,7 +165,7 @@ func newKibanaRoleManagementCreateOrUpdateFunc(c *resty.Client) KibanaRoleManage } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } // Retrive the object to return it @@ -197,7 +197,7 @@ func newKibanaRoleManagementDeleteFunc(c *resty.Client) KibanaRoleManagementDele } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return NewAPIError(resp.StatusCode(), resp.Status()) + return NewAPIError(resp.StatusCode(), "%s", resp.Status()) } return nil diff --git a/libs/go-kibana-rest/kbapi/api.kibana_save_object.go b/libs/go-kibana-rest/kbapi/api.kibana_save_object.go index a04f18145..03423a42c 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_save_object.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_save_object.go @@ -85,7 +85,7 @@ func newKibanaSavedObjectGetFunc(c *resty.Client) KibanaSavedObjectGet { if resp.StatusCode() == 404 { return nil, nil } - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } var data map[string]interface{} @@ -165,7 +165,7 @@ func newKibanaSavedObjectFindFunc(c *resty.Client) KibanaSavedObjectFind { if resp.StatusCode() == 404 { return nil, nil } - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } var data map[string]interface{} @@ -214,7 +214,7 @@ func newKibanaSavedObjectCreateFunc(c *resty.Client) KibanaSavedObjectCreate { } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } var dataResponse map[string]interface{} err = json.Unmarshal(resp.Body(), &dataResponse) @@ -263,7 +263,7 @@ func newKibanaSavedObjectUpdateFunc(c *resty.Client) KibanaSavedObjectUpdate { } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } var dataResponse map[string]interface{} err = json.Unmarshal(resp.Body(), &dataResponse) @@ -304,7 +304,7 @@ func newKibanaSavedObjectDeleteFunc(c *resty.Client) KibanaSavedObjectDelete { } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return NewAPIError(resp.StatusCode(), resp.Status()) + return NewAPIError(resp.StatusCode(), "%s", resp.Status()) } var dataResponse map[string]interface{} err = json.Unmarshal(resp.Body(), &dataResponse) @@ -356,7 +356,7 @@ func newKibanaSavedObjectExportFunc(c *resty.Client) KibanaSavedObjectExport { } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } data := resp.Body() @@ -396,7 +396,7 @@ func newKibanaSavedObjectImportFunc(c *resty.Client) KibanaSavedObjectImport { } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } var dataResponse map[string]interface{} err = json.Unmarshal(resp.Body(), &dataResponse) diff --git a/libs/go-kibana-rest/kbapi/api.kibana_shorten_url.go b/libs/go-kibana-rest/kbapi/api.kibana_shorten_url.go index 257d9bb44..07c0a35f9 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_shorten_url.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_shorten_url.go @@ -63,7 +63,7 @@ func newKibanaShortenURLCreateFunc(c *resty.Client) KibanaShortenURLCreate { log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } shortenURLResponse := &ShortenURLResponse{} diff --git a/libs/go-kibana-rest/kbapi/api.kibana_spaces.go b/libs/go-kibana-rest/kbapi/api.kibana_spaces.go index 9b1e7a9c7..0b49dfcde 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_spaces.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_spaces.go @@ -87,7 +87,7 @@ func newKibanaSpaceGetFunc(c *resty.Client) KibanaSpaceGet { if resp.StatusCode() == 404 { return nil, nil } - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } kibanaSpace := &KibanaSpace{} @@ -113,7 +113,7 @@ func newKibanaSpaceListFunc(c *resty.Client) KibanaSpaceList { } log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } kibanaSpaces := make(KibanaSpaces, 0, 1) err = json.Unmarshal(resp.Body(), &kibanaSpaces) @@ -148,7 +148,7 @@ func newKibanaSpaceCreateFunc(c *resty.Client) KibanaSpaceCreate { log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } kibanaSpace = &KibanaSpace{} err = json.Unmarshal(resp.Body(), kibanaSpace) @@ -189,7 +189,7 @@ func newKibanaSpaceCopySavedObjectsFunc(c *resty.Client) KibanaSpaceCopySavedObj log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return NewAPIError(resp.StatusCode(), resp.Status()) + return NewAPIError(resp.StatusCode(), "%s", resp.Status()) } data := make(map[string]interface{}) err = json.Unmarshal(resp.Body(), &data) @@ -205,7 +205,7 @@ func newKibanaSpaceCopySavedObjectsFunc(c *resty.Client) KibanaSpaceCopySavedObj } } if len(errors) > 0 { - return NewAPIError(500, strings.Join(errors, "\n")) + return NewAPIError(500, "%s", strings.Join(errors, "\n")) } return nil @@ -231,7 +231,7 @@ func newKibanaSpaceDeleteFunc(c *resty.Client) KibanaSpaceDelete { log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return NewAPIError(resp.StatusCode(), resp.Status()) + return NewAPIError(resp.StatusCode(), "%s", resp.Status()) } @@ -261,7 +261,7 @@ func newKibanaSpaceUpdateFunc(c *resty.Client) KibanaSpaceUpdate { log.Debug("Response: ", resp) if resp.StatusCode() >= 300 { - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } kibanaSpace = &KibanaSpace{} err = json.Unmarshal(resp.Body(), kibanaSpace) diff --git a/libs/go-kibana-rest/kbapi/api.kibana_status.go b/libs/go-kibana-rest/kbapi/api.kibana_status.go index c6ad95539..6aec6a86e 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_status.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_status.go @@ -29,7 +29,7 @@ func newKibanaStatusGetFunc(c *resty.Client) KibanaStatusGet { if resp.StatusCode() == 404 { return nil, nil } - return nil, NewAPIError(resp.StatusCode(), resp.Status()) + return nil, NewAPIError(resp.StatusCode(), "%s", resp.Status()) } kibanaStatus := make(KibanaStatus) err = json.Unmarshal(resp.Body(), &kibanaStatus) diff --git a/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go b/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go index 6389d699f..283c27613 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go @@ -415,6 +415,9 @@ func newKibanaSyntheticsMonitorDeleteFunc(c *resty.Client) KibanaSyntheticsMonit } result, err := unmarshal(resp, []MonitorDeleteStatus{}) + if err != nil { + return nil, err + } return *result, err } } @@ -481,6 +484,9 @@ func newKibanaSyntheticsParameterDeleteFunc(c *resty.Client) KibanaSyntheticsPar } result, err := unmarshal(resp, []ParameterDeleteStatus{}) + if err != nil { + return nil, err + } return *result, err } } @@ -503,9 +509,9 @@ func handleKibanaError(err error, resp *resty.Response) error { kibanaErr := KibanaError{} err := json.Unmarshal(resp.Body(), &kibanaErr) if err != nil { - return NewAPIError(resp.StatusCode(), resp.Status(), err) + return NewAPIError(resp.StatusCode(), "status: %s, err: %s", resp.Status(), err) } - return NewAPIError(resp.StatusCode(), kibanaErr.Message, kibanaErr.Error) + return NewAPIError(resp.StatusCode(), "message: %s, err: %s", kibanaErr.Message, kibanaErr.Error) } return nil } diff --git a/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go b/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go index 1c48454a6..84f121e57 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go @@ -444,6 +444,7 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsPrivateLocationAPI() { created, err := pAPI.Create(ctx, cfg) assert.NoError(s.T(), err) + assert.NotNil(s.T(), created) assert.Equal(s.T(), created.Label, cfg.Label) assert.Equal(s.T(), created.AgentPolicyId, cfg.AgentPolicyId)