ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
810 stars 1.49k forks source link

Terraform: support check mode on task level #7422

Open humpalu opened 10 months ago

humpalu commented 10 months ago

Summary

I included the task of the terraform in a bigger structure. I would like to set the terraform in 'plan' mode by default and activate it to apply when its needed.

The --check is working on playbook level but the task level check mode isnt like here: https://docs.ansible.com/ansible/2.9/user_guide/playbooks_checkmode.html#enabling-or-disabling-check-mode-for-tasks

Issue Type

Bug Report

Component Name

terraform

Ansible Version

$ ansible --version
ansible [core 2.12.10]
  config file = /ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Mar 13 2023, 10:26:41) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

Configuration

$ ansible-config dump --only-changed

community.general 4.8.3

OS / Environment

Ubuntu

Steps to Reproduce

- name: Deploy Project with terraform 
  community.general.terraform:
    project_path: '../../../../terraform/myproject'
    state: present
    backend_config: 
      key: "sonar/{{terraform_environment}}/terraform.tfstate"
  environment:
    AWS_ACCESS_KEY_ID: '{{terraform_aws_access_key_id}}'
    AWS_SECRET_ACCESS_KEY: '{{terraform_aws_secret_access_key}}'
    AWS_DEFAULT_REGION: "eu-central-1"
  delegate_to: 127.0.0.1
  connection: local
  check_mode: yes

Expected Results

Run only a plan not an apply

Actual Results

ok: [10.10.10.17 -> 127.0.0.1] => {
    "changed": false,
    "command": "/usr/bin/terraform apply -no-color -input=false -auto-approve -lock=true /tmp/tmpcexfmwpk.tfplan",
    "invocation": {
        "module_args": {
            "backend_config": {
                "key": "xxx/xxx/terraform.tfstate"
            },
            "backend_config_files": null,
            "binary_path": null,
            "check_destroy": false,
            "force_init": false,
            "init_reconfigure": false,
            "lock": true,
            "lock_timeout": null,
            "overwrite_init": true,
            "parallelism": null,
            "plan_file": null,
            "plugin_paths": null,
            "project_path": "../../../../terraform/xxx",
            "provider_upgrade": false,
            "purge_workspace": false,
            "state": "present",
            "state_file": null,
            "targets": [],
            "variables": null,
            "variables_files": null,
            "workspace": "default"
        }
    },
    "outputs": {},
    "state": "present",
    "stderr": "",
    "stderr_lines": [],

Code of Conduct

ansibullbot commented 10 months ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 10 months ago

cc @m-yosefpor @rainerleber click here for bot help

humpalu commented 9 months ago

Any update?