WordPress and WooCommerce AWS Cloud has the next components:
- Web Node with Auto Scaling and support of ARM Graviton 2 instances,
- ElasticSearch, plugin like this required https://wordpress.org/plugins/elasticpress/
- Relational database MySQL/MariaDB or Aurora RDS
- Redis ElastiCahe for Sessions and Caches, plugin like this requred https://wordpress.org/plugins/redis-cache/
- CloudWatch for monitoring and allerting
- AWS SES(Simple Email Service)/SMTP to send email
- NFS/EFS shared network file system
- Install Terraform 0.15 or newer
- Install Terragrunt 0.29 or newer
- Optionally, install pre-commit hooks to keep Terraform formatting and documentation up-to-date.
If you are using macOS you can install all dependencies using Homebrew:
$ brew install terraform terragrunt pre-commit
The recommended way to configure access credentials to AWS account is using environment variables:
$ export AWS_DEFAULT_REGION=ap-southeast-1
$ export AWS_ACCESS_KEY_ID=...
$ export AWS_SECRET_ACCESS_KEY=...
Alternatively, you can edit terragrunt.hcl
and use another authentication mechanism as described in AWS provider documentation.
Infrastructure consists of multiple layers (wp_auto_scaling, mysql, load_balancer, ...) where each layer is described using one Terraform module with inputs
arguments specified in terragrunt.hcl
in respective layer's directory.
Navigate through layers to review and customize values inside inputs
block.
There are two ways to manage infrastructure (slower&complete, or faster&granular):
- Region as a whole (slower&complete). Run this command to create infrastructure in all layers in a single region:
$ cd region
$ terragrunt run-all apply
- As a single layer (faster&granular). Run this command to create infrastructure in a single layer (eg,
wp_auto_scaling
):
$ cd ap-southeast-1/wp_auto_scaling
$ terragrunt apply
After the confirmation your infrastructure should be created.
destroy-all (DEPRECATED: use run-all) DEPRECATED: Use run-all destroy instead.
terragrunt run-all destroy
Destroy a ‘stack’ by running ‘terragrunt destroy’ in each subfolder.
After apply command run:
terragrunt run-all output
#or
terragrunt output-all
or by modules:
cd load_balancer
terragrunt run-all output
#or
terragrunt output-all --terragrunt-non-interactive
The terraform/trragrunt output command is used to extract the value of an output variable from the state file.
With no additional arguments, output will display all the outputs for the root module. If an output NAME is specified, only the value of that output is printed.
The command-line flags are all optional. The list of available flags are:
-json - If specified, the outputs are formatted as a JSON object, with a key per output. If NAME is specified, only the output specified will be returned. This can be piped into tools such as jq for further processing. -raw - If specified, Terraform will convert the specified output value to a string and print that string directly to the output, without any special formatting. This can be convenient when working with shell scripts, but it only supports string, number, and boolean values. Use -json instead for processing complex data types. -no-color - If specified, output won't contain any color. -state=path - Path to the state file. Defaults to "terraform.tfstate". Ignored when remote state is used.
- Terraform documentation and Terragrunt documentation for all available commands and features
- Terraform AWS modules
- Terraform modules registry
- Terraform best practices