How to display contents of my terraform S3 state file in Ansible?

213 Views Asked by At

I am new to Ansible; couldn't find this on the docs. I know that I can run terraform plan and apply based on the check_mode boolean. But I need to run terraform state list and terraform show and possibly terraform state show {resource} based on my statefile. How can I get that to run?

My main.yml in task looks like this:

- name: "Run terraform project: {{ tf_role }}"
  terraform:
    state: present
    backend_config:
      bucket: "{{ bootstrap_stack.ansible_facts.cloudformation[stack_name].stack_outputs.TerraformBucketName }}"
      region: "{{ bootstrap_region }}"
      kms_key_id: "{{ bootstrap_stack.ansible_facts.cloudformation[stack_name].stack_outputs.TerraformKeyId }}"
      encrypt: "true"
      workspace_key_prefix: "{{ target_infra }}"
      key: "{{ tf_project }}.tfstate"
    force_init: true
    project_path: "../terraform/{{role_name}}"
    variables:
      target_region: "{{ bootstrap_region }}"
      target_infra: "{{ target_infra }}"
    workspace: "{{ hostvars[inventory_hostname]['Id'] }}"
  check_mode: "{{ check_mode | default('yes') }}"
  register: test-default-reporting
  tags:
    - test-default-reporting
0

There are 0 best solutions below