Metricbeat and Heartbeat 8.x custom index Name should pickup from template ,but creates always bedefault index name

can you please try exactly my example

Not correct that is what is causing the issue..

Can you please try Exactly my config just change the host and u/p.

output.elasticsearch:
  hosts: ["https://localhost:9200"]
  index: "cis-metric-%{[agent.version]}" 
  username: "elastic"
  password: "password"
  ssl.verification_mode: "none"

setup.ilm.enabled: true
setup.ilm.check_exists: true
setup.ilm.rollover_alias: cis-metric
setup.ilm.pattern: '{now/d}-000001'
setup.ilm.overwrite: false

setup.template.enabled: true  
setup.template.name: "cis-metric-%{[agent.version]}" 
setup.template.pattern: "cis-metric-%{[agent.version]}" 
setup.template.overwrite: false 
setup.ilm.policy_name: cis-metric