FlexibleEngineCloud / terraform-provider-flexibleengine

Terraform flexibleengine provider
https://www.terraform.io/docs/providers/flexibleengine/
Mozilla Public License 2.0
30 stars 53 forks source link

[CTS] API response is not unmarshalled properly #738

Closed eonpatapon closed 2 years ago

eonpatapon commented 2 years ago

Terraform Version

Terraform v1.1.7
on linux_amd64
+ provider registry.terraform.io/toolbox/flexibleengine v1.28.0

Affected Resource(s)

Terraform Configuration Files

resource "flexibleengine_cts_tracker_v1" "tracker" {
  bucket_name = "xxxx"
  status      = "enabled"
  region      = "eu-west-0"
}

The tracker and bucket was created some time ago. Then plans started to fail with:

Stack trace from the terraform-provider-flexibleengine_v1.25.1 plugin:
panic: runtime error: index out of range [0] with length 0

goroutine 90 [running]:
github.com/terraform-providers/terraform-provider-flexibleengine/flexibleengine.resourceCTSTrackerRead(0xc0004f9480, 0x1454740, 0xc00000c1e0, 0x1eefff0, 0xc000100800)
github.com/terraform-providers/terraform-provider-flexibleengine/flexibleengine/resource_flexibleengine_cts_tracker_v1.go:108 +0x88f

I saw that this was fixed in 1.28.0 via c4e39c8d6ea1183a6eb85fd1174f582055ee65bb, but now with 1.28.0 I get this:

flexibleengine_cts_tracker_v1.tracker: Refreshing state... [id=system]

Error: can not find CTS tracker system

with flexibleengine_cts_tracker_v1.tracker,
on main.tf line 1, in resource "flexibleengine_cts_tracker_v1" "tracker":
resource "flexibleengine_cts_tracker_v1" "tracker" {

Debug Output

Looks like the API response is not what is expected:

2022-04-12T08:50:28.496+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/12 08:50:28 [DEBUG] Unable to parse JSON: json: cannot unmarshal array into Go value of type map[string]interface {}: timestamp=2022-04-12T08:50:28.496+0200
2022-04-12T08:50:28.496+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/12 08:50:28 [DEBUG] API Response Body: [{"bucket_name":"xxxxx","tracker_name":"system","detail":"noBucket","file_prefix_name":"","status":"error"}]: timestamp=2022-04-12T08:50:28.496+0200
2022-04-12T08:50:28.497+0200 [ERROR] vertex "flexibleengine_cts_tracker_v1.tracker" error: can not find CTS tracker system

Related #727

ShiChangkuo commented 2 years ago

@eonpatapon it seems that the API response was changed, can you provide the debug log with API request and response?

the response of Querying a Tracker has two formats:

CTS may support multiple trackers in the future. If the query request GET /v1.0/{project_id}/tracker does not contain parameter tracker_name, the response is in array format. Otherwise, the response is in object format.

eonpatapon commented 2 years ago

@ShiChangkuo here's what I can find:

flexibleengine_s3_bucket_policy.bucket_policies: Refreshing state... [id=xxxxx]
flexibleengine_cts_tracker_v1.tracker: Refreshing state... [id=system]
2022-04-14T09:12:30.251+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [DEBUG] initialize Swift S3 session: timestamp=2022-04-14T09:12:30.251+0200
2022-04-14T09:12:30.251+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [INFO] Building Swift S3 auth structure: timestamp=2022-04-14T09:12:30.251+0200
2022-04-14T09:12:30.251+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [INFO] Setting AWS metadata API timeout to 100ms: timestamp=2022-04-14T09:12:30.251+0200
2022-04-14T09:12:30.251+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [DEBUG] API Request URL: GET https://cts.eu-west-0.prod-cloud-ocb.orange-business.com/v1.0/9f2e36b98a1149aab266626ffbbfXXXX/tracker: timestamp=2022-04-14T09:12:30.251+0200
2022-04-14T09:12:30.251+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [DEBUG] API Request Headers:
Accept: application/json
User-Agent: terraform-provider-flexibleengine golangsdk/2.0.0
X-Auth-Token: ***: timestamp=2022-04-14T09:12:30.251+0200
2022-04-14T09:12:30.726+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [DEBUG] API Response Code: 200: timestamp=2022-04-14T09:12:30.726+0200
2022-04-14T09:12:30.726+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [DEBUG] API Response Headers:
Connection: keep-alive
Content-Length: 115
Content-Type: application/json
Date: Thu, 14 Apr 2022 07:12:30 GMT
Set-Cookie: Path=/;Secure;HttpOnly
Strict-Transport-Security: max-age=16070400; includeSubDomains
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Request-Id: 8628abb8bcb92ddaaf4e729c28197806
X-Xss-Protection: 1; mode=block;: timestamp=2022-04-14T09:12:30.726+0200
2022-04-14T09:12:30.726+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [DEBUG] Unable to parse JSON: json: cannot unmarshal array into Go value of type map[string]interface {}: timestamp=2022-04-14T09:12:30.726+0200
2022-04-14T09:12:30.726+0200 [INFO]  provider.terraform-provider-flexibleengine_1.28.0: 2022/04/14 09:12:30 [DEBUG] API Response Body: [{"bucket_name":"xxxxx","tracker_name":"system","detail":"noBucket","file_prefix_name":"","status":"error"}]: timestamp=2022-04-14T09:12:30.726+0200
2022-04-14T09:12:30.727+0200 [ERROR] vertex "flexibleengine_cts_tracker_v1.tracker" error: can not find CTS tracker system
2022-04-14T09:12:30.727+0200 [ERROR] vertex "flexibleengine_cts_tracker_v1.tracker" error: can not find CTS tracker system
2022-04-14T09:12:30.727+0200 [ERROR] vertex "flexibleengine_cts_tracker_v1.tracker (expand)" error: can not find CTS tracker system

I believe the call is: [DEBUG] API Request URL: GET https://cts.eu-west-0.prod-cloud-ocb.orange-business.com/v1.0/9f2e36b98a1149aab266626ffbbfXXXX/tracker:

Where 9f2e36b98a1149aab266626ffbbfXXXX is my tenant ID.

ShiChangkuo commented 2 years ago

@eonpatapon the root reason is the system tracker in error status, I will fixed it asap.