Skip to content

Latest commit

 

History

History
217 lines (183 loc) · 8.26 KB

cloud.terraform.terraform_provider_inventory.rst

File metadata and controls

217 lines (183 loc) · 8.26 KB

cloud.terraform.terraform_provider

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.
Parameter Choices/Defaults Configuration Comments
binary_path
path
added in 1.1.0
The path of a terraform binary to use.
plugin
string / required
added in 1.1.0
    Choices:
  • cloud.terraform.terraform_provider
The name of the Inventory Plugin.
This should always be cloud.terraform.terraform_provider.
project_path
raw
added in 1.1.0
The path to the initialized Terraform directory with the .tfstate file.
If state_file is not specified, Terraform will attempt to automatically find the state file in project_path for use as inventory source.
If state_file and project_path are not specified, Terraform will attempt to automatically find the state file in the current working directory.
Accepts a string or a list of paths for use with multiple Terraform projects.
search_child_modules
boolean
added in 1.2.0
    Choices:
  • no ←
  • yes
Whether to include ansible_host and ansible_group resources from Terraform child modules.
state_file
path
added in 1.1.0
Path to an existing Terraform state file to be used as an inventory source.
If state_file is not specified, Terraform will attempt to automatically find the state file in project_path for use as inventory source.
If state_file and project_path are not specified, Terraform will attempt to automatically find the state file in the current working directory

- 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

Authors

  • 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.