Before you begin, ensure you have the following:
- Hetzner Account: Sign up or log in to your Hetzner account.
- Registered Domain: Have a domain registered with Hetzner.
- Terraform Installation: Ensure Terraform is installed on your machine. Visit Terraform's official website for installation instructions.
- SSH Key Pair: Generate a pair of SSH keys (public and private) if you haven't already.
- Ansible Ensure Ansible is installed
Follow these steps to set up your environment with Terraform:
-
Clone the Repository:
- Use
git clone [email protected]:kubephil/wordpress-hetzner.git
to clone the repository to your local machine. - Navigate to the Terraform directory within the cloned repository.
- Use
-
Configure Terraform Variables:
- It's recommended to create a
terraform.tfvars
file for your variable definitions. - Add the following variables to the file, replacing placeholders with your actual values (see notes on how to obtain them):
hcloud_token = "<your-hetzner-cloud-token>" hetznerdns_token = "<your-hetzner-dns-token>" hetznerdns_zone_id = "<your-hetzner-dns-zone-id>"
- It's recommended to create a
-
Initialize Terraform:
- Run
terraform init
in your terminal. This command initializes Terraform, setting up your environment to execute Terraform configurations.
- Run
-
Apply Terraform Configuration:
- Execute
terraform apply
to apply the Terraform configuration. - Review the plan and confirm the changes to start the deployment process.
- This will create a file called inventory.ini in the ansible directory with the server config
- Execute
-
Destory the Resource. DESTRUCTIVE
- Execute
terraform destroy
- Review the plan and confirm the changes to start the deployment process.
- Execute
Once the server is created. Follow these steps to deploy wordpress via ansible and docker-compose
- Create ACME config File:
- Navigate to the
ansible
directory and create avars.yml
file for the ACME config and db passworddomain_name: "yourdomain.com" acme_email: "[email protected]" wordpress_db_password: "your-secure-db-password"
- Navigate to the
- Run the playbook
- Execute the command
ansible-playbook -i inventory.ini playbook.yml
- This will deploy the config, copy the docker-compose file and start wordpress
- Execute the command
- Terraform Documentation: For more detailed instructions on using Terraform, refer to the Terraform Documentation.
- Obtain the hcloud token: The hcloud token is per project. Navigate to
https://console.hetzner.cloud/projects/<your-project>/security/tokens
and create a read and write token - Obtain the DNS token: Navigate to the API tokens in Hetzner DNS. Note your domain needs to point to Hetzner's Name servers.
- Apply and Teardown several times: In case you teardown using terrafrom and reapply you might need to run
ssh-keygen -R <your-server-ip>
. This will remove it from the known_hosts.