I'm running Apache Airflow on Cloud Composer (composer-1.14.2-airflow-1.10.14). I want to use Terraform to create infrastructure but I can't find any operators to do this. As a workaround I'm using BashOperator like this:
create_vm=BashOperator(
task_id='create_cluster',
bash_command=f'''
sudo apt-get update -y && \
sudo apt-get install software-properties-common -y && \
sudo apt-get update -y && \
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - && \
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" && \
sudo apt-get update && sudo apt-get install terraform && \
cd /home/airflow/gcs/.../ && \
terraform init && \
terraform plan -out /home/airflow/gcs/.../plantf && \
terraform init && \
terraform apply /home/airflow/gcs/.../plantf
''',
dag=dag)
This really doesn't feel like best practice. Is there a recommended way to run Terraform commands via an Airflow operator?