Compare commits

...

5 Commits

Author SHA1 Message Date
Noah Masur
0582b4a147
fix: dupe resource 2024-05-07 16:25:53 -04:00
Noah Masur
c06cb27bcc
register instance profile for ssm and allow ping 2024-05-07 16:24:12 -04:00
Noah Masur
de106298d6
Revert "debug: terraform cycle"
This reverts commit b34997257c.
2024-05-07 15:37:28 -04:00
Noah Masur
b34997257c
debug: terraform cycle 2024-05-07 15:35:27 -04:00
Noah Masur
ddfaf0064c
fix: reference to removed var in tf 2024-05-07 15:29:08 -04:00
2 changed files with 47 additions and 1 deletions

View File

@ -1,5 +1,6 @@
resource "aws_instance" "instance" {
ami = aws_ami.image.id
iam_instance_profile = aws_iam_instance_profile.instance.name
instance_type = var.ec2_size
vpc_security_group_ids = [aws_security_group.instance.id]
@ -21,6 +22,14 @@ resource "aws_security_group" "instance" {
description = "Allow SSH and HTTPS"
vpc_id = data.aws_vpc.vpc.id
ingress {
description = "Ping"
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "SSH"
from_port = 22
@ -45,3 +54,40 @@ resource "aws_security_group" "instance" {
ipv6_cidr_blocks = ["::/0"]
}
}
# Setup IAM for the instance to use SSM
data "aws_iam_policy_document" "ec2_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "instance_profile" {
statement {
actions = [
"s3:ListAllMyBuckets",
]
resources = ["*"]
}
}
resource "aws_iam_role" "instance_profile" {
name = "nixos"
assume_role_policy = data.aws_iam_policy_document.ec2_assume_role.json
inline_policy {
name = "instance-profile"
policy = data.aws_iam_policy_document.instance_profile.json
}
}
resource "aws_iam_role_policy_attachment" "instance_ssm" {
role = aws_iam_role.instance_profile.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
resource "aws_iam_instance_profile" "instance" {
name = "nixos"
role = aws_iam_role.instance_profile.name
}

View File

@ -75,7 +75,7 @@ resource "aws_ebs_snapshot_import" "image" {
# Convert to AMI
resource "aws_ami" "image" {
description = "Created with NixOS."
name = replace(basename(local.image_file), "/\\.vhd$/", "")
name = replace(basename(data.aws_s3_object.image.key), "/\\.vhd$/", "")
virtualization_type = "hvm"
root_device_name = "/dev/xvda"
ena_support = true