Skip to content

Instantly share code, notes, and snippets.

@MarcoPolo
Created November 13, 2020 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoPolo/9d438badab2fe3a66888aaafd279e058 to your computer and use it in GitHub Desktop.
Save MarcoPolo/9d438badab2fe3a66888aaafd279e058 to your computer and use it in GitHub Desktop.
module "nixos_image_20_09" {
source = "../terraform-nixos/aws_image_nixos"
release = "20.09"
}
resource "aws_key_pair" "nix_key" {
key_name = "nix_key"
public_key = file("~/.ssh/aws_nix.pub")
}
resource "aws_security_group" "sg" {
name = "nix_sg"
ingress {
cidr_blocks = [
"0.0.0.0/0"
]
from_port = 22
to_port = 22
protocol = "tcp"
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "example" {
ami = module.nixos_image_20_09.ami
instance_type = "t2.micro"
key_name = aws_key_pair.nix_key.key_name
security_groups = [aws_security_group.sg.name]
}
module "deploy_nixos" {
source = "../terraform-nixos/deploy_nixos"
# NIX_PATH = "${path.module}/../nix/nixpkgs.nix"
nixos_config = "${path.module}/configuration.nix"
target_user = "root"
target_host = aws_instance.example.public_ip
ssh_private_key_file = "~/.ssh/aws_nix"
triggers = {
// Also re-deploy whenever the VM is re-created
instance_id = aws_instance.example.id
}
}
output ip {
value = aws_instance.example.public_ip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment