5. Inside a new directory create ``main.tf`` file with the following contents that will start an AWS instance with NixOS image using one SSH keypair and an SSH security group:
``aws_image_nixos`` module will return an NixOS AMI given `NixOS release number <https://status.nixos.org>`_
so that ``aws_instance`` resource can reference the AMI in `instance_type <https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#instance_type>`_ argument.
5. Make sure to `configure AWS credentials <https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication>`_.
6. Applying Terraform configuration should get you a running NixOS:
..code:: shell
terraform init
terraform apply
Deploying NixOS changes
-----------------------
Once AWS instance is running an NixOS image via Terraform, we can teach Terraform to always build
latest NixOS configuration and apply those changes to your instance.
1. Create ``configuration.nix`` with the following contents:
-``deploy_nixos`` module requires NixOS to be installed on the target machine and Nix on the host machine.
-``deploy_nixos`` module doesn't work when the client and target architectures are different (unless you use `distributed builds <https://nixos.org/manual/nix/unstable/advanced-topics/distributed-builds.html>`_).
- If you need to inject a value into Nix, there is no elegant solution.
- Each machine is evaluated separately, so note that your memory requirements will grow linearly with the number of machine.
Going Forward
-------------
- It's possible to `switch to use Google Compute Engine provider <https://github.com/tweag/terraform-nixos/tree/master/google_image_nixos#readme>`_.
-`deploy_nixos module <https://github.com/tweag/terraform-nixos/tree/master/deploy_nixos#readme>`_ supports a number arguments, for example to upload keys, etc.