Create a Terraform-enabled Execution Environment teaser: In this challenge you will create an Execution Environment that will enable Terraform usage in Ansible Automation Platform notes:
Create a Terraform-enabled Execution Environment
What is an Execution Environment?
All automation in Red Hat Ansible Automation Platform runs on container images called automation execution environments. Automation execution environments create a common language for communicating automation dependencies, and offer a standard way to build and distribute the automation environment.
In the previous challenge an Execution Environment called Terraform Execution Environment was already created for you.
To use Terraform in YOUR Ansible Automation Platform environment you must create and Execution Environment that includes the Cloud Terraform collection, the Terraform binary, other cloud collections, and other dependencies. Hence, why you will learn how to create an Execution Environment.
The tool needed to create an execution environment is called ansible-builder
👋 Challenge introduction.
Estimated time to complete: 30 minutes
-
In this challenge you will learn
-
How to create the necessary configuration files needed to create an execution environment
-
How to create the execution environment container image using the
ansbile-buildertool -
How to add the new execution environment to Ansible Automation Platform
-
Execution Environments
To run Terraform commands from within Ansible Automation Platform, you will need to create an execution environment that contains the Terraform binary and the Red Hat certified collection for Terraform. This is easy to do using ansible-builder.
In this challenge you will create an execution environment containing everything you need to run Terraform from the Ansible Automation Platform.
[NOTE]You can perform the following steps at the TERMINAL, or in Visual Studio Code (VSCode). In VSCode you can open a terminal prompt. Choose either theTERMINALtab, or theVSCODEtab from the top of the lab screen. We will walk through the steps using theTERMINALbut please feel free to do this in theVSCODEtab if you are more comfortable there!
☑️ Task 1 - Create the configuration files for the execution environment
To create an execution environment with ansible-builder, we need an execution environment definition file.
The file name will be execution-environment.yml
Go to the TERMINAL tab at the top of the lab to open the terminal prompt.
You will be in the /home/rhel folder
Change to the folder named /home/rhel/terraform-ee
cd /home/rhel/terraform-ee
Two empty file already exist in this folder, execution-environment.yml and requirements.yml files.
Modify the execution-environment.yml file and paste into it the following contents: Use vi or vim or nano to modify the execution-environment.yml file.
vim execution-environment.yml
---
version: 3
images:
base_image:
name: registry.redhat.io/ansible-automation-platform-25/ee-minimal-rhel8:latest
dependencies:
galaxy: requirements.yml
options:
package_manager_path: /usr/bin/microdnf
additional_build_steps:
prepend_base:
- RUN $PYCMD -m pip install --upgrade pip setuptools
append_base:
- RUN curl "https://releases.hashicorp.com/terraform/1.12.2/terraform_1.12.2_linux_amd64.zip" -o "/terraform.zip"
- RUN unzip /terraform.zip -d /terraform
- RUN mv /terraform/terraform /bin
This file defines the rules ansible-builder should use to create the execution environment container, including:
-
version: the version of ansible-builder to use -
images: here you define the base image to use for the container. You are using theee-minimal-rhel8:latestbase image for the build process -
dependencies: in this section you can declare dependencies for optionally galaxy (ansible collections), python, and other system dependencies. Notice this section includes a statementgalaxy: requirements.yml, this is the file used to define dependent collections found on Ansible Galaxy to be included within the Execution Environment being built -
additional_build_steps: here we can list commands to be inserted into the Dockerfile/Containerfile to be executed. In this example, we are downloading and installing Terraform because the Terraform binary is needed for Ansible Automation Platform for playbook execution, specifically playbooks that trigger Terraform.prepend_baseis to include commands to be usedbeforethe main build steps.append_baseis to include commands to be usedafterthe main build steps.
Modify the file called requirements.yml and paste the following contents: Use vi or nano to modify the requirements.yml file.
vim requirements.yml
--- collections: - name: amazon.aws - name: cloud.terraform - name: google.cloud
This file defines the Ansible content collections you want to include in your execution environment.
-
Include the
amazon.aws,cloud.terraform, andgoogle.cloudcollections -
This will allow Ansible playbooks to perform automation on cloud infrastructure on AWS and GCP using Terraform and Ansible Automation Platform
-
If additional collections are desired, one would include them in the
requirements.ymlfile as well
Please move ahead to the next task.
☑️ Task 2 - Run ansible-builder
Run ansible-builder to build the execution environment container.
From the terminal prompt run the following:
ansible-builder build -v 3 --tag terraform-ee
This will build the container image tagged with terraform-ee.
This will take a few minutes, and you should see output similar to the following: 
To see the newly created image run the following command. This image was built locally.
podman images
At this point, you would typically push the container image to a registry such as Quay or Dockerhub or your own Private Automation Hub.
If you have a Quay or Dockerhub account already, feel free to create a repository, push the image as you normally would, and use it in the following steps, otherwise we have a pre-existing image you can pull.
Example commands on how to tag and then push the Execution Environment image to Quay.io
podman tag localhost/terraform-ee quay.io/[username]/terraform-ee
podman login --username [username] --password [mypassowrd] quay.io
podman push quay.io/[username]/terraform-ee
☑️ Task 3 - Add the Terraform Execution Environment to Ansible Automation Platform
Now you will add an execution environment to Ansible Automation Platform.
Click on the Ansible Automation Platform tab at the top of lab.
(if not already)
Log in using the following credentials: Login credentials: User: admin Password: ansible123!
Expand the Automation Execution menu on the left.
Navigate to Automation Execution -> Infrastructure -> Execution Environments.
Click on + Create execution environment and enter the following information.
| Field | Value |
|---|---|
Name |
myTerraform EE |
Image |
quay.io/acme_corp/terraform_ee |
Pull |
Only pull the image if not present before running |
Registry credential |
Quay Registry Credential |
[NOTE]Since this image on Quay.io is public you don’t need to create a Registry credential
Click on Create execution environment to save this new Execution Environmnet.
Yes, Yes, we’re using the same image we already have, but remember, this is just to demnstrate how you would add your own created Execution Environment to Ansible Automation Platform.

This Execution Environment is now available for use in Ansible Automation Platform.