You can't get the index number of an item in a set per Terraform's documentation on dynamic blocks.
key is the map key or list element index for the current element. If the for_each expression produces a set value then key is identical to value and should not be used.
It's probably a smell that there is better way you could approach this problem. But not knowing the full scope of what you are trying to achieve, I also understand that sometimes Terraform requires us to jump through some interesting hoops.
If you are dead set on getting the set index and its values in a dynamic block like you have above then you can convert the set to a map assigning indexes as the keys.
Something like this should work.
zipmap(range(length(var.myset)), var.myset)
Then you can use the resulting map in your for_each block. That should make set.key yield the current index (that was constructed by the range function) and set.value yield the value that was contained in the set.
An important thing to note is that unlike lists, sets are not ordered, so they don't have an index, per se. That's why you can't use the index function like the example above. It's also why I built the indexes using the range function.
It's also possible that you may have to explicitly convert the set to a list - Terraform should do an implicit conversion. But sometimes what it should do and what it does don't always align. And in that case, the statement would be as follows.
zipmap(range(length(var.myset)), toList(var.myset))
This is also explained in Terraform's documentation on types.