On , I learnt ...
How to configure ctags
to parse Terraform files
If you’re using Universal Ctags
(which you should be), you just need to add a ~/.ctags.d/terraform.ctags
with
contents:
--langdef=terraform
--langmap=terraform:.tf.tfvars
--regex-terraform=/^[[:space:]]*resource[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/r,Resource/
--regex-terraform=/^[[:space:]]*data[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/d,Data/
--regex-terraform=/^[[:space:]]*variable[[:space:]]*"([^"]*)"/\1/v,Variable/
--regex-terraform=/^[[:space:]]*provider[[:space:]]*"([^"]*)"/\1/p,Provider/
--regex-terraform=/^[[:space:]]*module[[:space:]]*"([^"]*)"/\1/m,Module/
--regex-terraform=/^[[:space:]]*output[[:space:]]*"([^"]*)"/\1/o,Output/
--regex-terraform=/^([a-z0-9_]+)[[:space:]]*=/\1/f,TFVar/
Then, for example, a Terraform resource like:
resource "aws_cloudwatch_log_group" "my-log-group" {
name = "my-log-group"
...
}
will have my-log-group
stored as an identifier so you can jump to its
definition from other references.
Inspiration taken from ctag support for Terraform although the snippet above is a slightly amended version from the vim-terraform-completion repo.