Created
November 13, 2020 05:51
-
-
Save MarcoPolo/9d438badab2fe3a66888aaafd279e058 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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