This terraform code sets up a Valheim server on AWS, based on mbround18's valheim docker image. The following resources are created:
- VPC with one public subnet
- EC2 instance
- ECS cluster and Task Definition
- EFS for storing server/saves/backups files
- (Optional) Lambdas which terminate/create the EC2 instance on a schedule
The following external modules are used:
- diodonfrost/terraform-aws-lambda-scheduler-stop-start
- terraform-aws-modules/terraform-aws-vpc
- cloudposse/terraform-aws-ecs-container-definition
Clone this repository and cd into it:
$ git clone https://github.com/codeeno/valheim-terraform
$ cd valheim-terraformCopy the terraform.tfvars.sample file:
$ mv terraform.tfvars.sample terraform.tfvarsAdjust the values in the terraform.tfvars to your liking. Then, apply the terraform:
$ terraform applyCheck the outputs for the elastic public IP address of your server.
The inputs which start with server correspond to environment variables set by the docker container. Check the official documentation for more info.
| Name | Type | Default |
|---|---|---|
| availability_zone | string |
"eu-central-1a" |
| container_image_tag | string |
"latest" |
| enable_scheduled_shutdown | bool |
false |
| enable_scheduled_startup | bool |
false |
| instance_type | string |
n/a |
| key_name | string |
null |
| server_auto_backup | number |
null |
| server_auto_backup_days_to_live | number |
null |
| server_auto_backup_on_shutdown | number |
null |
| server_auto_backup_on_update | number |
null |
| server_auto_backup_remove_old | number |
null |
| server_auto_backup_schedule | string |
null |
| server_auto_update | number |
null |
| server_auto_update_schedule | string |
null |
| server_name | string |
n/a |
| server_password | string |
n/a |
| server_public | number |
1 |
| server_tz | string |
"Europe/Berlin" |
| server_update_on_startup | number |
null |
| server_webhook_url | string |
null |
| server_world | string |
n/a |
| shutdown_schedule_expression | string |
null |
| startup_schedule_expression | string |
null |
| subnet_cidr | string |
"10.0.0.0/24" |
| task_cpu | number |
n/a |
| task_memory | number |
n/a |
| vpc_cidr | string |
"10.0.0.0/16" |
| vpc_subnet | string |
"10.0.0.0/24" |
