In this challenge we will implement a simple LAMP stack using terraform and docker.
Utilize /root/code/terraform-challenges/challenge2
directory to store your Terraform configuration files.
We will create the resources in the order of their dependencies, thus you may run plan/apply at any stage, or wait till the end.
Note that these challenges do not use an embedded VSCode IDE, therefore we must use the venerable vi
to create and edit files. Now you can put all the resources into a single file e.g. main.tf
or as shown here in separate files. Terraform doesn't care!
-
terraform-jump-host
Install terraform binary version=1.1.5 on iac-servercurl -L -o /tmp/terraform_1.1.5_linux_amd64.zip https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_linux_amd64.zip unzip -d /usr/local/bin /tmp/terraform_1.1.5_linux_amd64.zip
-
docker
Docker provider has already been configured using kreuzwerker/docker provider.
Check out the provider.tf given at /root/code/terraform-challenges/challenge2cd /root/code/terraform-challenges/challenge2 cat provider.tf
Let's initialize the provider now.
terraform init
You should now refer to the documentation for this provider. Go to the Terraform Registry and paste
kreuzwerker/docker
into the search bar. -
php-httpd-image
Create a terraform resource named php-httpd-imageRefer to the provider documentation for docker-image
Using
vi
, create php-httpd-image.tf -
mariadb-custom-image
Create a terraform resource named mariadb-imageRefer to the provider documentation for docker-image
Using
vi
, create mariadb-custom-image.tf -
mariadb-volume
Create a terraform resource named mariadb_volumeRefer to the provider documentation for docker-volume
Using
vi
, create mariadb-volume.tf -
private_network
Create a terraform resource named private_networkRefer to the provider documentation for docker-network
Using
vi
, create private-network.tf -
db
Define a terraform resource mariadb for creating docker containerRefer to the provider documentation for docker-container
Using
vi
, create db.tf -
webserver
Define a terraform resource php-httpd for creating docker containerRefer to the provider documentation for docker-container
Using
vi
, create webserver.tf -
db_dashboard
Define a terraform resource phpmyadmin for docker containerRefer to the provider documentation for docker-container
Using
vi
, create db-dashboard.tf -
DEPLOY!
terraform plan terraform apply