Prerequisites
- Terraform instalation
- Ansible instalation
- OpenStack application credentials (~/.config/openstack/clouds.yaml)
- OpenStack security group with allow ingress traffic to TCP 22 (SSH) from terraform node
main.tf
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
}
ansible = {
source = "ansible/ansible"
}
}
}
provider "openstack" {
cloud = "test-application-credentials"
}
data "openstack_compute_keypair_v2" "keypair_1" {
name = "test-keypair"
}
data "openstack_networking_network_v2" "network_1" {
name = "test-network"
}
data "openstack_networking_secgroup_v2" "secgroup_1" {
# Ensure that the security group allow ingress to TCP 22 (SSH) from terraform node
name = "test-secgroup"
}
data "openstack_networking_port_v2" "port_1" {
device_id = openstack_compute_instance_v2.instance_1.id
network_id = openstack_compute_instance_v2.instance_1.network.0.uuid
}
# data "template_file" "user_data" {
# template = <
<strong>test-playbook.yml</strong>
<code>
---
- name: Deploy webserver(s)
hosts: www
# remote_user: ubuntu
gather_facts: no
become: true
pre_tasks:
- name: Wait util host is reachable by SSH
wait_for_connection:
timeout: 300
- name: Gether facts
setup:
tasks:
- name: Install nginx
apt:
update_cache: yes
name:
- nginxDeploy
terraform init
terraform apply -auto-approve
Ansible Provider
https://github.com/ansible/terraform-provider-ansible
https://registry.terraform.io/providers/ansible/ansible/latest/docs
Links
https://www.redhat.com/en/blog/providing-terraform-with-that-ansible-magic