Giter Club home page Giter Club logo

factorio-aci-terraform's Introduction

A Terraform Script for Running a Factorio Server on Azure

This uses Azure Container Instances to create and run a server of the game Factorio, based on the Docker image factoriotools/factorio. Additionally, there is a small management API included to start/stop the server.

The default is an instance with 2 cores and 4 gb memory, which costs about 83 โ‚ฌ a month if it runs the entire time (+ a few cents for the storage).

Included in this template are:

  • ACI instance
  • Azure Storage Account and file share for game state/settings/...
  • A resource group
  • An Azure function to start/stop and check on the container
  • A contributor role assignment for the function to the container instances. i.e. the function will have contributor permissions on your ACI

Authentication

To run this terraform script, you need an Azure subscription and the Azure CLI. Once you have that, and export an environment variable TF_VAR_tenantid and TF_VAR_subid to pass these values into the Terraform provider.

This guide explains what's going on.

The provided Functions can be looked at here. The terraform template deploys a release (probably the latest, check main.tf) from there as functions with a function-level authentication. In order to call the functions get the host key from the Function app via the Azure Portal or any other way you prefer.

Set up and Run

Use your favorite terminal, cd into the directory that contains the main.tf file and run these commands:

$ terraform init
Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "azurerm" (hashicorp/azurerm) 2.2.0...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
$ terraform apply
 terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_container_group.gameserv will be created
  + resource "azurerm_container_group" "gameserv" {
      + dns_name_label      = "safespacefactorio"
      + fqdn                = (known after apply)
      + id                  = (known after apply)
      + ip_address          = (known after apply)
      + ip_address_type     = "public"
      + location            = "westeurope"
      + name                = "factorio-gameserver"
      + os_type             = "Linux"
      + resource_group_name = "factorio"
      + restart_policy      = "Always"

      + container {
          + commands = (known after apply)
          + cpu      = 2
          + image    = "factoriotools/factorio"
          + memory   = 4
          + name     = "factoriogame"
[...]

Plan: 4 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

azurerm_resource_group.main: Creating...
[...]
azurerm_container_group.gameserv: Creation complete after 1m8s

... and you should be good to go. Check the deployment in the portal and while you are there you can get the keys for the function app. The handlers are all GET so use a browser to call https://<dns_label>-ctrl.azurewebsites.net/api/status?code=<host key from the Azure function App>. Instead of /api/status you can also call /api/start or /api/stop for the respective actions.

Configure Factorio

Use the Azure Storage Exporer to connect to the file share and edit the JSON files you find there.

License

MIT

factorio-aci-terraform's People

Contributors

celaus avatar

Stargazers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.