How to map scripts to instances in terraform

i have two bash scripts A and B and i am requesting two instances in terraform using vra7 provider. how to run script A to instanceA and script B to instance B using remote-exec. tried with the below code. but getting error.

    resource_configuration = {
              rvar.ip_address = ""
                          }


provisioner "file" {
    source = "/work/scripts/runit.sh"
    destination = "/tmp/runit.sh"

    connection {
    type     = "ssh"
    user     = "${var.username1}"
    host = "${self.resource_configuration.rvar.ip_address[0]}"
    password = "${var.password1}"
    }
  }

  provisioner "remote-exec" {
    inline = [
      "sudo -S <<< ${var.password1} chmod +x /tmp/runit.sh",
      "sudo /tmp/runit.sh"
    ]

    connection {
    type     = "ssh"
    user     = "${var.username1}"
    host = "${self.resource_configuration.rvar.ip_address[0]}"
    password = "${var.password1}"
    }
}

  #second proviioner (file and remote-exec)
  provisioner "file" {
    source = "/work/scripts/runit1.sh"
    destination = "/tmp/runit.sh"

    connection {
    type     = "ssh"
    user     = "${var.username1}"
    host = "${self.resource_configuration.rvar.ip_address[1]}"
    password = "${var.password1}"
    }
  }

  provisioner "remote-exec" {
    inline = [
      "sudo -S <<< ${var.password1} chmod +x /tmp/runit.sh",
      "sudo /tmp/runit.sh"
    ]

    connection {
    type     = "ssh"
    user     = "${var.username1}"
    host = "${self.resource_configuration.rvar.ip_address[1]}"
    password = "${var.password1}"
    }
}
}

while running i am getting the below error

invalid index operation into non-indexable type: TypeString in:

The error is because “resource_configuration.rvar.ip_address” is not a list:

    resource_configuration = {
      rvar.ip_address = ""
    }

host = “${self.resource_configuration.rvar.ip_address[0]}”

Without seeing the full configuration, it’s tricky to make a suggestion to fix this. If you are using count to create multiple instances, you don’t need to index the ip_address:

resource "vra7_deployment" "machine" {
  count             = 2

provisioner "file" {
    source = "/work/scripts/runit.sh"
    destination = "/tmp/runit.sh"

    connection {
      type     = "ssh"
      user     = "${var.username1}"
      host = "${self.resource_configuration.rvar.ip_address}"
      password = "${var.password1}"
    }
  }
}