macos-instance/main.tf

129 lines
2.3 KiB
Terraform
Raw Normal View History

2024-11-11 21:55:04 +00:00
data "aws_ami" "mac_11" {
2024-11-11 21:18:50 +00:00
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = [
2024-11-11 21:55:04 +00:00
"amzn-ec2-macos-11.7.4-*-*"
2024-11-11 21:18:50 +00:00
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}
2024-11-11 21:55:04 +00:00
data "aws_ami" "mac_12" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = [
"amzn-ec2-macos-12.7.3-*-*"
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}
data "aws_ami" "mac_13" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = [
"amzn-ec2-macos-13.7-*-*"
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}
data "aws_ami" "mac_14" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = [
"amzn-ec2-macos-14.7-*-*"
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}
data "aws_ami" "mac_15" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = [
"amzn-ec2-macos-15.0-*-*"
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}
2024-11-11 21:18:50 +00:00
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.64.0"
name = "mac-instance-vpc"
azs = var.availability_zones
cidr = var.vpc_cidr
public_subnets = var.public_subnets_cidrs
enable_dns_hostnames = true
enable_dns_support = true
}
resource "aws_security_group" "ssh" {
name_prefix = "mac-ssh-sg-"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
lifecycle {
create_before_destroy = true
}
}
2024-11-11 21:55:04 +00:00
# mac2-m2.metal # 4 performance cores, 4 efficiency cores 8vCPUs 24G Mem 10G Network 8G EBS
# mac2-m2pro.metal # 8 performance cores, 4 efficiency cores 12vCPUs 32G Mem 10G Network 8G EBS
resource "aws_instance" "mac_instance" {
ami = data.aws_ami.mac_15.image_id
2024-11-11 21:18:50 +00:00
instance_type = "mac1.metal"
key_name = var.ssh_key_name
subnet_id = module.vpc.public_subnets[1]
vpc_security_group_ids = [aws_security_group.ssh.id]
}
2024-11-11 21:55:04 +00:00
2024-11-11 21:18:50 +00:00
# ssh -i private_key.pem ec2-user@52.53.52.53