ansible.builtin.terraform (v2.6.20) — module

Manages a Terraform deployment (and plans)

| "added in version" 2.5 of ansible.builtin"

Authors: Ryan Scott Brown @ryansb

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.6.20

Description

Provides support for deploying resources with Terraform and pulling resource information back into Ansible.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Basic deploy of a service
- terraform:
    project_path: '{{ project_dir }}'
    state: present

Inputs

    
lock:
    description:
    - Enable statefile locking, if you use a service that accepts locks (such as S3+DynamoDB)
      to store your statefile.
    required: false

state:
    choices:
    - planned
    - present
    - absent
    default: present
    description:
    - Goal state of given stage/project
    required: false

targets:
    description:
    - A list of specific resources to target in this plan/application. The resources selected
      here will also auto-include any dependencies.
    required: false

plan_file:
    description:
    - The path to an existing Terraform plan file to apply. If this is not specified,
      Ansible will build a new TF plan and execute it.
    required: false

variables:
    description:
    - A group of key-values to override template variables or those in variables files.
    required: false

force_init:
    default: false
    description:
    - To avoid duplicating infra, if a state file can't be found this will force a `terraform
      init`. Generally, this should be turned off unless you intend to provision an entirely
      new Terraform deployment.
    required: false
    type: bool

state_file:
    description:
    - The path to an existing Terraform state file to use when building plan. If this
      is not specified, the default `terraform.tfstate` will be used.
    - This option is ignored when plan is specified.
    required: false

binary_path:
    description:
    - The path of a terraform binary to use, relative to the 'service_path' unless you
      supply an absolute path.
    required: false

lock_timeout:
    description:
    - How long to maintain the lock on the statefile, if you use a service that accepts
      locks (such as S3+DynamoDB).
    required: false

project_path:
    description:
    - The path to the root of the Terraform directory with the vars.tf/main.tf/etc to
      use.
    required: true

variables_file:
    description:
    - The path to a variables file for Terraform to fill into the TF configurations.
    required: false

Outputs

command:
  description: Full `terraform` command built by this module, in case you want to
    re-run the command outside the module or debug a problem.
  returned: always
  sample: terraform apply ...
  type: string
outputs:
  contains:
    sensitive:
      description: Whether Terraform has marked this value as sensitive
      returned: always
      type: bool
    type:
      description: The type of the value (string, int, etc)
      returned: always
      type: string
    value:
      description: The value of the output as interpolated by Terraform
      returned: always
  description: A dictionary of all the TF outputs by their assigned name. Use `.outputs.MyOutputName.value`
    to access the value.
  returned: on success
  sample: '{"bukkit_arn": {"sensitive": false, "type": "string", "value": "arn:aws:s3:::tf-test-bukkit"}'
  type: complex
stdout:
  description: Full `terraform` command stdout, in case you want to display it or
    examine the event log
  returned: always
  sample: ''
  type: string