favoretti / terraform-provider-adx

Mozilla Public License 2.0
14 stars 5 forks source link

adx_table: Column always wants to be updated. #33

Closed guy-radford-sunswap closed 1 year ago

guy-radford-sunswap commented 1 year ago

Is there an existing issue for this?

Terraform Version

v1.3.7

ADX Provider Version

v0.0.18

Terraform Configuration Files

resource "adx_table" "events" {
  name          = "events"
  database_name = local.axd_database_name

  #.create table events (
  #    event_id: string,
  #    event_timestamp: datetime,
  #    event_enqueuedtime: datetime,
  #    device_id: string,
  #    event_name: string,
  #    version:int,
  #    payload: dynamic
  #)

  column {
    name = "event_id"
    type = "string"
  }
  column {
    name = "event_timestamp"
    type = "datetime"
  }
  column {
    name = "event_write_timestamp"
    type = "datetime"
  }
  column {
    name = "device_id"
    type = "string"
  }
  column {
    name = "event_name"
    type = "string"
  }
  column {
    name = "version"
    type = "int"
  }
  column {
    name = "payload"
    type = "dynamic"
  }
  depends_on = [adx_table.iothub_received_raw_events]
}

Debug Output/Panic Output

# adx_table.events will be updated in-place
  ~ resource "adx_table" "events" {
        id              = "adxedrdevuksouth.uksouth.kusto.windows.net|adxdb-endurance-dev-uksouth|table|events"
        name            = "events"
        # (3 unchanged attributes hidden)

      ~ column {
          ~ name = "['version']" -> "version"
            # (1 unchanged attribute hidden)
        }

        # (6 unchanged blocks hidden)
    }

Expected Behaviour

I would expect the version field to not require changing, this has not chnage since a complete re-build.

Actual Behaviour

TF suggest the version field needs updating, even when it does not.

Thank you

Steps to Reproduce

No response

Important Factoids

No response

References

No response

favoretti commented 1 year ago

Hi there and thank you for reporting this. This is an interesting one. I'll try to reproduce it locally to see if there's something weird happening. Funky part is that Read seems to return version column as an array..

slwbuild commented 1 year ago

We see this one internally a lot. I just haven't gotten around to fixing it (By using some hacky DiffSupression). Essentially the escaping is automatically removed by ADX if not needed for characters like '-' and state is updated accordingly which causes the change on next plan.

slwbuild commented 1 year ago

Looking at it again, it actually seems to be the reverse problem. version might be a type of keyword in ADX and it's trying to escape it for you. Some more research is obviously required for this one (DiffSupression still might fix).

favoretti commented 1 year ago

@guy-radford-sunswap if you rename the column from version to something else - does the effect persist? Also, if version is a keyword - do we want to prohibit columns with that name or kludge around it?

slwbuild commented 1 year ago

ADX allows you to name a column basically anything as long as its escaped. I haven't figured out an elegant solution just yet.

favoretti commented 1 year ago

Normalize everything to escaped form during read and in the state?

slwbuild commented 1 year ago

Yeah I was thinking we just add a diff suppression function on the name where we perform the following:

One question though, is if the input is not escaped and it should be, do we escape it for them to avoid the error from ADX? Some inputs like dashes and other characters ADX will NOT auto-escape for you.

slwbuild commented 1 year ago

Nearly finished with this one. When i added a few acceptance tests to reproduce the above I found some additional bugs related to adding new columns to an existing table (they aren't added properly).

guy-radford-sunswap commented 1 year ago

@guy-radford-sunswap if you rename the column from version to something else - does the effect persist? Also, if version is a keyword - do we want to prohibit columns with that name or kludge around it?

Ill give it ago when I next to a rebuild, probably wont be today...sorry I missed this the other day.