Terraform Module - Output Returns Empty after Successful Run.

350 views
Skip to first unread message

Bharath Annamaneni

unread,
Jan 13, 2021, 3:38:19 PM1/13/21
to Ansible Project
Hello Ansible Users,

I am trying to run/use the Ansible's Terraform Module to provision the servers in Public Cloud. The Terraform Code works fine when run manually and through Ansible, but, the Ansible doesn't return the output of the resources being provisioned by Terraform.

Per Ansible's Terraform Module documentation it is expected to return a "output" key on success with the details of the resources being provisioned. But, in my case its empty.


play.yml
hostslocalhost
  gather_factsfalse
  becomefalse

  tasks:
  - nameProvision AWS
    community.general.terraform:
     project_path"/home/terraform/aws-vm"
     statepresent
     force_inittrue
     variables:
      typet2.micro
    registerterraform
  
  - debug:
      varterraform


Output:
ok: [localhost] => {
    "terraform": {
        "changed": true,
        "command": "/usr/bin/terraform apply -no-color -input=false -auto-approve=true -lock=true /tmp/tmp5plmx0xb.tfplan",
        "failed": false,
        "outputs": {},
        "state": "present",
        "stderr": "",
        "stderr_lines": [],
        "stdout": "aws_instance.awsvm: Creating...\naws_instance.awsvm: Still creating... [10s elapsed]\naws_instance.awsvm: Still creating... [20s elapsed]\naws_instance.awsvm: Still creating... [30s elapsed]\naws_instance.awsvm: Still creating... [40s elapsed]\naws_instance.awsvm: Creation complete after 42s [id=i-068dd9cb7d994abe3]\n\nApply complete! Resources: 1 added, 0 changed, 0 destroyed.\n\nThe state of your infrastructure has been saved to the path\nbelow. This state is required to modify and destroy your\ninfrastructure, so keep it safe. To inspect the complete state\nuse the `terraform show` command.\n\nState path: terraform.tfstate\n",
        "stdout_lines": [
            "aws_instance.awsvm: Creating...",
            "aws_instance.awsvm: Still creating... [10s elapsed]",
            "aws_instance.awsvm: Still creating... [20s elapsed]",
            "aws_instance.awsvm: Still creating... [30s elapsed]",
            "aws_instance.awsvm: Still creating... [40s elapsed]",
            "aws_instance.awsvm: Creation complete after 42s [id=i-068dd9cb7d994abe3]",
            "",
            "Apply complete! Resources: 1 added, 0 changed, 0 destroyed.",
            "",
            "The state of your infrastructure has been saved to the path",
            "below. This state is required to modify and destroy your",
            "infrastructure, so keep it safe. To inspect the complete state",
            "use the `terraform show` command.",
            "",
            "State path: terraform.tfstate"
        ],
        "workspace": "default"
    }
}

Can anyone please help me resolving the issue.

Jorge Rúa

unread,
Jan 14, 2021, 5:37:47 AM1/14/21
to ansible...@googlegroups.com
What ansible documentation say is that the terraform ansible module ouputs Terraform outputs https://www.terraform.io/docs/configuration/outputs.html

If you don't have any Terraform output declared in your .tf files you won't see any output.

HTH



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bd3f7985-c6ff-416e-8a22-71cfb5e97e47n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages