|
| 1 | +# NGINX Controller Automation Demo |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This demo uses Packer, Terraform, and Ansible to automate the setup of an NGINX Controller AWS pseudo-production environment that includes a PostgreSQL external database, a mock SMTP server, and a series of NGINX Plus instances. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +### Packer |
| 10 | + |
| 11 | +This demo has been developed and tested with Packer `1.6.x`. Backwards compatibility is not guaranteed. |
| 12 | + |
| 13 | +Instructions on how to install Packer can be found in the [Packer website](https://www.packer.io/downloads.html). |
| 14 | + |
| 15 | +### Terraform |
| 16 | + |
| 17 | +This demo has been developed and tested with Terraform `0.13.x`. Backwards compatibility is not guaranteed. |
| 18 | + |
| 19 | +Instructions on how to install Terraform can be found in the [Terraform website](https://www.terraform.io/downloads.html). |
| 20 | + |
| 21 | +### Ansible |
| 22 | + |
| 23 | +This demo has been developed and tested with Ansible `2.10.x`. Backwards compatibility is not guaranteed. |
| 24 | + |
| 25 | +Instructions on how to install Ansible can be found in the [Ansible website](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html). |
| 26 | + |
| 27 | +### NGINX Controller & NGINX Plus |
| 28 | + |
| 29 | +You will need to download the NGINX Controller tar file, NGINX Controller license, and NGINX Plus license from your [MyF5 portal](https://account.f5.com/myf5) before you run this script. |
| 30 | + |
| 31 | +You will also need a FQDN for NGINX Controller with its `A record` pointing to an AWS elastic IP. |
| 32 | + |
| 33 | +## Guide |
| 34 | + |
| 35 | +There are three "distinct" steps to this NGINX Controller automation demo: |
| 36 | + |
| 37 | +1. **Packer** prebuilds AWS AMIs (using the Ansible provisioner) for PostgreSQL, a mock SMTP server, NGINX Controller, and NGINX Plus. Packer templates (and the corresponding Ansible playbooks used by Packer) can be found in the [`packer/`](packer/) directory. |
| 38 | +2. **Terraform** deploys a pseudo-production ready NGINX Controller infrastructure environment in AWS using the AWS AMIs created by Packer. Terraform modules can be found in the [`terraform/`](terraform/) directory. |
| 39 | +3. **Ansible** installs and configures NGINX Controller on the NGINX Controller instance and the NGINX Controller agent on the NGINX Plus instance. Ansible playbooks can be found in the [`ansible/`](ansible/) directory. |
| 40 | + |
| 41 | +In turn, there are four "distinct" components deployed in this NGINX Controller automation demo: |
| 42 | + |
| 43 | +1. **NGINX Controller** |
| 44 | +2. **NGINX Plus instance(s)** |
| 45 | +3. **PostgreSQL database** |
| 46 | +4. **Mock SMTP server** |
| 47 | + |
| 48 | +Both Packer and Terraform have been separated into logical subdirectories following the above four "distinct" components. |
| 49 | + |
| 50 | +For ease of use, both the Packer and Ansible steps have been included in the Terraform script at the top and bottom of [`main.tf`](main.tf) respectively. However, you can decouple Packer and Ansible from Terraform setting the `run_packer` and `run_ansible` variables to `false` within your Terraform variables, and then running each step separately as detailed below. |
| 51 | + |
| 52 | +### Packer |
| 53 | + |
| 54 | +To use the provided Packer templates, you will first need to: |
| 55 | + |
| 56 | +1. Export your AWS credentials as environment variables (or alternatively, use one of the authentication methods described in the [Packer AWS builder docs](https://www.packer.io/docs/builders/amazon). |
| 57 | +2. Tweak any desired variables (detailed within each respective Packer template). Alternatively, you can input those variables at runtime. |
| 58 | + |
| 59 | +There are four Packer templates in this demo: |
| 60 | + |
| 61 | +|Name|Description| |
| 62 | +|----|-----------| |
| 63 | +|[`nginx.pkr.hcl`](packer/nginx/nginx.pkr.hcl)|Build an NGINX Plus AMI| |
| 64 | +|[`nginx-controller.pkr.hcl`](packer/nginx-controller/nginx-controller.pkr.hcl)|Build an NGINX Controller AMI| |
| 65 | +|[`postgresql.pkr.hcl`](packer/postgresql/postgresql.pkr.hcl)|Build a PostgreSQL database| |
| 66 | +|[`smtp.pkr.hcl`](packer/smtp/smtp.pkr.hcl)|Build a mock SMTP server| |
| 67 | + |
| 68 | +To start a Packer build, run: |
| 69 | + |
| 70 | +``` |
| 71 | +packer build packer/<subdirectory>/<template>.pkr.hcl |
| 72 | +``` |
| 73 | + |
| 74 | +(**Note:** Both the `nginx-controller.pkr.hcl` and `nginx.pkr.hcl` Packer templates require you to explicitly set some variables.) |
| 75 | + |
| 76 | +### Terraform |
| 77 | + |
| 78 | +To use the provided Terraform deployment, you will first need to: |
| 79 | + |
| 80 | +1. Export your AWS credentials as environment variables (or alternatively, tweak the AWS provider in [`provider.tf`](provider.tf)). |
| 81 | +2. Tweak any desired variables in [`variables.tf`](variables.tf). Alternatively, you can input those variables at runtime. |
| 82 | + |
| 83 | +There are five Terraform modules in this demo: |
| 84 | + |
| 85 | +|Name|Description| |
| 86 | +|----|-----------| |
| 87 | +|[`network/`](terraform/network/)|Deploy NGINX Controller's network stack| |
| 88 | +|[`nginx-controller/`](terraform/nginx-controller/)|Deploy NGINX Controller instance and relevant network components| |
| 89 | +|[`nginx/`](terraform/nginx/)|Deploy NGINX Plus instance(s) and relevant network components| |
| 90 | +|[`postgresql/`](terraform/postgresql/)|Deploy PostgreSQL instance| |
| 91 | +|[`smtp/`](terraform/smtp/)|Deploy mock SMTP instance| |
| 92 | + |
| 93 | +To start the AWS NGINX Controller deployment, you can either: |
| 94 | + |
| 95 | +* Run [`./setup.sh`](setup.sh) to initialize Terraform and start the Terraform deployment. |
| 96 | +* Run `terraform init` and `terraform apply`. |
| 97 | + |
| 98 | +Once you are done playing with NGINX Controller, you can destroy the AWS NGINX Controller deployment by either: |
| 99 | + |
| 100 | +* Run [`./cleanup.sh`](cleanup.sh) to destroy your Terraform deployment. |
| 101 | +* Run `terraform destroy` (you can optionally delete your `.terraform` directory too). |
| 102 | + |
| 103 | +### Ansible |
| 104 | + |
| 105 | +To use the provided Ansible playbooks, you will first need to install the required collections/roles by running: |
| 106 | + |
| 107 | +``` |
| 108 | +ansible-galaxy install -r ansible/requirements.yml |
| 109 | +``` |
| 110 | + |
| 111 | +There are two Ansible playbooks in this demo: |
| 112 | + |
| 113 | +|Name|Description| |
| 114 | +|----|-----------| |
| 115 | +|[`nginx-controller-install.yml`](ansible/nginx-controller-install.yml)|Install and configure NGINX Controller| |
| 116 | +|[`nginx-controller-agent.yml`](ansible/nginx-controller-agent.yml)|Install and configure the NGINX Controller agent| |
| 117 | + |
| 118 | +To execute a playbook, run: |
| 119 | + |
| 120 | +``` |
| 121 | +ansible-playbook --private-key=</path/to/key> -i </instance/ip>, -u ubuntu ansible/<playbook>.yml |
| 122 | +``` |
| 123 | + |
| 124 | +(**Note:** You will first need to install and configure NGINX Controller using the `nginx-controller-install.yml` playbook before you can install the NGINX Controller agent on NGINX Plus instances using the `nginx-controller-agent.yml` playbook.) |
| 125 | + |
| 126 | +## Author Information |
| 127 | + |
| 128 | +[Alessandro Fael Garcia](https://github.com/alessfg) |
0 commit comments