Automated deployment of the 42 Cloud-1 project.
The repository is split into:
iac/: infrastructure as code with Terraform on AWS.cac/: configuration as code with Ansible.
Install these tools on the machine that runs the deployment:
gitsshtaskterraform- AWS credentials configured for Terraform
- an SSH key at
~/.ssh/cloud-1
Optional for local checks:
ansibleansible-galaxy
The Terraform AWS provider uses the standard AWS credential chain. For example:
aws configureor export the usual environment variables:
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_DEFAULT_REGION=eu-west-3Secrets are intentionally ignored by Git. After cloning the repository, create the local files from the examples.
cp cac/group_vars/secrets.example.yml cac/group_vars/secrets.yml
cp iac/terraform.tfvars.example iac/terraform.tfvarsEdit cac/group_vars/secrets.yml:
user_name: change_me
user_pass: change_me
root_pass: change_me
wp_email: admin@example.comEdit iac/terraform.tfvars:
github_token = "replace_me"
# Optional overrides
# aws_region = "eu-west-3"
# instance_type = "t3.micro"The GitHub token is used by the master instance to clone this repository during provisioning.
The Inception .env file is generated by Ansible from:
cac/roles/worker/templates/env.j2For manual local use only, an example exists at:
cac/roles/worker/files/inception/.env.exampleDo not commit real .env, terraform.tfvars, secrets.yml, Terraform state files, private keys, or generated Inception secrets.
Deploy everything from scratch:
task upThis runs Terraform first, then runs the Ansible playbook from the master instance.
Useful commands:
task deploy # Terraform init/apply only
task configure # run Ansible against the current worker
task worker # SSH into the worker
task master # SSH into the master
task worker-reboot # reboot the worker to test persistence
task destroy # destroy AWS resources
task re # destroy, recreate, and configureLocal syntax checks:
cd cac && make check
cd ../iac && terraform fmt -check && terraform validateBefore pushing, verify that no secret file is tracked:
git status --ignoredIgnored local files should appear with !!.