Loop conditional and math?

Hi there,
given the variable below, how can I loop through the Kafka.Servers list and test if the loop index match the Kafka.NodeId -1 ?

any recommendation on best way to do this ?

thanks

variable "Kafka.Servers" {
    value: "server1,server2,server3,server4" {}
}

variable "Kafka.NodeId" {
    value "1" {
        machine = ["kafka-1"]
    }

    value "2" {
        machine = ["kafka-2"]
    }

    value "3" {
        machine = ["kafka-3"]
    }

    value "4" {
        machine = ["kafka-4"]
    }
}

Hi @julien.tognazzi

We can give advice on Octopus related problems, but we are not able to help with general coding advice. I’d recommend utilising specific coding forums such as StackOverflow to help you resolve this. You may also be able to find other blogs related to loops and checking indexes from there.

Once you get this working, if there is any Octopus related issues that come up from this, please let us know.

Kind Regards
Sean

My issue is very related to Octopus and its limited abilities, has mentioned here

and I wanted to know if someone had some advice on how to achieve something like this:
#{each kafka in Kafka.Servers}#{if Octopus.Template.Each.Index != Kafka.NodeId}THIS#{/if}THAT#{/each}"

Hi @julien.tognazzi

Thanks for clarifying the scenario you’re trying to use this in.

It seems like the code you have written out is pretty close to what we would recommend. We have this example here that covers a similar scenario to the one you are attempting to use. One thing I would maybe change is to have your index that you are targeting be a variable you set beforehand, but that’s a small nit-pick and shouldn’t affect this.

Is there any particular problem that you are coming across with this? I can see your loop should work correctly, and depending on how your index is accessed that should work as well.

Kind Regards
Sean