Builds an inventory from Terraform state file.
Version added: 1.1.0
- Builds an inventory from specified state file.
- To read state file command "Terraform show" is used, thus requiring initialized working directory.
- Does not support caching.
- name: Create an inventory from state file in current directory
plugin: cloud.terraform.terraform_provider
# Running command `ansible-inventory -i inventory.yml --graph --vars` would then produce the inventory:
# @all:
# |--@anothergroup:
# | |--somehost
# | | |--{group_hello = from group!}
# | | |--{group_variable = 11}
# | | |--{host_hello = from host!}
# | | |--{host_variable = 7}
# |--@childlessgroup:
# |--@somegroup:
# | |--@anotherchild:
# | |--@somechild:
# | | |--anotherhost
# | | | |--{group_hello = from group!}
# | | | |--{group_variable = 11}
# | | | |--{host_hello = from anotherhost!}
# | | | |--{host_variable = 5}
# | |--somehost
# | | |--{group_hello = from group!}
# | | |--{group_variable = 11}
# | | |--{host_hello = from host!}
# | | |--{host_variable = 7}
# | |--{group_hello = from group!}
# | |--{group_variable = 11}
# |--@ungrouped:
# | |--ungrupedhost
- name: Create an inventory from state file in provided directory
plugin: cloud.terraform.terraform_provider
project_path: some/project/path
- name: Create an inventory from state file in multiple provided directories
plugin: cloud.terraform.terraform_provider
project_path:
- some/project/path
- some/other/project/path
- name: Create an inventory from provided state file
plugin: cloud.terraform.terraform_provider
state_file: some/state/file/path
- name: Create an inventory from state file in provided project directory
plugin: cloud.terraform.terraform_provider
project_path: some/project/path
state_file: mycustomstate.tfstate
- Polona Mihalič (@PolonaM)
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.