thousandeyes / terraform-provider-thousandeyes

ThousandEyes Terraform Provider
Apache License 2.0
21 stars 26 forks source link

[Bug]: "use_public_bgp" field not mapped correctly among others #157

Open cbhoffman opened 8 months ago

cbhoffman commented 8 months ago

What versions are you using?

Currently 2.0.2

What did you expect to happen?

After setting "use-public-bgp" to "true" within our DNS Server test. We expect to see the correct output within the console.

What actually happened?

The tf plan produces expected result. However, no change is made in the console. After tf deploy, the terraform state shows as "false" for the resource. Every subsequent tf plan execution shows a change on the resource amending the "false" default value to "true".

After looking at the SDK, the problem is how the SDK struct field names are mapped to the TF provider schema. Specifically, the problem is with the "CamelCaseToUnderscore" function, that runs within the "ResourceBuildStruct" function.

For example: Within the SDK, in the AgentServer struct, the field name is "UsePublicBGP". After the CamelCaseToUnderscore function is executed it produces a result of "use_publicbgp". This does not match the expected value in the tf provider schema ("use_public_bgp"). This is why our configured value doesn't go any further and why we aren't seeing the expected result being produced in the thousandeyes console.

The CamelCaseToUnderscore function does not seem to handle struct field names where there are multiple capital case letters at the end of the field name. Besides "UsePublicBGP", there are other examples of SDK struct field names which might cause the same problem:

For example:

Terraform code to reproduce the bug

resource "thousandeyes_agent_to_server" "example_agent_to_server_test" {
  test_name      = "Example Agent to Server test set from Terraform provider"
  interval       = 120
  alerts_enabled = false
  use_public_bgp = true

  server = "www.thousandeyes.com"
  port   = 443

  agents {
    agent_id = 3 # Singapore
  }
}

Any additional comments or code?

Potential Solution Ideas

Within this repo:

Amend the problem schema field names

For example:

Refactor the CamelCaseToUnderscore function

Within the SDK repo:

Amend the Struct field names

Steps to reproduce the bug

Isolate the "CamelCaseToUnderscore" function to recreate what happens when the SDK struct field values are mapped to the provider schema.

You will see that some names won't match as expected.

cbhoffman commented 8 months ago

Love to get your feedback on this @joaomper-TE @shahid-te

I'm happy to make a PR depending on the direction you want to go with this.

joaomper-TE commented 8 months ago

Hey @cbhoffman and thanks for reporting this! And it does seem that the problem is exactly what you reported.

We will open a bug on our side and will take care of it in the near-future.